-
Notifications
You must be signed in to change notification settings - Fork 3
/
api.py
55 lines (36 loc) · 1.08 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
# coding: utf-8
import requests
BASE_API = 'https://checash.herokuapp.com/'
def create_user(**kwargs):
r = requests.post(
'{}{}'.format(BASE_API, 'user'),
data={
'first_name': kwargs.get('first_name', 'Nikita'),
'last_name': kwargs.get('last_name', 'God'),
'username': kwargs.get('username', 'god_nikita')
}
)
json = r.json()
return json.get('id')
def add_bill(user_id, qr):
r = requests.post(
'{}{}{}{}'.format(BASE_API, 'user/', user_id, '/add-bill/'),
data=(
{'qr': qr} if isinstance(qr, str)
else {'fn': qr.get('fn'),
'i': qr.get('i'),
'fp': qr.get('fp'),
'n': qr.get('n')}
)
)
return r.json()
def get_bills(user_id):
r = requests.get(
'{}{}{}{}'.format(BASE_API, 'user/', user_id, '/get-bills-detailed/'),
)
return r.json()
def get_item_info(item_id):
r = requests.get(
'{}{}{}{}'.format(BASE_API, 'item/', item_id, '/category')
)
return r.json()