|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import json |
|
|
|
|
from flask import Flask, g |
|
|
|
|
|
|
|
|
|
from cookiespool.config import * |
|
|
|
|
from cookiespool.db import * |
|
|
|
|
|
|
|
|
@ -7,52 +7,58 @@ __all__ = ['app']
|
|
|
|
|
|
|
|
|
|
app = Flask(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/') |
|
|
|
|
def index(): |
|
|
|
|
return '<h2>Welcome to Cookie Pool System</h2>' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_conn(): |
|
|
|
|
""" |
|
|
|
|
获取 |
|
|
|
|
:return: |
|
|
|
|
""" |
|
|
|
|
for name in GENERATOR_MAP: |
|
|
|
|
print(name) |
|
|
|
|
if not hasattr(g, name): |
|
|
|
|
setattr(g, name + '_cookies', eval('CookiesRedisClient' + '(name="' + name + '")')) |
|
|
|
|
setattr(g, name + '_account', eval('AccountRedisClient' + '(name="' + name + '")')) |
|
|
|
|
for website in GENERATOR_MAP: |
|
|
|
|
print(website) |
|
|
|
|
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('/<name>/random') |
|
|
|
|
def random(name): |
|
|
|
|
@app.route('/<website>/random') |
|
|
|
|
def random(website): |
|
|
|
|
""" |
|
|
|
|
获取随机的Cookie, 访问地址如 /weibo/random |
|
|
|
|
:return: 随机Cookie |
|
|
|
|
""" |
|
|
|
|
g = get_conn() |
|
|
|
|
cookies = getattr(g, name + '_cookies').random() |
|
|
|
|
cookies = getattr(g, website + '_cookies').random() |
|
|
|
|
return cookies |
|
|
|
|
|
|
|
|
|
@app.route('/<name>/add/<username>/<password>') |
|
|
|
|
def add(name, username, password): |
|
|
|
|
|
|
|
|
|
@app.route('/<website>/add/<username>/<password>') |
|
|
|
|
def add(website, username, password): |
|
|
|
|
""" |
|
|
|
|
添加用户, 访问地址如 /weibo/add/user/password |
|
|
|
|
:param website: 站点 |
|
|
|
|
:param username: 用户名 |
|
|
|
|
:param password: 密码 |
|
|
|
|
:return: |
|
|
|
|
""" |
|
|
|
|
g = get_conn() |
|
|
|
|
result = getattr(g, name + '_account').set(username, password) |
|
|
|
|
return result |
|
|
|
|
print(username, password) |
|
|
|
|
getattr(g, website + '_accounts').set(username, password) |
|
|
|
|
return json.dumps({'status': '1'}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@app.route('/<name>/count') |
|
|
|
|
def count(name): |
|
|
|
|
@app.route('/<website>/count') |
|
|
|
|
def count(website): |
|
|
|
|
""" |
|
|
|
|
获取Cookies总数 |
|
|
|
|
""" |
|
|
|
|
g = get_conn() |
|
|
|
|
count = getattr(g, name + '_cookies').count() |
|
|
|
|
return str(int) if isinstance(count, int) else count |
|
|
|
|
count = getattr(g, website + '_cookies').count() |
|
|
|
|
return json.dumps({'status': '1', 'count': count}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
|
|
|