-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMarineTraffic2.py
38 lines (26 loc) · 928 Bytes
/
MarineTraffic2.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
def get_ship_position(ship_id):
import requests
url = "https://www.marinetraffic.com/vesselDetails/latestPosition/shipid:{}".format(ship_id)
headers = {
"accept": "application/json",
"accept-encoding": "gzip, deflate",
"user-agent": "Mozilla/5.0",
"x-requested-with": "XMLHttpRequest"
}
response = requests.get(url, headers=headers)
response.raise_for_status()
return response.json()
def main():
from datetime import datetime
data = get_ship_position("371441")
print(data)
ts = datetime.utcfromtimestamp(data["lastPos"])
print("Last known position: {} / {} @ {}".format(data["lat"], data["lon"], ts))
print("Speed : ",data['speed'])
print("Status : ",data['shipStatus'])
print("Area : ",data['areaCode'])
print("Area Name : ",data['areaName'])
return 0
if __name__ == "__main__":
import sys
sys.exit(main())