-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbestoon.py
94 lines (50 loc) · 1.89 KB
/
bestoon.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
80
81
82
83
84
85
86
87
88
89
90
91
92
import requests
import json
class Bestoon:
def __init__(self, token = None):
self.__token = token
self.url = dict()
self.set_urls()
def set_token(self, token):
self.__token = token
def set_urls(self):
self.url['base'] = 'http://bestoon.ir'
self.url = {
'register' : self.url['base'] + '/accounts/register/',
'login' : self.url['base'] + '/accounts/login/',
'set_expense' : self.url['base'] + '/submit/expense/',
'set_income' : self.url['base'] + '/submit/income/',
'get_expenses' : self.url['base'] + '/q/expenses/',
'get_incomes' : self.url['base'] + '/q/incomes/',
'general_status' : self.url['base'] + '/q/generalstat/',
}
def login(self, username, password):
data = {'username' : username, 'password' : password}
r = requests.post(url = self.url['login'], data = data)
return r.json()
def set_expense(self, amount, text):
data = {'token' : self.__token, 'amount' : amount, 'text' : text}
r = requests.post(url = self.url['set_expense'], data = data)
return r.json()
def set_income(self, amount, text):
data = {'token' : self.__token, 'amount' : amount, 'text' : text}
r = requests.post(url = self.url['set_income'], data = data)
return r.json()
def get_expenses(self, number = None):
if number is None:
data = {'token' : self.__token}
else:
data = {'token' : self.__token, 'num' : number}
r = requests.post(url = self.url['get_expenses'], data = data)
return json.loads(r.json())
def get_incomes(self, number = None):
if number is None:
data = {'token' : self.__token}
else:
data = {'token' : self.__token, 'num' : number}
r = requests.post(url = self.url['get_incomes'], data = data)
return json.loads(r.json())
def get_general_status(self):
data = {'token' : self.__token}
r = requests.post(url = self.url['general_status'], data = data)
return r.json()