def run(start='2015-01-01', end=None): config = common.loadJsonConfig() # connect to api wpApi = wikiApi.WikiApi.setUpApi(user=config['w_username'], password=config['w_password'], site=config['wp_site']) comApi = wikiApi.CommonsApi.setUpApi(user=config['w_username'], password=config['w_password'], site=u'https://commons.wikimedia.org') # find changed pages pageList = wpApi.getEmbeddedin(u'Mall:Offentligkonstlista', 0) contribs, ministats, users = handleContributions(wpApi, pageList, start=start, end=end) images, image_users = handleImages(wpApi, comApi, pageList, start=start, end=end) # combine users users = list(set(users + image_users)) userInfo = wpApi.getUserData(users) # add some more ministats ministats['images'] = len(images) ministats['image_users'] = len(list(set(image_users))) ministats['list_users'] = ministats['users'] ministats['users'] = len(users) f = codecs.open('users.json', 'w', 'utf8') f.write(json.dumps(userInfo, indent=4, ensure_ascii=False)) f.close() f = codecs.open('contribs.json', 'w', 'utf8') f.write(json.dumps(contribs, indent=4, ensure_ascii=False)) f.close() print json.dumps(ministats, indent=4, ensure_ascii=False)
def run(start='2015-01-01', end=None): config = common.loadJsonConfig() # connect to api wpApi = wikiApi.WikiApi.setUpApi(user=config['w_username'], password=config['w_password'], site=config['wp_site']) comApi = wikiApi.CommonsApi.setUpApi(user=config['w_username'], password=config['w_password'], site=u'https://commons.wikimedia.org') # find changed pages pageList = wpApi.getEmbeddedin(u'Mall:Offentligkonstlista', 0) contribs, ministats, users = handleContributions(wpApi, pageList, start=start, end=end) images, image_users = handleImages(wpApi, comApi, pageList, start=start, end=end) # combine users users = list(set(users+image_users)) userInfo = wpApi.getUserData(users) # add some more ministats ministats['images'] = len(images) ministats['image_users'] = len(list(set(image_users))) ministats['list_users'] = ministats['users'] ministats['users'] = len(users) f = codecs.open('users.json', 'w', 'utf8') f.write(json.dumps(userInfo, indent=4, ensure_ascii=False)) f.close() f = codecs.open('contribs.json', 'w', 'utf8') f.write(json.dumps(contribs, indent=4, ensure_ascii=False)) f.close() print json.dumps(ministats, indent=4, ensure_ascii=False)
#!/usr/bin/python # -*- coding: utf-8 -*- ''' Tool for updating the copyright status of an object based on the birth/death year of the artist(s) ToDO: tag free objects with multiple artists update unfree object once it becomes free (relies on multi-artistfix) ''' import odok as odokConnect import common config = common.loadJsonConfig() # Number of years since birth before considering the work to be free (if year of death is unknown) YEARS_AFTER_BIRTH = 150 # Number of years since death before considering the work to be free YEARS_AFTER_DEATH = 70 def tagUnfree(dbWriteSQL, testing): ''' identifies unfree objects based on the birth and/or death year of the artist and also tags any object with multiple artists ''' if testing: query = u"""##would change free=%s\nSELECT `id`, `free`, `title`, `artist` FROM `main_table` """ else: query = u"""UPDATE `main_table` SET free=%s """ query += u"""WHERE `free` = '' AND `id` IN (SELECT `object` FROM `artist_links` WHERE `artist` IN (SELECT `id` FROM `artist_table` WHERE
Expand UGC to rewrite object correctly formatted (including any ignored parameters) Deal with section links (these do not have real wikidata entries) split run into 'generate list of pages to run on' and 'run on a given list of pages' that way a non-main function for runing on a given page can be introduced ''' import dateutil.parser import codecs import datetime import json import common import WikiApi as wikiApi import odok as odokConnect import dataDicts as dataDict import UGC_synk as UGCsynk config = common.loadJsonConfig() def run(verbose=False, days=100, strict=True, testing=False): ''' update database based on all list changes INCOMPLETE ''' # open connections wpApi = wikiApi.WikiApi.setUpApi(user=config['w_username'], password=config['w_password'], site=config['wp_site']) wdApi = wikiApi.WikiDataApi.setUpApi(user=config['w_username'], password=config['w_password'], site=config['wd_site']) dbApi = odokConnect.OdokApi.setUpApi(user=config['odok_user'],