forked from feeluown/FeelUOwn
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
40 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import asyncio | ||
import logging | ||
from functools import partial | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class VersionManager(object): | ||
current_version = 'v9.0a' | ||
|
||
def __init__(self, app): | ||
self._app = app | ||
|
||
@asyncio.coroutine | ||
def check_release(self): | ||
url = 'https://api.github.com/repos/cosven/FeelUOwn/releases' | ||
logger.info('正在查找新版本...') | ||
try: | ||
loop = asyncio.get_event_loop() | ||
future = loop.run_in_executor( | ||
None, partial(self._app.request.get, url, timeout=5)) | ||
res = yield from future | ||
if not res.status_code == 200: | ||
logger.warning('connect to api.github.com timeout') | ||
return | ||
releases = res.json() | ||
for release in releases: | ||
if release['tag_name'] > self.current_version: | ||
title = u'发现新版本 %s hoho' % release['tag_name'] | ||
logger.info(title) | ||
content = release['name'] | ||
self._app.message(title) | ||
break | ||
except Exception as e: | ||
logger.error(str(e)) |