自动检查更新

This commit is contained in:
John Smith
2019-09-16 20:48:03 +08:00
parent dc264d40f0
commit 1514bfed5b
2 changed files with 28 additions and 4 deletions

17
main.py
View File

@@ -1,13 +1,15 @@
# -*- coding: utf-8 -*-
import argparse
import webbrowser
import asyncio
import logging
import os
import webbrowser
import tornado.ioloop
import tornado.web
import update
import views.chat
import views.config
import views.main
@@ -31,6 +33,8 @@ def main():
level=logging.INFO if not args.debug else logging.DEBUG
)
asyncio.ensure_future(update.check_update())
app = tornado.web.Application(
[
(r'/chat', views.chat.ChatHandler),
@@ -45,10 +49,15 @@ def main():
debug=args.debug,
autoreload=False
)
app.listen(args.port, args.host)
try:
app.listen(args.port, args.host)
except OSError:
logger.warning('Address is used %s:%d', args.host, args.port)
return
finally:
url = 'http://localhost' if args.port == 80 else f'http://localhost:{args.port}'
webbrowser.open(url)
logger.info('Server started: %s:%d', args.host, args.port)
url = 'http://localhost' if args.port == 80 else f'http://localhost:{args.port}'
webbrowser.open(url)
tornado.ioloop.IOLoop.current().start()

15
update.py Normal file
View File

@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
import aiohttp
VERSION = 'v1.1.4'
async def check_update():
async with aiohttp.ClientSession() as session:
async with session.get('https://api.github.com/repos/xfgryujk/blivechat/releases/latest') as r:
data = await r.json()
if data['name'] != VERSION:
print('New version available:', data['name'])
print(data['body'])
print('Download:', data['html_url'])