checkuser, Administrators
2,635
edits
Zhuyifei1999 (talk | contribs) (R) |
Zhuyifei1999 (talk | contribs) (Update) |
||
Line 15: | Line 15: | ||
import sys | import sys | ||
import urllib | import urllib | ||
from datetime import datetime | |||
# This is required for the text that is shown when you run this script | # This is required for the text that is shown when you run this script | ||
Line 60: | Line 61: | ||
newtext = text | newtext = text | ||
size_r = re.compile(ur"""(?im)(?P<all>\{\{\s*Size\s*((\s*\|\s*(?P<pages>pages|wiki[ _]pages)\s*=\s*(?P<pages_value>\d*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<pagesurl>statistics[ _]URL|wiki[ _]statistics[ _]URL)\s*=\s*(?P<pagesurl_value>https?://[^ \|\}\<]*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<wikifactor>wikiFactor)\s*=\s*(?P<wikifactor_value>\d*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<wikifactorurl>wikiFactor[ _]URL)\s*=\s*(?P<wikifactorurl_value>http://[^ \|\}\<]*)\s*[^\|\}]*\s*))+\s*\|?\s*\}\} | size_r = re.compile(ur"""(?im)(?P<all>\{\{\s*Size\s*((\s*\|\s*(?P<pages>pages|wiki[ _]pages)\s*=\s*(?P<pages_value>\d*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<pagesurl>statistics[ _]URL|wiki[ _]statistics[ _]URL)\s*=\s*(?P<pagesurl_value>https?://[^ \|\}\<]*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<wikifactor>wikiFactor)\s*=\s*(?P<wikifactor_value>\d*)\s*[^\|\}]*\s*)|(\s*\|\s*(?P<wikifactorurl>wikiFactor[ _]URL)\s*=\s*(?P<wikifactorurl_value>http://[^ \|\}\<]*)\s*[^\|\}]*\s*))+\s*\|?\s*\}\}(\(As[ _]of[ _](?P<day>\d*)[ _](?P<month>)[ _](?P<year>\d*)\)+\s*\|?\s*))""") | ||
wtext = page.get() | wtext = page.get() | ||
m = size_r.finditer(wtext) | m = size_r.finditer(wtext) | ||
all = "" | all = "" | ||
newvalues = "" | newvalues = "" | ||
Line 77: | Line 79: | ||
wikifactor_value = i.group('wikifactor_value') and i.group('wikifactor_value').strip() or '' | wikifactor_value = i.group('wikifactor_value') and i.group('wikifactor_value').strip() or '' | ||
wikifactorurl_value = i.group('wikifactorurl_value') and i.group('wikifactorurl_value').strip() or '' | wikifactorurl_value = i.group('wikifactorurl_value') and i.group('wikifactorurl_value').strip() or '' | ||
time_all = i.group('all') and i.group('all').strip() or '' | |||
day = i.group('day') and i.group('day').strip() or '' | day = i.group('day') and i.group('day').strip() or '' | ||
month = i.group('month') and i.group('month').strip() or '' | month = i.group('month') and i.group('month').strip() or '' | ||
year = i.group('year') and i.group('year').strip() or '' | year = i.group('year') and i.group('year').strip() or '' | ||
#get new values | #get new values | ||
n = re.findall(ur"(https?://[^\|\}\]]+\?action=raw|https?://[^\|\}\]]+:Statistics)", pagesurl_value) | n = re.findall(ur"(https?://[^\|\}\]]+\?action=raw|https?://[^\|\}\]]+:Statistics)", pagesurl_value) | ||
Line 97: | Line 100: | ||
if o: | if o: | ||
if o[0] and int(pages_value) != int(o[0]): | if o[0] and int(pages_value) != int(o[0]): | ||
comment = u"Robot: Updating size: %s -> %s" % (pages_value, o[0]) | |||
pages_value = o[0] | pages_value = o[0] | ||
newtime = True | |||
else: | else: | ||
break | break | ||
Line 116: | Line 120: | ||
print wikifactorurl, wikifactorurl_value""" | print wikifactorurl, wikifactorurl_value""" | ||
if newtime: | |||
dt = datetime.date(datetime.utcnow()) | |||
day = dt.strftime('%d') | |||
month = dt.strftime('%B') | |||
year = dt.strftime('%Y') | |||
newvalues = u"""{{Size <!--see Template:Size for full detail--> | newvalues = u"""{{Size <!--see Template:Size for full detail--> | ||
| %s = %s <!--type the plain number of pages - NO thousands separators--> | | %s = %s <!--type the plain number of pages - NO thousands separators--> | ||
Line 121: | Line 132: | ||
| %s = %s <!--preferred; if unknown leave void; see: Category:wikiFactor for help--> | | %s = %s <!--preferred; if unknown leave void; see: Category:wikiFactor for help--> | ||
| %s = %s <!--wF source (often 'PopularPages', 'Mostvisitedpages' or 'PageHits'); if unknown leave void--> | | %s = %s <!--wF source (often 'PopularPages', 'Mostvisitedpages' or 'PageHits'); if unknown leave void--> | ||
}}""" % (pages and pages or 'pages', pages_value and pages_value or '', pagesurl and pagesurl or 'statistics URL', pagesurl_value and pagesurl_value or '', wikifactor and wikifactor or 'wikiFactor', wikifactor_value and wikifactor_value or '', wikifactorurl and wikifactorurl or 'wikiFactor URL', wikifactorurl_value and wikifactorurl_value or '') | }}(As of: %s %s %s)<!--manually add/amend date when stats are verified and/or updated-->""" % (pages and pages or 'pages', pages_value and pages_value or '', pagesurl and pagesurl or 'statistics URL', pagesurl_value and pagesurl_value or '', wikifactor and wikifactor or 'wikiFactor', wikifactor_value and wikifactor_value or '', wikifactorurl and wikifactorurl or 'wikiFactor URL', wikifactorurl_value and wikifactorurl_value or '', day and day or '', month and month or '', year and year or '') | ||
newtext = text.replace(all, newvalues) | newtext = text.replace(all, newvalues) | ||
if not self.save(newtext, page, self.summary): | if not self.save(newtext, page, self.summary): |