-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.py
63 lines (48 loc) · 1.62 KB
/
run.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
#!/usr/bin/env python3
# _*_ coding:utf-8 _*_
# @Author :triangle
# @Time :2019/4/30 16:02
# @Filename :run.py
from flask import Flask, jsonify
from db import RedisClient
from scheduler import run_schedule
from settings import SERVER_HOST, SERVER_PORT, SERVER_ACCESS_LOG
myapp = Flask(__name__)
redis_conn = RedisClient()
@myapp.route("/")
def index():
return jsonify({"Welcome": "This is a proxy pool system."},
{"if there has problem": "Please communicate with QQ:976264593"})
@myapp.route("/pop")
def pop_proxy():
proxy = redis_conn.pop_proxy().decode("utf8")
if proxy[:5] == "https":
return jsonify({"https": proxy})
else:
return jsonify({"http": proxy})
@myapp.route("/get/<int:count>")
def get_proxy(count):
res = []
for proxy in redis_conn.get_proxies(count):
if proxy[:5] == "https":
res.append({"https": proxy})
else:
res.append({"http": proxy})
return jsonify(res)
@myapp.route("/count")
def count_all_proxies():
count = redis_conn.count_all_proxies()
return jsonify({"count": str(count)})
@myapp.route("/count/<int:score>")
def count_score_proxies(score):
count = redis_conn.count_score_proxies(score)
return jsonify({"count": str(count)})
@myapp.route("/clear/<int:score>")
def clear_proxies(score):
if redis_conn.clear_proxies(score):
return jsonify({"Clear": "Successful"})
return jsonify({"Clear": "Score should >= 0 and <= 10"})
if __name__ == "__main__":
# run_schedule()
# 启动服务端 Flask app
myapp.run(host=SERVER_HOST, port=SERVER_PORT, debug=SERVER_ACCESS_LOG)