-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtkstar.py
49 lines (36 loc) · 1.32 KB
/
tkstar.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
from datetime import timezone
from json.decoder import JSONDecodeError
import requests
import json
import datetime
from bs4 import BeautifulSoup
from lib import fix_lazy_json
import logging
log = logging.getLogger('werkzeug')
class BalanceException(Exception):
def __str__(self):
return 'BalanceException'
class LoginException(BalanceException):
def __str__(self):
return 'LoginException'
class DownloadException(BalanceException):
def __str__(self):
return 'DownloadException'
def fetch_info(device_id, key):
res = requests.post('https://www.mytkstar.net:8089/openapiv3.asmx/GetTracking', data={
'DeviceID': device_id,
'Key': key,
'MapType': 'Google',
'TimeZones': '2:00',
'Model': '0',
'Language': 'en_US'
}, headers={
'User-Agent': 'Mozilla/5.0 (Linux; Android 7.1.1; Pixel Build/NMF26U) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.91 Mobile Safari/537.36'
})
if res.status_code != 200:
raise DownloadException()
soup_mysite = BeautifulSoup(res.text, "html.parser")
result = json.loads(soup_mysite.find_all()[0].text)
result['id'] = device_id
result['positionTime'] = datetime.datetime.strptime(result['positionTime'], '%Y-%m-%d %H:%M:%S').replace(tzinfo=timezone.utc)
return result