You've already forked QWeatherReporter
add: added a new way to get ip and location
This commit is contained in:
@@ -7,10 +7,31 @@
|
||||
|
||||
|
||||
import requests
|
||||
import json
|
||||
|
||||
|
||||
def request():
|
||||
session = requests.Session()
|
||||
session.trust_env = False
|
||||
r = session.get('https://ip.tool.lu/', timeout=5).text
|
||||
class Request(object):
|
||||
def __init__(self):
|
||||
self.url1 = 'https://ip.tool.lu'
|
||||
self.url2 = 'https://acg.toubiec.cn/random.php?ret=json'
|
||||
self.session = requests.Session()
|
||||
self.session.trust_env = False
|
||||
|
||||
def request_way_1(self):
|
||||
"""
|
||||
https://ip.tool.lu
|
||||
:return: {'IP:': r.split(':')[1].split()[0], 'Location': r.split(':')[2].split()}
|
||||
"""
|
||||
r = self.session.get(self.url1, timeout=5).text
|
||||
return {'IP:': r.split(':')[1].split()[0], 'Location': r.split(':')[2].split()} # return IP & Cities
|
||||
|
||||
def request_way_2(self):
|
||||
"""
|
||||
https://acg.toubiec.cn/random.php?ret=json
|
||||
:return: {'IP': data['client_ip'], 'Location': data['client_lsp']}
|
||||
"""
|
||||
r = self.session.get(self.url2, timeout=5).text
|
||||
data = json.loads(r)[0]
|
||||
return {'IP': data['client_ip'], 'Location': data['client_lsp']}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user