File tree 5 files changed +45
-5
lines changed
5 files changed +45
-5
lines changed Original file line number Diff line number Diff line change 1
1
[app]
2
2
env = "production"
3
3
4
+ [web]
5
+ host = "127.0.0.1"
6
+ port = 8080
7
+
4
8
[redis]
5
9
address = "redis://127.0.0.1:6379"
6
10
db = 1
Original file line number Diff line number Diff line change 1
1
import asyncio
2
+
3
+ from src .app .web import Web
2
4
from src .app .ip_checker import IPChecker
3
5
from src .sites import *
4
6
from src .app .ip_get import IPGet
@@ -9,6 +11,7 @@ def main():
9
11
tasks = []
10
12
tasks .append (IPGet .share ().run ())
11
13
tasks .append (IPChecker ().run ())
14
+ Web ().start ()
12
15
loop .run_until_complete (asyncio .wait (tasks ))
13
16
14
17
Original file line number Diff line number Diff line change @@ -18,6 +18,10 @@ class AppEnvType:
18
18
# Coroutine count
19
19
COROUTINE_COUNT_IP_CHECK = 20
20
20
21
+ WEB = {
22
+ 'host' : '0.0.0.0' ,
23
+ 'port' : 8008
24
+ }
21
25
# Config
22
26
REDIS = {
23
27
'address' : '127.0.0.1:6379' ,
@@ -61,6 +65,10 @@ def load(cls):
61
65
if redis :
62
66
cls .REDIS .update (redis )
63
67
68
+ web = configs .get ('web' )
69
+ if redis :
70
+ cls .WEB .update (web )
71
+
64
72
app = configs .get ('app' )
65
73
if app :
66
74
cls .APP_ENV = app .get ('env' , cls .APP_ENV )
Original file line number Diff line number Diff line change
1
+ from sanic import Sanic
2
+ from sanic .response import json
3
+ from multiprocessing import Process
4
+
5
+ from src .app .ip_factory import IPFactory
6
+ from src .app .main import Config
7
+
8
+ app = Sanic ()
9
+
10
+
11
+ class Web (Process ):
12
+
13
+ def run (self ):
14
+ app .run (** Config .WEB )
15
+
16
+
17
+ @app .route ('/get_ip' )
18
+ async def get_ip (request ):
19
+ ip = await IPFactory .get_random_ip (bool (request .raw_args .get ('https' , False )))
20
+ return json ({
21
+ 'ip' : ip .ip ,
22
+ 'port' : ip .port ,
23
+ # 'https': ip.https,
24
+ 'http' : ip .to_http (),
25
+ })
Original file line number Diff line number Diff line change 3
3
4
4
5
5
class IPData (DataHelper ):
6
- ip : str
7
- port : int
8
- delay : float
9
- http : bool
10
- https : bool
6
+ ip : str = ''
7
+ port : int = 0
8
+ delay : float = 0.0
9
+ http : bool = False
10
+ https : bool = False
11
11
score : float = Config .DEFAULT_SCORE
12
12
13
13
@classmethod
You can’t perform that action at this time.
0 commit comments