def testDate(date): ''' Check that a date is YYYY or YYYY-MM or YYYY-MM-DD ''' date = date.lower().strip('ca ') item = date[:len('YYYY-MM-DD')].split('-') if len(item) == 3 and all(common.is_pos_int(x) for x in item) and \ int(item[1][:len('MM')]) in range(1, 12 + 1) and \ int(item[2][:len('DD')]) in range(1, 31 + 1): # 1921-09-17Z or 2014-07-11T08:14:46Z return None elif len(item) == 1 and common.is_pos_int(item[0][:len('YYYY')]): # 1921Z return None elif len(item) == 2 and \ all(common.is_pos_int(x) for x in (item[0], item[1][:len('MM')])) and \ int(item[1][:len('MM')]) in range(1, 12 + 1): # 1921-09Z return None elif len(item) == 2 and common.is_pos_int(item[0][:len('YYYY')]) and \ item[1] == u'talet': # 1900-talet return None else: return u'Weirdly formated date: %s' % date
def get_deathyear(self, item): """ Return the latest of all found death dates related to a item. @return: int or None """ # internal markup for unknown or something weird unknown = (u't329875228', u't318787658', u't329488873', u't318035461') deathyears = [] # via wikidata for item wd_painting = self.wd_paintings.get(item.get_obj_id()) if wd_painting and wd_painting.get('death_dates'): deathyears += wd_painting.get('death_dates') # via wikidata for knwon lido artist lido_artists = item.get_artists() for nsid in lido_artists.keys(): wd_artist = self.wd_creators.get(nsid) if wd_artist and wd_artist.get('death_dates'): deathyears += wd_artist.get('death_dates') # remove dupes and unknowns deathyears = list(set(deathyears) - set(unknown)) # identify the largest year = None for deathyear in deathyears: if not common.is_pos_int(deathyear[:4]): pywikibot.error("Found non-integer deathyear: %s" % deathyear) deathyear = int(deathyear[:4]) if deathyear > year: # works as any int > None year = deathyear return year
def isoDate(date): """Given a string this returns an iso date (if possible).""" item = date[:len('YYYY-MM-DD')].split('-') if len(item) == 3 and all(common.is_pos_int(x) for x in item) and \ int(item[1][:len('MM')]) in range(1, 12 + 1) and \ int(item[2][:len('DD')]) in range(1, 31 + 1): # 1921-09-17Z or 2014-07-11T08:14:46Z return '%s-%s-%s' % (item[0], item[1], item[2]) elif len(item) == 1 and common.is_pos_int(item[0][:len('YYYY')]): # 1921Z return item[0] elif (len(item) == 2 and all( common.is_pos_int(x) for x in (item[0], item[1][:len('MM')])) and int(item[1][:len('MM')]) in range(1, 12 + 1)): # 1921-09Z return '%s-%s' % (item[0], item[1]) else: return None
def main(*args): """Command line entry-point.""" usage = ( 'Usage:' '\tpython uploader.py -in_path:PATH -dir:PATH -cutoff:NUM\n' '\t-in_path:PATH path to the directory containing the media files or ' 'to the make_info output file if "-type" is set to url\n' '\t-type:STRING the type of upload to make. Must be either "FILES" ' 'or "URL". Defaults to FILES (optional)\n' '\t-dir:PATH specifies the path to the directory containing a ' 'user_config.py file (optional)\n' '\t-cutoff:NUM stop the upload after the specified number of files ' '(optional)\n' '\t-confirm Whether to output a confirmation after each upload ' 'attempt (optional)\n' '\t-test Whether to do mock upload, simply outputting to commandline. ' '(optional)\n' '\t-nochunk Whether to turn off chunked uploading, this is slow ' 'and does not support files > 100Mb (optional, type:FILES only)\n' '\t-only:PATH to file containing list of urls to upload, skipping all ' 'others. One entry per line. (optional, type:URL only)\n' '\t-skip:PATH to file containing list of urls to skip, uploading all ' 'others. Can be combined with "-only" for further filtering, e.g ' '"-only:<list of vase images> -skip:<list of blue images>" to get ' 'non-blue vase images. One entry per line. (optional, type:URL only)\n' '\tExample:\n' '\tpython uploader.py -in_path:../diskkopia -cutoff:100\n') cutoff = None in_path = None test = False confirm = False chunked = True typ = 'files' only = None skip = None # Load pywikibot args and handle local args for arg in pywikibot.handle_args(args): option, sep, value = arg.partition(':') if option == '-cutoff': if common.is_pos_int(value): cutoff = int(value) elif option == '-in_path': in_path = value elif option == '-test': test = True elif option == '-confirm': confirm = True elif option == '-nochunk': chunked = False elif option == '-type': if value.lower() == 'url': typ = 'url' elif value.lower() not in ('url', 'files'): pywikibot.output(usage) return elif option == '-only': only = common.trim_list( common.open_and_read_file(value).split('\n')) elif option == '-skip': skip = common.trim_list( common.open_and_read_file(value).split('\n')) elif option == '-usage': pywikibot.output(usage) return if in_path: if typ == 'files': up_all(in_path, cutoff=cutoff, test=test, verbose=confirm, chunked=chunked) elif typ == 'url': up_all_from_url(in_path, cutoff=cutoff, only=only, skip=skip, test=test, verbose=confirm) else: pywikibot.output(usage)