From e3a195db3b648aca03fe68ce3e9bdd26e9d6f928 Mon Sep 17 00:00:00 2001 From: kev Date: Tue, 7 Jul 2015 15:44:11 +0800 Subject: [PATCH] add urlwatch --- urlwatch/Dockerfile | 30 +++++++++++++++ urlwatch/README.md | 6 +++ urlwatch/urlwatch/Makefile | 13 +++++++ urlwatch/urlwatch/lib/hooks.py | 44 ++++++++++++++++++++++ urlwatch/urlwatch/urls.yml | 68 ++++++++++++++++++++++++++++++++++ 5 files changed, 161 insertions(+) create mode 100644 urlwatch/Dockerfile create mode 100644 urlwatch/README.md create mode 100644 urlwatch/urlwatch/Makefile create mode 100755 urlwatch/urlwatch/lib/hooks.py create mode 100644 urlwatch/urlwatch/urls.yml diff --git a/urlwatch/Dockerfile b/urlwatch/Dockerfile new file mode 100644 index 0000000..31c9877 --- /dev/null +++ b/urlwatch/Dockerfile @@ -0,0 +1,30 @@ +# +# Dockerfile for urlwatch +# + +FROM alpine +MAINTAINER kev + +RUN apk add -U ca-certificates \ + build-base \ + libxml2 \ + libxml2-dev \ + libxslt \ + libxslt-dev \ + make \ + python-dev \ + py-pip \ + && pip install keyring \ + lxml \ + urlwatch \ + yaml \ + && apk del build-base \ + libxml2-dev \ + libxslt-dev \ + python-dev \ + && rm -rf /var/cache/apk/* \ + && echo '*/15 * * * * cd ~/.urlwatch && make' | crontab + +COPY urlwatch /root/.urlwatch + +CMD ["crond", "-f", "-L", "/dev/stdout"] diff --git a/urlwatch/README.md b/urlwatch/README.md new file mode 100644 index 0000000..f1b0b71 --- /dev/null +++ b/urlwatch/README.md @@ -0,0 +1,6 @@ +urlwatch +======== + +[urlwatch][1] - a tool for monitoring webpages for updates + +[1]: thp.io/2008/urlwatch/ diff --git a/urlwatch/urlwatch/Makefile b/urlwatch/urlwatch/Makefile new file mode 100644 index 0000000..4485d73 --- /dev/null +++ b/urlwatch/urlwatch/Makefile @@ -0,0 +1,13 @@ +SHELL = /bin/bash +PATH := /usr/local/bin:$(PATH) + +SMTP = smtp.datageek.info:587 +FROM = urlwatch@datageek.info +TO = noreply@datageek.info + +all: urls.txt + urlwatch -s $(SMTP) -f $(FROM) -t $(TO) -A -T + +urls.txt: urls.yml + python lib/hooks.py + diff --git a/urlwatch/urlwatch/lib/hooks.py b/urlwatch/urlwatch/lib/hooks.py new file mode 100755 index 0000000..cb11179 --- /dev/null +++ b/urlwatch/urlwatch/lib/hooks.py @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +# +# version detector for urlwatch +# + +import lxml.html +import os.path +import re +import yaml + + +urlwatch_dir = os.path.expanduser(os.path.join('~', '.urlwatch')) +urls_txt = os.path.join(urlwatch_dir, 'urls.txt') +urls_yml = os.path.join(urlwatch_dir, 'urls.yml') +config = yaml.load(open(urls_yml)) + + +def filter(url, data): + + for key, cfg in config.items(): + if url.endswith('#' + key): + exp = cfg['exp'] + break + else: + return data + + try: + dom = lxml.html.fromstring(data.encode('utf-8')) + txt = dom.xpath(exp)[0] + ver = re.search(r'([0-9]+\.)*[0-9]+', txt).group(0) + return '{}: {}\n'.format(key, ver) + except: + return '{}: {}\n'.format(key, 'unknown') + + +if __name__ == '__main__': + + print 'Generating ...', + urls = ['{0[url]}#{1}\n'.format(cfg, key) for key, cfg in config.items()] + with open(urls_txt, 'w') as f: + f.writelines(urls) + print 'OK!' + diff --git a/urlwatch/urlwatch/urls.yml b/urlwatch/urlwatch/urls.yml new file mode 100644 index 0000000..b41ec2e --- /dev/null +++ b/urlwatch/urlwatch/urls.yml @@ -0,0 +1,68 @@ +vagrant: + url: https://www.vagrantup.com/downloads.html + exp: //h2[@class="os-name" and .="Mac OS X"]/following-sibling::ul/li/a/@href + +coreos: + url: https://coreos.com + exp: //div[@class="co-p-homepage-release-text"]/text() + +git: + url: http://git-scm.com + exp: //span[@class="version"]/text() + +phantomjs: + url: http://phantomjs.org + exp: //span[@class="version"]/text() + +firefox: + url: https://www.mozilla.org/en-US/firefox/new/ + exp: //li[@class="os_osx"]/a[@class="download-link"]/@href + +python: + url: https://www.python.org/downloads/ + exp: //div[@class="download-unknown"]/p[@class]/a[1]/text() + +ubuntu: + url: http://www.ubuntu.com/download/server + exp: //div[contains(@class, "row-hero")]//h2/text() + +mongodb: + url: https://www.mongodb.org/downloads + exp: //h2[@class="release-version" and contains(., "Production")]/text() + +jquery: + url: http://jquery.com + exp: //span[@class="download"]/following-sibling::span/text() + +vim: + url: http://en.wikipedia.org/wiki/Vim_%28text_editor%29 + exp: //th[a="Stable release"]/following-sibling::td/text() + +redis: + url: http://redis.io + exp: //a[contains(@href, "/releases/")]/text() + +scrapy: + url: https://github.com/scrapy/scrapy/releases + exp: //ul[@class="release-timeline-tags"]/li[1]//span[@class="tag-name"]/text() + +scrapyd: + url: https://github.com/scrapy/scrapyd/releases + exp: //div[contains(@class, "label-latest")]//h1[@class="release-title"]/a/text() + +shadowsocks: + url: https://github.com/shadowsocks/shadowsocks/releases + exp: //ul[@class="release-timeline-tags"]/li[1]//span[@class="tag-name"]/text() + +urlwatch: + url: https://github.com/thp/urlwatch/releases + exp: //ul[@class="release-timeline-tags"]/li[1]//span[@class="tag-name"]/text() + +influxdb: + url: http://influxdb.com/download/ + exp: //h1[.="Download"]/following-sibling::h3[contains(., "Stable")][1]/text() + +monit: + url: http://mmonit.com/monit/changes/ + exp: //div[@class="container"]/div[@class="row"][1]//h3/a/text() +