Use urllib3 to check latest version
This commit is contained in:
parent
31f9c96f83
commit
7860af2e6e
27
buku.py
27
buku.py
@ -3450,27 +3450,32 @@ def browse(url):
|
|||||||
def check_upstream_release():
|
def check_upstream_release():
|
||||||
"""Check and report the latest upstream release version."""
|
"""Check and report the latest upstream release version."""
|
||||||
|
|
||||||
proxies = {
|
global myproxy
|
||||||
'https': os.environ.get('https_proxy'),
|
|
||||||
}
|
if myproxy is None:
|
||||||
|
gen_headers()
|
||||||
|
|
||||||
|
if myproxy:
|
||||||
|
http_handler = urllib3.ProxyManager(myproxy, num_pools=1, headers=myheaders)
|
||||||
|
else:
|
||||||
|
http_handler = urllib3.PoolManager(num_pools=1, headers={'User-Agent': USER_AGENT})
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.get(
|
r = http_handler.request('GET', 'https://api.github.com/repos/jarun/buku/releases?per_page=1', headers={'User-Agent': USER_AGENT})
|
||||||
'https://api.github.com/repos/jarun/buku/releases?per_page=1',
|
|
||||||
proxies=proxies
|
|
||||||
)
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logerr(e)
|
logerr(e)
|
||||||
return
|
return
|
||||||
|
|
||||||
if r.status_code != 200:
|
if r.status == 200:
|
||||||
logerr('[%s] %s', r.status_code, r.reason)
|
latest = json.loads(r.data.decode(errors='replace'))[0]['tag_name']
|
||||||
else:
|
|
||||||
latest = r.json()[0]['tag_name']
|
|
||||||
if latest == 'v' + __version__:
|
if latest == 'v' + __version__:
|
||||||
print('This is the latest release')
|
print('This is the latest release')
|
||||||
else:
|
else:
|
||||||
print('Latest upstream release is %s' % latest)
|
print('Latest upstream release is %s' % latest)
|
||||||
|
else:
|
||||||
|
logerr('[%s] %s', r.status, r.reason)
|
||||||
|
|
||||||
|
http_handler.clear()
|
||||||
|
|
||||||
|
|
||||||
def regexp(expr, item):
|
def regexp(expr, item):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user