]> gitweb.pimeys.fr Git - today.git/blobdiff - comics.py
Modularisation++ : module comics pour xkcd et jl8 (young DC)
[today.git] / comics.py
diff --git a/comics.py b/comics.py
new file mode 100644 (file)
index 0000000..d650594
--- /dev/null
+++ b/comics.py
@@ -0,0 +1,28 @@
+#!/usr/bin/env python
+# -*- encoding: utf-8 -*-
+
+""" Gathering des webcomics """
+
+import urllib
+import re
+from lxml import etree
+
+def last_xkcd():
+    p = urllib.urlopen("http://xkcd.com")
+    t = p.read()
+    current_id = int(re.findall("Permanent link to this comic: http://xkcd.com/(.*?)/", t)[0])
+    return current_id
+
+def last_jl8():
+    rss = urllib.urlopen("http://limbero.org/jl8/rss/")
+    t = rss.read()
+    x = etree.fromstring(t)
+    links = x.xpath("//link")
+    maxnum = links[1].text.split("/")[-1]
+    maxnum = int(maxnum)
+    return maxnum
+
+functions = {
+    "xkcd" : last_xkcd,
+    "dc" : last_jl8,
+    }