readme update
[bliep.git] / bliep.py
1 #!/usr/bin/env python3
2
3 import requests
4 import mysql.connector
5 import hashlib
6
7 apiurl = 'https://bliep-main.bliep.nl/api';
8
9 r = requests.post('{}/authenticate'.format(apiurl), json={
10 "username":
11 "mart@martlubbers.net",
12 "password":
13 #FIXME
14 "HIER JE WACHWOORD INVOEREN",
15 "client_id":
16 "393977lIRGDPPGSNt2z5Hhj7VdLu0GEDh7pCKC64Jht2id5TyBNr7DSJjGS7jIAF"})
17 token = 'Bearer {}'.format(r.json()['access_token'])
18 r = requests.get(
19 '{}/profile/credit/history'.format(apiurl),
20 params={'limit': '200', 'offset': '0'},
21 headers={'Authorization': token})
22
23 try:
24 cnx = mysql.connector.connect(
25 user='bliep', password='bliep123', host='localhost', database='bliep')
26 except mysql.connector.Error as err:
27 print(err)
28 exit()
29 cursor = cnx.cursor()
30 for i in r.json()['data']['items']:
31 q = "INSERT IGNORE INTO data (amount, date, description, uid) "\
32 "VALUES (%s, FROM_UNIXTIME(%s), %s, %s)"
33 amount = int(float(i['amount'])*100)
34 date = int(i['date']/1000)
35 res = cursor.execute(q, (
36 amount,
37 date,
38 i['description'],
39 int(str(date)+str(abs(amount)))))
40 cnx.commit()
41 cursor.close()
42 cnx.close()