-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapi.py
More file actions
77 lines (60 loc) · 1.59 KB
/
api.py
File metadata and controls
77 lines (60 loc) · 1.59 KB
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
# -*- coding: utf-8 -*-
# @Time : 2019/8/16 21:04
# @Author : Esbiya
# @Email : 18829040039@163.com
# @File : api.py
# @Software: PyCharm
import json
from flask import Flask, g
from db import *
from config import *
__all__ = ['app']
app = Flask(__name__)
@app.route('/')
def index():
return '<h2>Welcome to Cookie Pool System</h2>'
def get_conn():
"""
初始化数据库
:return:
"""
for website in GENERATOR_MAP:
if not hasattr(g, website):
setattr(g, website + '_cookies', eval('RedisClient' + '("cookies", "' + website + '")'))
setattr(g, website + '_accounts', eval('RedisClient' + '("accounts", "' + website + '")'))
return g
@app.route('/<website>/random')
def random(website):
"""
获取随机 Cookie
:param website:
:return:
"""
g = get_conn()
cookies = getattr(g, website + '_cookies').random()
return cookies
@app.route('/<website>/add/<username>/<password>')
def add(website, username, password):
"""
添加用户
:param website: 站点
:param username: 用户名
:param password: 密码
:return:
"""
g = get_conn()
print(username, password)
getattr(g, website + '_accounts').set(username, password)
return json.dumps({'status': '1'})
@app.route('/<website>/count')
def count(website):
"""
获取 cookie 总数
:param website:
:return:
"""
g = get_conn()
count = getattr(g, website + '_cookies').count()
return json.dumps({'status': '1', 'count': count})
if __name__ == '__main__':
app.run(host='0.0.0.0', port=8778)