-
Notifications
You must be signed in to change notification settings - Fork 8
/
commons_fi_by_user.py
74 lines (67 loc) · 3.21 KB
/
commons_fi_by_user.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Featured Image categories by user
# Mike Peel 15-Jan-2022 v1 - start
# Import modules
import pywikibot
from pywikibot import pagegenerators
commons = pywikibot.Site('commons', 'commons')
targetcat = 'Category:Featured pictures by creator'
destinationpage = 'Commons:Featured pictures/Statistics/Featured pictures by creator'
skip = ['by country', 'by subject', 'images from', 'Wiki Loves']
page = pywikibot.Page(commons, destinationpage)
pagetext = '{{en|This is a list of [[Commons:Featured pictures|featured pictures]] by user. If you want to be included in this list, create a subcategory of [[:Category:Featured pictures by creator]] with the format \'Featured images by <username>\', and you will be included in this list with the next bot update (daily). This page is automatically updated by [[User:Pi bot]]. If you want to change the format of this page, or want to be excluded from this list, please contact [[User:Mike Peel]]. Manual changes will be ignored by the bot update.}}\n== {{LangSwitch|cs=Tabulka|de=Tabelle|en=Table|es=Tabla|zh=表格}} ==\n\n{|class="wikitable sortable" cellspacing="0"\n!{{LangSwitch|de=Benutzer|en=User|es=Usuario|zh=用戶}}\n!{{LangSwitch|de=Kategorie|en=Category|es=Categoría|zh=分類}}\n!{{LangSwitch|de=Anzahl FPs|es=Imágenes Destacadas|en=Featured Pictures {{FP star|size=15}}|zh=優質圖像數量}}\n'
cat = pywikibot.Category(commons, targetcat)
subcats = pagegenerators.SubCategoriesPageGenerator(cat, recurse=False);
for subcat in subcats:
skipthis = False
for toskip in skip:
if toskip in subcat.title():
skipthis = True
if skipthis:
continue
print(subcat.title())
title = subcat.title()
title = title.replace('By','by')
title = title.replace('user','User')
print(title)
if "'s" in title:
username = title.split("'s")[0]
elif " - " in title:
username = title.split("-")[0]
elif "/" in title:
username = title.split("/")[0]
elif "of " in title:
username = title.split("of ")[1]
elif "from " in title:
username = title.split("from ")[1]
else:
username = title.split('by ')[1]
username = username.replace('User:','')
username = username.replace('Photographs by','')
username = username.replace('Files by','')
username = username.replace('Category:','')
username = username.replace('Yann Forget','Yann')
if '(' in username:
username = username.split('(')[0]
username = username.strip()
if '/' in username:
username = username.split('/')[0]
pagetext = pagetext + '|-\n'+'|[[User:'+username+'|'+username+']] || [[:'+subcat.title() + '|'
count = 0
filenames = []
files = pagegenerators.CategorizedPageGenerator(subcat, recurse=False);
for file in files:
if file.title() not in filenames:
filenames.append(file.title())
count += 1
for result in pagegenerators.SubCategoriesPageGenerator(subcat, recurse=False):
files = pagegenerators.CategorizedPageGenerator(result, recurse=False);
for file in files:
if file.title() not in filenames:
filenames.append(file.title())
count += 1
pagetext = pagetext + subcat.title().replace('Category:','') + ']] || align="right" | ' + str(count) + '\n'
pagetext = pagetext + '\n|}[[Category:Featured pictures by creator| ]]'
page.text = pagetext
page.save('Updating')