X-Git-Url: http://gitweb.pimeys.fr/?a=blobdiff_plain;f=today_server.py;h=37615d577df5e14f5907a5305e61a7650f47d6d4;hb=3c28b7a8fb1350a2dccea9a4f711ea018cffe666;hp=598a421fad662ec52baac72f42786947ef21c305;hpb=b51baa9dd11477238323855734eeefd82145d5e5;p=today.git diff --git a/today_server.py b/today_server.py index 598a421..37615d5 100755 --- a/today_server.py +++ b/today_server.py @@ -18,18 +18,14 @@ import sys import urllib import json import traceback +import inspect +import pprint os.chdir('/home/vincent/scripts/today/') sys.path.append("/home/vincent/scripts/dtc/") import dtc -#: Fichier où sont stockés les derniers IDs des trucs -store_published_file = "lasts_published" - -#: Fichier où est stockée une copie de la liste des derniers IDs *lus* -store_seen_file = "lasts_sync" - -#: Afficher du garbage pour débuguer -DEBUG = False +# Config serveur +import serverconfig def last_dtc(): """Vérifie si il y a des quotes DTC non lues""" @@ -102,14 +98,15 @@ def last_noob_warpzone(): for serie in [noobs, warpzones]: # Les titres sont dans l'ordre antichronologique, on s'arrête donc au premier qu'on comprend for titre in serie: - if "noob le film" in titre or "making of" in titre: + if "noob le film" in titre or "making of" in titre or "noob versus rct" == titre or "extraits ost" in titre: continue try: if DEBUG: print titre saison, ep = get_season_episode(titre) - except ValueError: - pass + except (ValueError, IndexError) as e: + print "%s sur un season_episode warpzone : %s\n" % (e, titre) + continue lasts.append([saison, ep]) del saison, ep break @@ -139,17 +136,25 @@ def last_grenier(): titles = parse_youtube("joueurdugrenier") return len(titles) +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(store_published_file) + f = open(serverconfig.store_published_file) news = json.load(f) f.close() return news def update_file(news): """Met à jour la liste des derniers ids dans le fichier.""" - f = open(store_published_file, 'w') + f = open(serverconfig.store_published_file, 'w') json.dump(news, f) f.close() @@ -164,6 +169,7 @@ FETCHS = { "norman" : last_norman, "cyprien" : last_cyprien, "grenier" : last_grenier, + "dc" : last_jl8, } def fetch_all(): @@ -173,8 +179,18 @@ def fetch_all(): try: news[k] = f() except Exception as e: - print "Erreur à la récupération de %s :" % k - traceback.print_exc() + errmsg = "Erreur à la récupération de %s :\n" % k + errmsg += traceback.format_exc() + # On dumpe le contenu local de la mémoire au moment de l'exception + fobj = inspect.trace()[-1][0] + # On fait un peu de ménage + d = {k:v for (k,v) in fobj.f_locals.iteritems() if not k.startswith("_")} + # On évite d'envoyer truckLoadsOfShit + d = {k: (v if len(str(v)) < 800 + else str(v)[:400] + "*" * 40 + "TRUNCATED OBJECT" + "*" * 40 + str(v)[-400:]) + for (k,v) in d.iteritems()} + errmsg += "\nContexte : %s\n\n" % (pprint.pformat(d)) + print errmsg return news def sync(): @@ -183,25 +199,27 @@ def sync(): t = sys.stdin.read() on_client = json.loads(t) # On récupère où en est le serveur dans le fichier idoine - if os.path.isfile(store_seen_file): - on_server = json.load(open(store_seen_file)) + if os.path.isfile(serverconfig.store_seen_file): + on_server = json.load(open(serverconfig.store_seen_file)) else: on_server = {} # On garde le maximum for k in set(on_client.keys() + on_server.keys()): on_server[k] = max(on_client.get(k, 0), on_server.get(k, 0)) # On enregistre ce nouveau dico - json.dump(on_server, open(store_seen_file, "w")) + json.dump(on_server, open(serverconfig.store_seen_file, "w")) # On envoie au client ce nouveau dico print json.dumps(on_server) if __name__ == "__main__": - if "--debug" in sys.argv or "--verbose" in sys.argv: - DEBUG = True + DEBUG = ("--debug" in sys.argv) or ("--verbose" in sys.argv) or serverconfig.DEBUG if sys.argv[1] == "check": news = fetch_all() - olds = get_file() - olds.update(news) + if "--init" in sys.argv: + olds = news + else: + olds = get_file() + olds.update(news) update_file(olds) elif sys.argv[1] == "whatsup": news = get_file()