Instantly share code, notes, and snippets.

Embed
What would you like to do?
import sys, pywikibot, re
from pywikibot import pagegenerators
pywikibot.handle_args(sys.argv[1:])
gen = pagegenerators.SearchPageGenerator('http://www.orientering.se', namespaces = [0])
pattern = re.compile(r'(http:\/\/www.orientering\.se(?:\/[A-Za-z0-9\-\._~:\/\?\&\=]*)?)')
class Memory:
def __init__(self, oldURL, newURL):
self.oldURL = oldURL
self.newURL = newURL
def proccessPage(page):
for url in re.findall(pattern, str(page.text)):
for past in memoryContainer:
if (url == past.oldURL):
print('auto edit' + url)
editPage(page, url, past.newURL)
return
print(url)
uInput = input('Enter new link, or enter "skip":')
if (uInput == 'skip'):
print('skiped')
return
else:
memoryContainer.append(Memory(url, uInput))
print('new link')
editPage(page, url, uInput)
return
def editPage(page, old, new):
page.text = page.text.replace(old, new)
page.save('updated link to SOFT(svenskorientering.se)')
memoryContainer = []
pages = 0
for page in gen:
print('working on: ' + str(page))
proccessPage(page)
pages += 1
print(pages)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment