forked from wuhan2020/volunteer-certificate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.py
64 lines (51 loc) · 1.64 KB
/
admin.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
import argparse
from tinydb import Query, TinyDB
from model import update_status, update_status_and_token
from utils import send_email
def send_email_to_status_0():
db = TinyDB("data.json")
People = Query()
target_users = db.search(People.status == 1)
print('there are %s target_users' % len(target_users))
for user in target_users:
update_status(user['email'], 0)
print('all done')
db.close()
def count_status():
db = TinyDB("data.json")
People = Query()
for i in range(5):
c = db.count(People.status == i)
print('status', i, 'have', c, 'people')
db.close()
def change_status_to_0():
db = TinyDB("data.json")
People = Query()
target_users = db.search(People.status.one_of([2, 3]))
for user in target_users:
update_status(user['email'], 0)
db.close()
def search_by_email(email):
db = TinyDB("data.json")
People = Query()
target_user = db.search(People.email.matches('.*%s.*' % email))
for user in target_user:
print(user)
db.close()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--action', default='search_by_email', choices=['search_by_email', 'reset_status'])
parser.add_argument('email')
args = parser.parse_args()
if args.action == 'search_by_email':
search_by_email(args.email)
elif args.action == 'reset_status':
update_status(args.email, status=0)
else:
# change_status_to_0()
# search_by_email('')
# search_by_email('')
# emails = ('[email protected]', )
# for i in emails:
# update_status(i, 0)
count_status()