bugfix
This commit is contained in:
parent
bcb509d66f
commit
ddf53befdd
@ -1,13 +1,21 @@
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
from requests import get
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from appPublic.http_client import Http_Client
|
from appPublic.http_client import Http_Client
|
||||||
from appPublic.sockPackage import get_free_local_addr
|
from appPublic.sockPackage import get_free_local_addr
|
||||||
public_headers = {
|
public_headers = {
|
||||||
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36"
|
"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36"
|
||||||
}
|
}
|
||||||
def ipip(ip):
|
|
||||||
|
def get_outip():
|
||||||
|
ip = get('https://api.ipify.org').content.decode('utf8')
|
||||||
|
return ip
|
||||||
|
|
||||||
|
def ipip(ip=None):
|
||||||
# ipip.net
|
# ipip.net
|
||||||
|
if ip is None:
|
||||||
|
ip = get_outip()
|
||||||
api= f"http://freeapi.ipip.net/{ip}"
|
api= f"http://freeapi.ipip.net/{ip}"
|
||||||
hc = Http_Client()
|
hc = Http_Client()
|
||||||
r= hc.get(api, headers=public_headers)
|
r= hc.get(api, headers=public_headers)
|
||||||
@ -16,7 +24,9 @@ def ipip(ip):
|
|||||||
'city':r[2]
|
'city':r[2]
|
||||||
}
|
}
|
||||||
|
|
||||||
def iplocation(ip):
|
def iplocation(ip=None):
|
||||||
|
if ip is None:
|
||||||
|
ip = get_outip()
|
||||||
# apikey come from
|
# apikey come from
|
||||||
# https://app.apiary.io/globaliptv/tests/runs
|
# https://app.apiary.io/globaliptv/tests/runs
|
||||||
# using my github accout
|
# using my github accout
|
||||||
@ -26,7 +36,9 @@ def iplocation(ip):
|
|||||||
r= hc.get(api, headers=public_headers)
|
r= hc.get(api, headers=public_headers)
|
||||||
return r
|
return r
|
||||||
|
|
||||||
def ipaddress_com(ip):
|
def ipaddress_com(ip=None):
|
||||||
|
if ip is None:
|
||||||
|
ip = get_outip()
|
||||||
url = f'https://www.ipaddress.com/ipv4/{ip}'
|
url = f'https://www.ipaddress.com/ipv4/{ip}'
|
||||||
print('ipaddress_com(),url=', url)
|
print('ipaddress_com(),url=', url)
|
||||||
hc = Http_Client()
|
hc = Http_Client()
|
||||||
|
@ -8,11 +8,14 @@ class ThreadWorkers:
|
|||||||
self.semaphore = threading.Semaphore(value=max_workers)
|
self.semaphore = threading.Semaphore(value=max_workers)
|
||||||
self.co_worker = 0
|
self.co_worker = 0
|
||||||
def _do(self, func, *args, **kwargs):
|
def _do(self, func, *args, **kwargs):
|
||||||
self.semaphore.acquire()
|
try:
|
||||||
self.co_worker += 1
|
self.semaphore.acquire()
|
||||||
func(*args, **kwargs)
|
self.co_worker += 1
|
||||||
self.co_worker -= 1
|
func(*args, **kwargs)
|
||||||
self.semaphore.release()
|
finally:
|
||||||
|
self.co_worker -= 1
|
||||||
|
self.semaphore.release()
|
||||||
|
|
||||||
|
|
||||||
def do(self, func, *args, **kwargs):
|
def do(self, func, *args, **kwargs):
|
||||||
b = Background(self._do, func, *args, **kwargs)
|
b = Background(self._do, func, *args, **kwargs)
|
||||||
@ -21,6 +24,10 @@ class ThreadWorkers:
|
|||||||
def get_workers(self):
|
def get_workers(self):
|
||||||
return self.co_worker
|
return self.co_worker
|
||||||
|
|
||||||
|
def until_done(self):
|
||||||
|
while self.co_worker > 0:
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
def k(worker):
|
def k(worker):
|
||||||
t = random.randint(1,4)
|
t = random.randint(1,4)
|
||||||
@ -30,4 +37,4 @@ if __name__ == '__main__':
|
|||||||
w = ThreadWorkers(max_workers=30)
|
w = ThreadWorkers(max_workers=30)
|
||||||
for i in range(100000):
|
for i in range(100000):
|
||||||
w.do(k, w)
|
w.do(k, w)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user