forked from beardache/WiFiMap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcities.py
More file actions
69 lines (52 loc) · 2.06 KB
/
cities.py
File metadata and controls
69 lines (52 loc) · 2.06 KB
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
__author__ = 'R'
__project__ = 'Wifimap Downloader'
import hashlib
import requests
import time
import random
import json
from os import path
# Config
user_agent = {
'User-Agent': 'Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 6 - 5.1.0 - API 22 - '
'1440x2560 Build/LMY47D) WiFiMap/2.2.0',
'Content-type': 'application/json',
'Accept': 'text/plain'
}
sign_in = {
"email": "",
"password": ""
}
def format_string(value):
return "{{{}}}".format(','.join('"{}":"{}"'.format(key, val) for (key, val) in sorted(value.items())))
def key():
random.seed(time.time())
return random.randrange(0, 1000)
def linuxTimestamp(string):
salt = "MoKXE8Z84hkHOIXNWw6XIJli2Sl-pqE-rryygRBj"
sha = hashlib.sha1()
sha.update("{}".format(string + salt))
return sha.hexdigest().lower()[2:25]
def load_token():
if not path.exists('session.txt'):
data = '{}'.format(format_string(sign_in))
token = requests.post("http://wifimap.io/users/sign_in?timestamp={}".format(linuxTimestamp(data)),
data=data, headers=user_agent)
with open("session.txt", "w") as line:
line.write(token.text)
return json.loads(token.text)
else:
with open("session.txt", "r") as line:
return json.loads(line.read())
if __name__ == "__main__":
token = load_token()["session_token"]
with open("city.csv", "r") as f:
for i in f:
split = i.split(",")
print '{} - {}'.format(split[2].translate(None, '"\n\r'), split[1].translate(None, '"\n'))
x = requests.get("http://wifimap.io//user/purchased_cities/"
"{}?srv_id={}&sub_srv_id={}×tamp={}&session_token={}".format(
split[0], key(), key(), linuxTimestamp(str(split[0] + token)), token), headers=user_agent)
with open('data/{} - {}'.format(split[2].translate(None, '"\n\r'),
split[1].translate(None, '"\n')).strip(), 'w') as z:
z.write(x.text.encode('utf-8'))