This repository has been archived by the owner on Feb 8, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapi.py
58 lines (50 loc) · 1.95 KB
/
api.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
import requests
PROVIDER = "http://bam.magnetomedia.de/trackinghistory.php"
LOBool = 'true'
class Tracker(object):
"""
It's a class that makes a POST request to a URL, and returns the JSON response
"""
@staticmethod
def PackageInfo(trackingNumber: str):
"""
It takes a tracking number, and returns a dictionary of information about the package
:param trackingNumber: The tracking number of the package
:return: A dictionary of the package information.
"""
try:
req = requests.get(f'{PROVIDER}?lastOperation={LOBool}&trackingNumber={trackingNumber}' ,timeout=5.0)
except requests.exceptions.Timeout:
print('Timeout')
except requests.exceptions.RequestException as er:
print('OOps Somthing Wrong')
raise SystemExit(er)
if req.status_code == 200:
return req.json()["data"][0]
else:
SystemExit('Http Error')
@staticmethod
def LastStatus(trackingNumber: str) -> None:
"""
It returns the last status of the package
:param trackingNumber: The tracking number of the package
:return: The last status of the package
"""
info = Tracker.PackageInfo(trackingNumber)
try:
if LOBool == 'false':
etat = info['etat']
if etat == 'Infos.Indisponibles':
return 'Info-unavailable'
return etat
if LOBool == 'true':
last_status = info["dernier_statut"]
if last_status == 'Neant':
return 'Info-unavailable' # This Package Is Not Registerd In The System Yet or Tracking Code is Wrong
if last_status == '':
last_status = info["lieu_depot"]
return last_status
else:
return "Unknown"
except:
print('No response')