From c1d2f1bec93d0f0559de08b517a5f0c8b1dd2183 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Mon, 8 Apr 2013 03:45:51 +0200 Subject: [PATCH] last_xantah --- today_server.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/today_server.py b/today_server.py index 209dd04..1f53b0e 100755 --- a/today_server.py +++ b/today_server.py @@ -16,6 +16,7 @@ import os import sys import urllib import json +import traceback os.chdir('/home/vincent/scripts/today/') sys.path.append("/home/vincent/scripts/dtc/") import dtc @@ -37,14 +38,18 @@ def last_dtc(): return dtc.last_inserted() def last_xkcd(): - try: - p = urllib.urlopen("http://xkcd.com") - except IOError: - return "Impossible de se connecter à 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() + ids = re.findall("""
Xantah (.*?)
""", t) + ids = [int(i) for i in ids] + return max(ids) + def get_file(): """Récupère la liste des derniers ids de chaque truc, stockée dans le fichiers.""" f = open(store_published_file) @@ -61,12 +66,18 @@ def update_file(news): FETCHS = { "xkcd" : last_xkcd, "dtc" : last_dtc, + "xantah" : last_xantah, } + def fetch_all(): """Va chercher sur les différents sites les nouveaux trucs.""" news = {} for (k, f) in FETCHS.iteritems(): - news[k] = f() + try: + news[k] = f() + except Exception as e: + #print "Erreur à la récupération de %s :" % k + traceback.print_exc() return news def sync(): @@ -90,7 +101,9 @@ def sync(): if __name__ == "__main__": if sys.argv[1] == "check": news = fetch_all() - update_file(news) + olds = get_file() + olds.update(news) + update_file(olds) elif sys.argv[1] == "whatsup": news = get_file() print json.dumps(news) -- 2.39.2