From 1514bfed5b109ace42749cb2201a630a2038facf Mon Sep 17 00:00:00 2001 From: John Smith Date: Mon, 16 Sep 2019 20:48:03 +0800 Subject: [PATCH] =?UTF-8?q?=E8=87=AA=E5=8A=A8=E6=A3=80=E6=9F=A5=E6=9B=B4?= =?UTF-8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 17 +++++++++++++---- update.py | 15 +++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 update.py diff --git a/main.py b/main.py index 4ef5649..661cf2b 100644 --- a/main.py +++ b/main.py @@ -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() diff --git a/update.py b/update.py new file mode 100644 index 0000000..68a02bb --- /dev/null +++ b/update.py @@ -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'])