From a67e8fad60d78717a29a52e1db6fe8be2dbd8dd0 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 31 Jan 2021 14:04:50 +0800 Subject: [PATCH 1/5] bugfix --- appPublic/iplocation.py | 63 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 appPublic/iplocation.py diff --git a/appPublic/iplocation.py b/appPublic/iplocation.py new file mode 100644 index 0000000..b3c852d --- /dev/null +++ b/appPublic/iplocation.py @@ -0,0 +1,63 @@ +import os +import sys +from bs4 import BeautifulSoup +from appPublic.http_client import Http_Client +from appPublic.sockPackage import get_free_local_addr +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" +} +def ipip(ip): + # ipip.net + api= f"http://freeapi.ipip.net/{ip}" + hc = Http_Client() + r= hc.get(api, headers=public_headers) + return { + 'country':r[0], + 'city':r[2] + } + +def iplocation(ip): + # apikey come from + # https://app.apiary.io/globaliptv/tests/runs + # using my github accout + apikey='c675f89c4a0e9315437a1a5edca9b92c' + api = f"https://www.iplocate.io/api/lookup/{ip}?apikey={apikey}", + hc = Http_Client() + r= hc.get(api, headers=public_headers) + return r + +def ipaddress_com(ip): + url = f'https://www.ipaddress.com/ipv4/{ip}' + hc = Http_Client() + r = hc.get(url, headers=public_headers) + bs = BeautifulSoup(r, 'html.parser') + section = bs.find_all('section')[0] + tds = section.find_all('td') + d = { + "country":tds[6].contents[1].split(' ')[0], + "city":tds[8].contents[0], + "lat":float(tds[10].contents[0].split(' ')[0]), + "lon":float(tds[11].contents[0].split(' ')[0]) + } + return d + +def get_ip_location(ip): + apis = { + "ipaddress":ipaddress_com, + "ipip.net":ipip, + "iplocation":iplocation, + } + hc = Http_Client() + for k,v in apis.items(): + try: + r = v(ip) + return r + except: + pass + +if __name__ == '__main__': + print(get_free_local_addr()) + if len(sys.argv) > 1: + info = get_ip_location(sys.argv[1]) + print(info) + From cd4b2ff78256d463bc6ed310818385bebc231f81 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 31 Jan 2021 14:06:37 +0800 Subject: [PATCH 2/5] bugfix --- appPublic/myTE.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appPublic/myTE.py b/appPublic/myTE.py index b49ad21..2f0c086 100644 --- a/appPublic/myTE.py +++ b/appPublic/myTE.py @@ -17,7 +17,7 @@ class MyTemplateEngine: self.file_coding = file_coding self.out_coding = out_coding loader = FileSystemLoader(pathList, encoding=self.file_coding) - self.env = Environment(loader=loader, enable_async=True) + self.env = Environment(loader=loader, enable_async=False) denv={ 'json':json, 'hasattr':hasattr, @@ -43,7 +43,7 @@ class MyTemplateEngine: def _render(self,template,data): # print('**********template=',template,'**data=',data,'type_data=',type(data),'************') - uRet = await template.render_async(**data) + uRet = template.render_async(**data) return uRet def renders(self,tmplstring,data): From 893debc6129494f0c4de02d17965fe9820abc475 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sun, 31 Jan 2021 14:40:34 +0800 Subject: [PATCH 3/5] bugfix --- appPublic/background.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appPublic/background.py b/appPublic/background.py index 04d4c08..94846d1 100644 --- a/appPublic/background.py +++ b/appPublic/background.py @@ -8,4 +8,4 @@ class Background(Thread): self.__kw = kw def run(self): - self.__callee(*self.__args, **self.__kw) + return self.__callee(*self.__args, **self.__kw) From e99823714ac5f408be713ca02f75fb2fa4e08b12 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Sat, 13 Feb 2021 11:09:20 +0800 Subject: [PATCH 4/5] bugfix --- appPublic/find_player.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appPublic/find_player.py b/appPublic/find_player.py index a809ccc..586c4f2 100644 --- a/appPublic/find_player.py +++ b/appPublic/find_player.py @@ -40,7 +40,7 @@ def find_players(port): #设置阻塞 #udpCliSock.setblocking(2) #设置超时时间 - udpCliSock.settimeout(0.5) + udpCliSock.settimeout(5) udpCliSock.bind(('', 0)) udpCliSock.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) udpCliSock.sendto(b'findplayers', ('255.255.255.255',port)) From 03dc50d01b8100c59457d9da6a97d7093855f066 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 18 Feb 2021 18:46:05 +0800 Subject: [PATCH 5/5] bugfix --- appPublic/myTE.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/appPublic/myTE.py b/appPublic/myTE.py index 2f0c086..940fb89 100644 --- a/appPublic/myTE.py +++ b/appPublic/myTE.py @@ -4,7 +4,7 @@ try: import ujson as json except: import json -from jinja2 import Environment,FileSystemLoader +from jinja2 import Environment,FileSystemLoader, BaseLoader import codecs from appPublic.argsConvert import ArgsConvert from appPublic.dictObject import DictObject @@ -12,6 +12,10 @@ def isNone(obj): return obj is None +def string_template_render(tmp_string, data): + rtemplate = Environment(loader=BaseLoader()).from_string(myString) + return rtemplate.render(**data) + class MyTemplateEngine: def __init__(self,pathList,file_coding='utf-8',out_coding='utf-8'): self.file_coding = file_coding