FeD:Code/Statusofclub
Aus Förderverein euregionale Digitalkultur e.V.
< FeD:Code
Ein kleines Plugin für den Goozerbot So funktioniert es:
!statusofclub
# plugs/statusofclub.py # -*- coding: latin-1 -*- # # I'm a charging my lazers! *KAWOOOOM* __copyright__ = 'FeD e.V.' __revision__ = '$Id: statusofclub.py 3 2010-02-18 23:50:00Z deck $' from gozerbot.generic import handle_exception from gozerbot.commands import cmnds from gozerbot.examples import examples from gozerbot.plughelp import plughelp from gozerbot.tests import tests import urllib2 import re, random plughelp.add('statusofclub', 'display the opening status of the Hackerspace') #So sieht ein wikieintrag aus #(Aktuell) (Vorherige) 09:48, 17. Feb. 2010 Airmack (Diskussion | Beiträge) (16 Bytes) (Geschlossen) #Alle nachrichten zu oeffnen und schliessen #SYNTAX # $SATZ, $USER $UHRZEIT OPENLINE=["Status of Hackerspace: Open, ", "Der Hackspace ist offen, "] # $SATZ CLOSEDLINE=["Status of Hackerspace: Closed", "Der Hackspace ist geschlossen."] # $BLAME $USER BLAME=["Somebody fucked up big times. Nicely done ", "Dir muss man auch alles beibringen, "] def handle_statusofclub(bot, ievent): # create a browser & open website data="" searchstring=urllib2.urlopen("https://fedev.eu/index.php?title=FeD:Voidspace/Status&action=raw").read() if str(searchstring).find('{{Statusbox|zu}}') != -1: data=CLOSEDLINE[random.randint(0,len(CLOSEDLINE)-1)] elif searchstring.find('{{Statusbox|auf}}') !=-1: # user who updated last userbuffer=urllib2.urlopen("https://fedev.eu/index.php?title=FeD:Voidspace/Status&limit=1&action=history&useskin=simple").read() c1=userbuffer.find('/index.php/Benutzer:')+20 c2=userbuffer.find(" title=",c1)-1 user=blamebuffer[c1:c2] # 15:01, 18. Feb. 2010 try: date=re.compile('[0-9]{2}:[0-9]{2}, [0-9]{1,2}. [A-Z]{3}. [0-9]{4}', re.IGNORECASE).findall(userbuffer))[0][0:5] data=OPENLINE[random.randint(0,len(OPENLINE)-1)]+" by " +user+" at "+date except: data=OPENLINE[random.randint(0,len(OPENLINE)-1)]+" by " +user else: # check for whom to blame blame=urllib2.urlopen("https://fedev.eu/index.php?title=FeD:Voidspace/Status&limit=1&action=history&useskin=simple") blamebuffer=blame.read() # c1&c2 begin and end of username c1=blamebuffer.find('/index.php/Benutzer:')+20 c2=blamebuffer.find(" title=",c1)-1 user=blamebuffer[c1:c2] data=BLAME[random.randint(0,len(BLAME)-1)] +user+"!" ievent.reply(data) cmnds.add('statusofclub', handle_statusofclub, 'USER') examples.add('statusofclub', 'show statusofclub', 'statusofclub')