-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMarineTraffic_General.py
79 lines (50 loc) · 1.74 KB
/
MarineTraffic_General.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
import pandas as pd
import requests
from datetime import datetime
# fetch Vessel infos
def get_ship_info(ship_id):
url ="https://www.marinetraffic.com/en/vesselDetails/vesselInfo/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()
#fetch voyage infos
def get_ship_voyage(ship_id):
url ="https://www.marinetraffic.com/vesselDetails/voyageInfo/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()
# fetch vessel position data
def get_ship_position(ship_id):
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():
info = get_ship_info("371441")
voyage = get_ship_voyage("371441")
position = get_ship_position("371441")
print("\n\n Info : ### \n",pd.Series(info))
print("\n\n Voyage : ### \n",pd.Series(voyage))
print("\n\n Position : ### \n",pd.Series(position))
return 0
if __name__ == "__main__":
import sys
sys.exit(main())