def main(): config = configparser.ConfigParser() config.read("pwrbot.cfg") # read wiki login wikiSect = "WIKI" userOpt = "username" pwOpt = "password" if not config.has_option(wikiSect, userOpt) and not config.has_option(wikiSect, pwOpt): print("No wiki login data found. Using simocraPy credentials.") wiki.login() else: username = config[wikiSect][userOpt] password = config[wikiSect][pwOpt] wiki.login(username, password) # read football stats settings statSect = "FOOTBALLSTATS" articleOpt = "article" mainteamOpt = "teamflags" if config.has_section(statSect): optLength = len(config.items(statSect)) if optLength % 2 != 0: print("Wrong option count in section" + statSect) return for i in range(0, optLength//2): art = config[statSect][articleOpt+str(i)] team = config[statSect][mainteamOpt+str(i)].split(',') print("Search for " + str(team) + " in article " + art) footballMatch.analyseFootballStats(art, team) """
def main(): opener = wiki.login() #Datei öffnen if len(sys.argv) < 2: print("missing argument: "+sys.argv[0]+" FILENAME") exit() if sys.argv[0] == sys.argv[1]: print("nope") file = open(sys.argv[1], "w") #Revisions sammeln revs = {} for page in wiki.allPages(): ##zerbricht an ß #title = urllib.parse.quote(page) title = page xml = wiki.sendQuery( "redirects", "prop=revisions", "titles="+urllib.parse.quote(page), "rvdir=older", "rvlimit=max") #redirects ausschließen #xml = xml.find("query").find("pages") #if not xml: # continue #title = xml.find("page").attrib["title"] #if title in revs: # continue #letzte Fluggbot-revision finden fluggbotid = 0 found = False for el in xml.iter(): if el.tag != "rev": continue if el.attrib["user"] != "Fluggbot": continue found = True id = int(el.attrib["revid"]) if id > fluggbotid: fluggbotid = id if not found: continue #letzte revision vor Fluggbot finden lastrevid = 0 for el in xml.iter(): if el.tag != "rev": continue if el.attrib["user"] == "Fluggbot": continue id = int(el.attrib["revid"]) if id > lastrevid and id < fluggbotid: lastrevid = id revs[title] = str(lastrevid) #Revisioncontents parsen und LD-Host-Links extrahieren links = [] for title in revs: qry = wiki.buildQuery(( "titles="+title, "prop=revisions", "rvstartid="+revs[title], "rvprop=content", "rvlimit=1", "redirects")) print(qry) try: r = wiki.opener.open(wiki._url+"api.php"+qry) except: print("Überspringe "+title) continue text = [] for line in r.readlines(): text.append(line.decode('utf-8')) found = extractLDHostLinks(text) for el in found: if not el in links: links.append(el) print(str(len(links))+" Links gefunden, schreibe in "+sys.argv[1]) for el in links: file.write(el + "\n")
def main(): opener = wiki.login(wiki.username, wiki.password) for p in wiki.allPages(opener, resume="speed"): doIt(p, opener)
def handle(self, *args, **options): wiki.login() vz = wiki.readVZ() staaten = wiki.readStates(vz) bnds = vz["buendnisse"] """ DB-Modelle aufbauen """ # Alte Daten löschen Staat.objects.all().delete() Buendnis.objects.all().delete() # "Kein Bündnis"-Bündnis neutralbnd = Buendnis() neutralbnd.name = "Kein Bündnis" neutralbnd.flagge = self.platzhalter neutralbnd.save() i = 1 for buendnis in bnds: bnd = Buendnis() bnd.nummer = i bnd.flagge = buendnis["flagge"] bnd.name = buendnis["name"] bnd.save() i += 1 # Staaten sortieren # staaten = sorted(staaten, key=lambda k: k['name']) i = 1 for state in staaten: # nur bespielte Staaten eintragen if state["spielerlos"]: continue staat = Staat() staat.nummer = i staat.name = state["name"] flag = "[[" + state["infobox"]["Flagge"] + "]]" staat.flagge = wiki.extractFlag(flag) staat.spieler = state["spieler"] staat.ms = state["ms"] staat.bomben = state["as"] staat.zweitstaat = state["zweitstaat"] i += 1 # Bündnis suchen found = False for bnd in Buendnis.objects.all(): if bnd.flagge == state["buendnis"]: staat.buendnis = bnd found = True if not found: if state["buendnis"] != self.neutralflagge: self.stdout.write( "Konnte " + state["buendnis"] + " keinem bestehenden Bündnis zuordnen. " + state["name"] + " wird daher als neutral eingetragen." ) staat.buendnis = neutralbnd staat.save() # Timestamp schreiben f = open("/home/fluggs/sysite/mssim/lastupdate", "w") f.write(str(int(time.time()))) f.close() print("mssim-db aktualisiert") # IAS IAS.updateArticle(staaten) print("IAS aktualisiert")