-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheasym2m.py
47 lines (27 loc) · 1.05 KB
/
easym2m.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
import requests
class BalanceException(Exception):
pass
class LoginException(BalanceException):
pass
class DownloadException(BalanceException):
pass
def fetch_balance(username, password, apikey):
s = requests.Session()
s.auth = (username, password)
s.headers['X-Api-Key'] = apikey
res = s.get('https://www.easym2m.eu/api/v2/customer/balance')
if res.status_code != 200:
raise DownloadException()
if 'balance' not in res.json():
raise DownloadException()
total_balance = float(res.json()['balance'])
res = s.get('https://www.easym2m.eu/api/v2/customer/simcards/100/1/')
if res.status_code != 200:
raise DownloadException()
sim_cards = res.json()['data']
for sim_card in sim_cards:
res = s.get('https://www.easym2m.eu/api/v2/customer/balance/' + sim_card['iccid'])
if 'balance' not in res.json():
raise DownloadException()
sim_card['balance'] = float(res.json()['balance'])
return {'total_balance': total_balance, 'sim_cards': sim_cards}