]> gitweb.pimeys.fr Git - today.git/commitdiff
[client] Les ids ne sont plus hardcodés, et du coup on peut update tout et n'importe...
authorVincent Le Gallic <legallic@crans.org>
Sat, 15 Feb 2014 02:33:38 +0000 (03:33 +0100)
committerVincent Le Gallic <legallic@crans.org>
Sat, 15 Feb 2014 02:33:42 +0000 (03:33 +0100)
Évidemment, si un jour on sort un id du genre "check" ou "sync", ça va être le bordel…

today.py

index b05a4553128043c6db87bd367aba7be8f0293779..97fb8fa92cd8a5e67fa975fa645962d8db01091d 100755 (executable)
--- a/today.py
+++ b/today.py
@@ -58,7 +58,7 @@ def is_int(a):
     except ValueError:
         return False
 
-def update_last_seen(newdict):
+def update_last_seen(newdict, lasts_seen=None):
     """Met à jour un des derniers trucs vus/lus"""
     if not all([is_int(v) or (v == "last") for v in newdict.values()]):
         raise ValueError("Donner un entier ou last")
@@ -70,10 +70,12 @@ def update_last_seen(newdict):
             newdict[key] = lasts_published[key]
     # On convertit les chaînes en entier (pour les <last_id> il leur arrive rien)
     newdict = {k: int(v) for (k,v) in newdict.items()}
-    lasts_seen = get_last_seen()
+    if not lasts_seen is None:
+        lasts_seen = get_last_seen()
     lasts_seen.update(newdict)
     with open(config.last_seen_file, "w") as f:
         f.write(json.dumps(lasts_seen))
+    return ", ".join(["last %s to %s" % (id, n) for (id, n) in newdict.items()])
 
 def parse_datefile(namefile):
     """Ouvre et parse un fichier avec des lignes de la forme
@@ -233,36 +235,6 @@ def get_dtc(*args):
     textquotes = format_quotes(quotes)
     return textquotes
 
-def update_xkcd(newid):
-    update_last_seen({"xkcd" : newid})
-
-def update_xantah(newid):
-    update_last_seen({"xantah" : newid})
-
-def update_visiteur(newid):
-    update_last_seen({"visiteur" : newid})
-
-def update_noob(newid):
-    update_last_seen({"noob" : newid})
-
-def update_warpzone(newid):
-    update_last_seen({"warpzone" : newid})
-
-def update_hugo(newid):
-    update_last_seen({"hugo" : newid})
-
-def update_norman(newid):
-    update_last_seen({"norman" : newid})
-
-def update_cyprien(newid):
-    update_last_seen({"cyprien" : newid})
-
-def update_grenier(newid):
-    update_last_seen({"grenier" : newid})
-
-def update_jl8(newid):
-    update_last_seen({"dc" : newid})
-
 
 def get_whatsup():
     """Récupère sur le serveur les derniers trucs."""
@@ -391,17 +363,6 @@ AUTOMATED_ACTIONS = {
 
 #: Les actions qu'on peut effectuer en rajoutant des paramètres
 OTHER_ACTIONS = {
-           "xkcd" : update_xkcd,
-           "xantah" : update_xantah,
-           "visiteur" : update_visiteur,
-           "noob" : update_noob,
-           "warpzone" : update_warpzone,
-           "hugo" : update_hugo,
-           "norman" : update_norman,
-           "cyprien" : update_cyprien,
-           "grenier" : update_grenier,
-           "dc" : update_jl8,
-           
            "dtc" : get_dtc,
            "ping" : ping,
            "show" : affiche,
@@ -427,12 +388,20 @@ if __name__ == "__main__":
     if "--no-remote" in sys.argv:
         config.do_remote = False
         sys.argv.remove("--no-remote")
+    output = None
     if len(sys.argv) == 1:
         # Juste un today
         output = ACTIONS[None]()
     else:
         commande = sys.argv[1]
         args = [s.decode("utf-8") for s in sys.argv[2:]]
-        output = ACTIONS[commande](*args)
+        if commande in ACTIONS:
+            output = ACTIONS[commande](*args)
+        else:
+            # on tente un update
+            lasts_seen  = get_last_seen()
+            if not commande in lasts_seen:
+                print "Attention : n'existait pas avant."
+            output = update_last_seen({commande : args[0]}, lasts_seen)
     if output:
         print output.encode("utf-8")