forked from g0v/koktai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload_img_to_wiki.py
50 lines (40 loc) · 1.74 KB
/
upload_img_to_wiki.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
# -*- coding: utf-8 -*-
import requests
import pywikibot, sys
from upload import UploadRobot
import os
def complete_desc_and_upload(filename, pagetitle, code, date):
#complete this once if applies to all files
description = u"""{{Information
|Description = {{en|1=Non-encodable character, coded """ + code + u""" in original Koktai dictionnary}}
|Source = https://github.com/g0v/koktai
|Author = 吳壽禮
|Date = """ + date + u"""
|Permission = {{Cc-by-sa-4.0|吳壽禮}}
}}
=={{int:license-header}}==
CC-BY-SA
"""
url = filename
keepFilename=True #False #set to True to skip double-checking/editing destination filename
verifyDescription=False #True #set to False to skip double-checking/editing description => change to bot-mode
targetSite = pywikibot.Site('commons', 'commons')
bot = UploadRobot(url, description=description, useFilename=pagetitle, keepFilename=keepFilename, verifyDescription=verifyDescription, targetSite = targetSite)
bot.upload_image(debug=True)
#print "would upload", url, description, pagetitle, keepFilename, verifyDescription, targetSite
def main(args):
#list each file here
for path in args:
basename = os.path.basename(path)
code = basename.rsplit(".",1)[0]
filename = path
pagetitle = u"Koktai dictionary missing char " + basename + ".png"
r = requests.get("https://commons.wikimedia.org/wiki/File:Koktai_dictionary_missing_char_%s.png" % (basename,))
if not r.ok:
date = "2016-03-02"
complete_desc_and_upload(filename, pagetitle, code, date)
else:
print(basename, "allready uploaded")
if __name__ == "__main__":
main(sys.argv[1:])
pywikibot.stopme()