From f858db9ed9baa860032d2777838aa029c0cb99b9 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Fri, 14 Feb 2014 20:57:22 +0100 Subject: [PATCH] Modularisation++ : module comics pour xkcd et jl8 (young DC) --- comics.py | 28 ++++++++++++++++++++++++++++ gather.py | 8 +++++++- today_server.py | 17 ----------------- 3 files changed, 35 insertions(+), 18 deletions(-) create mode 100644 comics.py diff --git a/comics.py b/comics.py new file mode 100644 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, + } diff --git a/gather.py b/gather.py index 527ab6f..09d98b1 100755 --- a/gather.py +++ b/gather.py @@ -15,13 +15,19 @@ import threading import traceback import inspect import pprint + + #: Gestion des chaînes youtube import youtube + #: Interface pour récupérer les quotes DTC #: essentiellement une coquille qui pointe vers la bonne fonction dans le module dtc, codé par ailleurs import lastdtc -GATHERING_MODULES = [youtube, lastdtc] +#: Récupératin des webcomics +import comics + +GATHERING_MODULES = [youtube, lastdtc, comics] def generate_errmsg(id): errmsg = "Erreur à la récupération de %s :\n" % id diff --git a/today_server.py b/today_server.py index 1727e27..0c50160 100755 --- a/today_server.py +++ b/today_server.py @@ -24,12 +24,6 @@ import serverconfig #: Récupération de toutes les nouveautés import gather -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_xantah(): p = urllib.urlopen("http://www.adoprixtoxis.com/lite/download/xantah_downloads.php") t = p.read() @@ -37,15 +31,6 @@ def last_xantah(): ids = [int(i) for i in ids] return max(ids) -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 - def get_file(): """Récupère la liste des derniers ids de chaque truc, stockée dans le fichier.""" f = open(serverconfig.store_published_file) @@ -60,9 +45,7 @@ def update_file(news): f.close() FETCHS = { - "xkcd" : last_xkcd, "xantah" : last_xantah, - "dc" : last_jl8, } def fetch_all(): -- 2.39.2