-
Notifications
You must be signed in to change notification settings - Fork 8
/
addtext.py
35 lines (30 loc) · 1022 Bytes
/
addtext.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from __future__ import unicode_literals
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Add some text to a wiki page
# Mike Peel 11-Jul-2017 v1 - initial version
import pywikibot
import numpy as np
import time
import string
from pywikibot import pagegenerators
import time
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
def addtext(site, project, toedit, text, othertext='',rate=10, trialrun=0):
site = pywikibot.Site('commons', 'commons')
repo = site.data_repository() # this is a DataSite object
for item in toedit:
item = item.decode('utf-8').strip()
print item
page = pywikibot.Page(site, item)
if page.text == '':
print "Error - page is empty!"
elif text not in page.text:
if (othertext == '') or (othertext not in page.text):
if trialrun:
print ' - To edit'
else:
page.text = page.text + "\n" + text
page.save(u"Adding " + text)