-
Notifications
You must be signed in to change notification settings - Fork 0
/
vehicle-upload.py
89 lines (76 loc) · 4.11 KB
/
vehicle-upload.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import subprocess
import logging
import argparse
import sys
from fileprocessor import Fileprocessor
from model_wiki import Model_wiki
fileprocessor = Fileprocessor()
modelwiki = Model_wiki()
parser = argparse.ArgumentParser(
description="upload photos of vehicle to Wikimedia Commons. Sample filename: аа903 69_20120520_369_colorwhite_r2.JPG"
)
parser.add_argument("filepath")
parser.add_argument('-v', '--vehicle', type=str, required=True, choices=[
'tram', 'trolleybus', 'bus', 'train', 'locomotive', 'station', 'auto','metro'])
parser.add_argument('-sys', '--system', type=str, required=False,
help='wikidata id or wikidata name of transport system. Not applied to "auto" ')
parser.add_argument('-c', '--city', type=str, required=False,
help='wikidata id or wikidata name of city for "auto" ')
parser.add_argument('-m', '--model', type=str, required='station' not in sys.argv,
help='wikidata id or wikidata name of vehicle model')
parser.add_argument('-st', '--street', type=str, default=None, required=False,
help='wikidata id or wikidata name of streer or highway')
parser.add_argument('-n', '--number', type=str, required=False,
help='vehicle number. Use BEFORE_UNDERSCORE to extract 3213 from 3213_20060702_162.jpg ')
parser.add_argument('--digital_number', type=str, required=False,
help='optional digit vehicle number for Wikimedia Commons category. Example: 1468 from 2TE10M-1468 ')
parser.add_argument('-ro', '--route', type=str,
required=False, help='vehicle route text')
parser.add_argument('-op', '--operator', type=str,
required=False, help='vehicle operator')
parser.add_argument('-opc', '--operator-vehicle-category', type=str,
required=False, help='commons category for vehicle operator like Operatorname buses')
parser.add_argument('--line', type=str, required=False,
help='railway line wikidata object for trains')
parser.add_argument("--country", type=str, required=True,
default='Russia', help='Country for {{Taken on}} template')
parser.add_argument('--facing', type=str, required=False, choices=['Left', 'Right', 'Front', 'Rear',
'Side', 'Three-quarter', 'Rear three-quarter'], help='puts in [[Category:Trolleybuses facing left]]')
parser.add_argument('--colors', type=str, nargs='+', required=False,
help='puts in [[Category:Green and yellow trams]]')
parser.add_argument('-s', "--secondary-objects", type=str, nargs='+', required=False,
help='secondary wikidata objects, used in category calc with country')
parser.add_argument("--progress", required=False, action="store_const",
default=False, help='display progress bar for folder upload', const=True)
parser.add_argument(
"-dry", "--dry-run", action="store_const", required=False, default=False, const=True
)
parser.add_argument("-l", "--later", action="store_const", required=False,
default=False, help='add to job list for upload later', const=True)
parser.add_argument("--verify", action="store_const",
required=False, default=False, const=True)
args = parser.parse_args()
desc_dict = dict()
desc_dict['mode'] = 'vehicle'
desc_dict['vehicle'] = args.vehicle
desc_dict['system'] = args.system
desc_dict['city'] = args.city
desc_dict['model'] = args.model
desc_dict['street'] = args.street
desc_dict['number'] = args.number
desc_dict['operator'] = args.operator
desc_dict['operator_vehicle_category'] = args.operator_vehicle_category
desc_dict['digital_number'] = args.digital_number
desc_dict['route'] = args.route
desc_dict['line'] = args.line
desc_dict['country'] = args.country
desc_dict['facing'] = args.facing
desc_dict['colors'] = args.colors
desc_dict['progress'] = args.progress
desc_dict['secondary_objects'] = args.secondary_objects or None
desc_dict['later'] = args.later
desc_dict['dry_run'] = args.dry_run
fileprocessor.process_and_upload_files(args.filepath, desc_dict)