MCPcopy
hub / github.com/MikeChongCan/scylla / api_v1_proxies

Function api_v1_proxies

scylla/web/server.py:37–113  ·  view source on GitHub ↗
(request: Request)

Source from the content-addressed store, hash-verified

35
36@app.route('/api/v1/proxies')
37async def api_v1_proxies(request: Request):
38 args = request.args
39
40 limit = 20
41
42 page = 1
43
44 is_anonymous = 2 # 0: no, 1: yes, 2: any
45
46 if 'limit' in args:
47 int_limit = _parse_str_to_int(args.get('limit'))
48 limit = int_limit if int_limit else 20
49
50 if 'page' in args:
51 int_page = _parse_str_to_int(args.get('page'))
52 page = int_page if int_page > 0 else 1
53
54 if 'anonymous' in args:
55 str_anonymous = args.get('anonymous')
56 if str_anonymous == 'true':
57 is_anonymous = 1
58 elif str_anonymous == 'false':
59 is_anonymous = 0
60 else:
61 is_anonymous = 2
62
63 str_https = None
64 if 'https' in args:
65 str_https = args.get('https')
66
67 country_list = []
68 if 'countries' in args:
69 countries = args.get('countries')
70 country_list = countries.split(',')
71
72 proxy_initial_query = _get_valid_proxies_query()
73
74 proxy_query = proxy_initial_query
75
76 if is_anonymous != 2:
77 if is_anonymous == 1:
78 proxy_query = proxy_initial_query.where(ProxyIP.is_anonymous == True)
79 elif is_anonymous == 0:
80 proxy_query = proxy_initial_query.where(ProxyIP.is_anonymous == False)
81
82 if str_https:
83 if str_https == 'true':
84 proxy_query = proxy_initial_query.where(ProxyIP.is_https == True)
85 elif str_https == 'false':
86 proxy_query = proxy_initial_query.where(ProxyIP.is_https == False)
87
88 if country_list and len(country_list) > 0:
89 proxy_query = proxy_query.where(ProxyIP.country << country_list)
90
91 count = proxy_query.count() # count before sorting
92
93 proxies = proxy_query.order_by(ProxyIP.updated_at.desc(), ProxyIP.latency).offset((page - 1) * limit).limit(limit)
94

Callers

nothing calls this directly

Calls 3

_parse_str_to_intFunction · 0.85
_get_valid_proxies_queryFunction · 0.85
getMethod · 0.80

Tested by

no test coverage detected