-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
106 lines (90 loc) · 3.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
from builtins import min
import requests
import json
from datetime import date
import time
import numpy as np
from termcolor import colored
def request(origin_lat, origin_long, dest_lat, dest_long):
try:
headers = {
'authority': 'app.snapp.taxi',
'content-type': 'application/json',
'x-app-name': 'passenger-pwa',
'x-app-version': '5.0.1',
'authorization': 'ENTER YOUR AUTH KEY',
'locale': 'fa-IR',
'user-agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.183 Mobile Safari/537.36',
'app-version': 'pwa',
'accept': '*/*',
'origin': 'https://app.snapp.taxi',
'sec-fetch-site': 'same-origin',
'sec-fetch-mode': 'cors',
'sec-fetch-dest': 'empty',
'referer': 'https://app.snapp.taxi/pre-ride?utm_source=website&utm_medium=webapp-button',
'accept-language': 'en-US,en;q=0.9,fa;q=0.8',
'cookie': '_ga=GA1.2.630158201.1604921803; _gid=GA1.2.2129247538.1605042565; facb35cfb204e400bdbaa82b44a500a9=9061bb9db340faf4174fe4745d27fc7b; 34b7ed1b00e796d0bcdc387e62021f03=acd89f353aefff86ad7cc9f6453e7a39',
}
data = '{"origin_lat":' + str(origin_lat) + ',"origin_lng":' + str(origin_long) + ',"destination_lat":' + str(
dest_lat) + ',"destination_lng":' + str(
dest_long) + ',"waiting":null,"tag":0,"round_trip":false,"voucher_code":null}'
response = requests.post('https://app.snapp.taxi/api/api-base/v2/passenger/price/s/6/0', headers=headers,
data=data)
if response.status_code != 200:
raise ValueError(response.content)
data = json.loads(response.content)
data = data["data"]
service = data['prices']
m = int(10000000)
for i in range(len(service) - 2):
final = int(service[i]['final'])
m = int(np.min([m, final]))
return m
except Exception as e:
print(colored(e, 'red'))
write_in_file('something wrong')
return 0
def write_in_file(price):
fi = open("snapp.csv", 'a')
fi.write(str(price) + ' , ' + str(date.today()) + ' , ' + str(time.strftime("%H:%M:%S", time.localtime())))
fi.write('\n')
fi.close()
if __name__ == '__main__':
print(time.strftime("%H:%M:%S", time.localtime()))
res = 100000000
price_list = []
origin_lat = 35.7992
origin_long = 51.4075
dest_lat = 35.7114
dest_long = 51.407
step = 100
radius = 500
res_origin_lat = origin_lat
res_origin_long = origin_long
res_dest_long = dest_long
res_dest_lat = dest_lat
for a in range(-radius, radius, step):
for b in range(-radius, radius, step):
lat = origin_lat + round(a * .00001, 4)
long = origin_long + round(a * .00001, 4)
price = request(lat, long, dest_lat, dest_long)
res = min(price, res)
if price == res:
res_lat = lat
res_long = long
price_list.append(price)
for a in range(-radius, radius, step):
for b in range(-radius, radius, step):
lat = dest_lat + round(a * .00001, 4)
long = dest_long + round(a * .00001, 4)
price = request(res_origin_lat, res_origin_long, lat, long)
res = min(price, res)
if price == res:
res_dest_lat = lat
res_dest_long = long
price_list.append(price)
print(colored(str(time.strftime("%H:%M:%S", time.localtime())), 'yellow'), colored(res, 'green'))
print('origin location \t' + str(res_origin_lat) + ',' + str(res_origin_long))
print('dest location \t' + str(res_dest_lat) + ',' + str(res_dest_long))
print('max price \t' + colored(max(price_list), 'red'))
write_in_file(res)