From 6cf385a73a67c1e7453a6b22645f01b9dcf5fea2 Mon Sep 17 00:00:00 2001 From: Jingbei Li Date: Sun, 28 Jun 2015 15:35:42 +0800 Subject: [PATCH] simple gitcafe.com support --- README.rst | 12 ++++++++++++ nvchecker/source/gitcafe.py | 23 +++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 nvchecker/source/gitcafe.py diff --git a/README.rst b/README.rst index b9204a5..b6af89e 100644 --- a/README.rst +++ b/README.rst @@ -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 `_ 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 `_ for updates. diff --git a/nvchecker/source/gitcafe.py b/nvchecker/source/gitcafe.py new file mode 100644 index 0000000..f2e1c57 --- /dev/null +++ b/nvchecker/source/gitcafe.py @@ -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)