simple gitcafe.com support

This commit is contained in:
Jingbei Li 2015-06-28 15:35:42 +08:00
parent 7390202d87
commit 6cf385a73a
2 changed files with 35 additions and 0 deletions

View File

@ -120,6 +120,18 @@ branch
An environment variable ``NVCHECKER_GITHUB_TOKEN`` can be set to a GitHub OAuth token in order to request more frequently than anonymously.
Check GitCafe
------------
Check `GitCafe <https://gitcafe.com/>`_ for updates. The version returned is in date format ``%Y%m%d``, e.g. ``20130701``.
gitcafe
The gitcafe repository, with author, e.g. ``Deepin/deepin-music``.
branch
Which branch to track? Default: ``master``.
Anonymously only. Authorization is not supported yet.
Check PyPI
----------
Check `PyPI <https://pypi.python.org/>`_ for updates.

View File

@ -0,0 +1,23 @@
import os
import json
import re
from functools import partial
from tornado.httpclient import AsyncHTTPClient, HTTPRequest
GITCAFE_URL = 'https://gitcafe.com/%s/commits/%s'
gitcafe_pattern = re.compile(r'datetime="([^"]*)"')
def get_version(name, conf, callback):
repo = conf.get('gitcafe')
br = conf.get('branch', 'master')
url = GITCAFE_URL % (repo, br)
headers = {'Accept': "text/html"}
request = HTTPRequest(url, headers=headers, user_agent='lilydjwg/nvchecker')
AsyncHTTPClient().fetch(request, callback=partial(_gitcafe, name, callback))
def _gitcafe(name, callback, res):
body = res.body.decode('utf-8')
data = gitcafe_pattern.search(body).group(1)
version = data.split('T', 1)[0].replace('-', '')
callback(name, version)