-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflask.py
128 lines (109 loc) · 3.09 KB
/
flask.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
from flask import Flask
import json
from datetime import datetime
app = Flask(__name__)
def cauth(auth, headers):
if headers.get("authorization") is None:
return None
elif headers.get("authorization") == auth:
return True
return False
def get_userids(key=None):
with open('/root/storage/upvotes.json', 'r') as x:
data = json.load(x)
if key is None:
return data
elif data.get(key) is None:
return False
return data[key]
def get_config(key=None):
with open('/root/storage/config.json', 'r') as x:
data = json.load(x)
if key is None:from flask import Flask
import json
from datetime import datetime
app = Flask(__name__)
def cauth(auth, headers):
if headers.get("authorization") is None:
return None
elif headers.get("authorization") == auth:
return True
return False
def get_userids(key=None):
with open('upvotes.json', 'r') as x:
data = json.load(x)
if key is None:
return data
elif data.get(key) is None:
return False
return data[key]
def get_config(key=None):
with open('config.json', 'r') as x:
data = json.load(x)
if key is None:
return data
return data[key]
def write_userids(key, id):
data = get_userids()
if get_userids(key) is False:
if conf["reset"] == 1:
data = {}
data[key] = []
data[key + "_voted"] = []
if id in data[key]:
return "already_voted"
data[key].append(id)
with open('upvotes.json', 'w') as x:
json.dump(data, x)
return True
conf = get_config()
@app.route(conf["post"],methods=['POST'])
def dbotsorg():
botid = conf["botid"]
auth = conf["auth"]
today = datetime.today().strftime('%Y-%m-%d')
check = cauth(auth, request.headers)
if request.method == 'POST' and check is not False:
data = request.json
if data["type"] == "upvote" and data["bot"] == botid:
userid = data["user"]
write_userids(today, userid)
return ''
@app.route('/')
def hello_world():
return 'Your server is up and running!'
if __name__ == '__main__':
app.run(debug = True)
return data
return data[key]
def write_userids(key, id):
data = get_userids()
if get_userids(key) is False:
if conf["reset"] == 1:
data = {}
data[key] = []
data[key + "_voted"] = []
if id in data[key]:
return "already_voted"
data[key].append(id)
with open('/root/storage/upvotes.json', 'w') as x:
json.dump(data, x)
return True
conf = get_config()
@app.route(conf["post"],methods=['POST'])
def dbotsorg():
botid = conf["botid"]
auth = conf["auth"]
today = datetime.today().strftime('%Y-%m-%d')
check = cauth(auth, request.headers)
if request.method == 'POST' and check is not False:
data = request.json
if data["type"] == "upvote" and data["bot"] == botid:
userid = data["user"]
write_userids(today, userid)
return ''
@app.route('/')
def hello_world():
return 'Your server is up and running!'
if __name__ == '__main__':
app.run(debug = True)