]>
gitweb.pimeys.fr Git - today.git/blob - today_server.py
2 # -*- encoding: utf-8 -*-
5 script qui affiche des trucs à penser, des J-n des conneries
8 Partie serveur, prévue pour chercher périodiquement les trucs non lus
9 et répondre à un check.
14 from lxml
import etree
19 os
.chdir('/home/vincent/scripts/today/')
24 #: Récupération de toutes les nouveautés
28 p
= urllib
.urlopen("http://xkcd.com")
30 current_id
= int(re
.findall("Permanent link to this comic: http://xkcd.com/(.*?)/", t
)[0])
34 p
= urllib
.urlopen("http://www.adoprixtoxis.com/lite/download/xantah_downloads.php")
36 ids
= re
.findall("""<div class="top">Xantah (.*?)</div>""", t
)
37 ids
= [int(i
) for i
in ids
]
41 rss
= urllib
.urlopen("http://limbero.org/jl8/rss/")
43 x
= etree
.fromstring(t
)
44 links
= x
.xpath("//link")
45 maxnum
= links
[1].text
.split("/")[-1]
50 """Récupère la liste des derniers ids de chaque truc, stockée dans le fichier."""
51 f
= open(serverconfig
.store_published_file
)
56 def update_file(news
):
57 """Met à jour la liste des derniers ids dans le fichier."""
58 f
= open(serverconfig
.store_published_file
, 'w')
64 "xantah" : last_xantah
,
69 """Va chercher sur les différents sites les nouveaux trucs."""
71 for (k
, f
) in FETCHS
.iteritems():
74 except Exception as e
:
76 news
.update(gather
.gather())
80 """Reçoit une requête de synchronisation."""
81 # On récupère où en est le client sur stdin
83 on_client
= json
.loads(t
)
84 # On récupère où en est le serveur dans le fichier idoine
85 if os
.path
.isfile(serverconfig
.store_seen_file
):
86 on_server
= json
.load(open(serverconfig
.store_seen_file
))
90 for k
in set(on_client
.keys() + on_server
.keys()):
91 on_server
[k
] = max(on_client
.get(k
, 0), on_server
.get(k
, 0))
92 # On enregistre ce nouveau dico
93 json
.dump(on_server
, open(serverconfig
.store_seen_file
, "w"))
94 # On envoie au client ce nouveau dico
95 print json
.dumps(on_server
)
97 if __name__
== "__main__":
98 DEBUG
= ("--debug" in sys
.argv
) or ("--verbose" in sys
.argv
) or serverconfig
.DEBUG
99 if sys
.argv
[1] == "check":
101 if "--init" in sys
.argv
:
107 elif sys
.argv
[1] == "whatsup":
109 print json
.dumps(news
)
110 elif sys
.argv
[1] == "sync":