From 18dc797478ece73aaf30c5322303d05006474d28 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Tue, 9 Apr 2013 05:10:14 +0200 Subject: [PATCH] tentative de last_noob, non fonctionnelle --- today_server.py | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/today_server.py b/today_server.py index cadb02d..98e4844 100755 --- a/today_server.py +++ b/today_server.py @@ -11,7 +11,9 @@ et répondre à un check. """ import time, datetime +import locale import re +import BeautifulSoup import os import sys import urllib @@ -33,6 +35,26 @@ def get_now(): now = datetime.datetime(*time.localtime(timestamp)[:7]) return now +def parse_date(s, french=True): + """Essaye d'obtenir une date à partir du string fourni""" + s = s.lower() + if isinstance(s, unicode): + s = s.encode("utf-8") + if s.startswith("le "): + s = s[3:] + # Y U PARKINSON ? + s = re.sub(" +", " ", s) + # Pour avoir les noms de dates en Français + if french: + locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8') + for format in ["%d %B %Y"]: + try: + struct = time.strptime(s, format) + return datetime.datetime(*struct[:7]) + except ValueError: + pass + raise ValueError("%r : Didn't manage to convert as date, sorry." % (s,)) + def last_dtc(): """Vérifie si il y a des quotes DTC non lues""" return dtc.last_inserted() @@ -63,6 +85,40 @@ def last_visiteur(): nepisodes = len(episodes) return nsaisons * 100 + nepisodes +def last_noob_warpzone(): + p = urllib.urlopen("http://noob-tv.com/agenda01.html") + t = p.read() + # On parse + soup = BeautifulSoup.BeautifulSoup(t) + # On récupère tous les évènements + garbage = soup.findAll("strong") + events = [] + for o in garbage: + l = o.findAll("span", attrs={"class":"Style31"}) + if l: + events.append([o.text[:o.text.index(":")].strip(), l[0].string.lower().strip()]) # la date, l'event + # On garde que les "sorties" + events = [o for o in events if "sortie" in o[1]] + # Fucking HTML + events = [[o[0].replace(u"û", u"û").replace(u"é", u"é"), o[1]] for o in events] + # Parsing des dates + eventss = [] + for i in range(len(events)): + raw_date, event = events[i] + try: + eventss.append([parse_date(raw_date), event]) + except ValueError: + pass + events = eventss + del eventss + noobs = [ev for ev in events if "noob" in ev[1]] + warpzones = [ev for ev in events if "warpzone" in ev[1]] + # On prend en considération le dernier évènement qui a eu lieu + now = get_now() + ###### + ###### RHÂ, shit, y'a des fuckings trucs du genre "1er" dans les dates… :/ + return noobs, warpzones + def get_file(): """Récupère la liste des derniers ids de chaque truc, stockée dans le fichiers.""" f = open(store_published_file) -- 2.39.2