You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# VanderBot, a script for writing CSV data to a Wikibase API. vanderbot.py
2
+
version='1.7.1'
3
+
created='2021-04-xx'
4
+
2
5
# (c) 2021 Vanderbilt University. This program is released under a GNU General Public License v3.0 http://www.gnu.org/licenses/gpl-3.0
3
6
# Author: Steve Baskauf
4
7
# For more information, see https://github.com/HeardLibrary/linked-data/tree/master/vanderbot
@@ -86,6 +89,10 @@
86
89
# - enable logging of some errors to be displayed (and saved to the log file if used): label/description fault, date fault
87
90
# - prior to writing new items, check that there are no existing items with the same labels and descriptions
88
91
# - move mutable configuration variables to the top of the script
92
+
# -----------------------------------------
93
+
# Version 1.7.1 change notes (2021-03-xx):
94
+
# - enable --version option.
95
+
# add more complete error trapping for dates
89
96
90
97
importjson
91
98
importrequests
@@ -94,6 +101,8 @@
94
101
fromtimeimportsleep
95
102
importsys
96
103
importuuid
104
+
importre
105
+
fromdatetimeimportdatetime
97
106
98
107
# Change the following lines to hard-code different defaults if not running from the command line.
99
108
@@ -102,7 +111,7 @@
102
111
log_object=sys.stdout# log output defaults to the console screen
103
112
allow_label_description_changes=False# labels and descriptions in the local CSV file that differ from existing Wikidata items are not automatically written
104
113
endpoint='https://query.wikidata.org/sparql'# default to the Wikidata Query Service endpoint
105
-
sparqlSleep=0.25# delay time between calls to SPARQL endpoint
114
+
sparqlSleep=0.1# delay time between calls to SPARQL endpoint
106
115
json_metadata_description_file='csv-metadata.json'# "Generating RDF from Tabular Data on the Web" metadata description file (mapping schema)
107
116
credentials_path_string='home'# value is "home", "working", "gdrive", or a relative or absolute path with trailing "/"
108
117
credentials_filename='wikibase_credentials.txt'# name of the API credentials file
@@ -115,9 +124,40 @@
115
124
password=465jli90dslhgoiuhsaoi9s0sj5ki3lo
116
125
'''
117
126
127
+
arg_vals=sys.argv[1:]
128
+
# see https://www.gnu.org/prep/standards/html_node/_002d_002dversion.html
129
+
if'--version'inarg_valsor'-V'inarg_vals: # provide version information according to GNU standards
130
+
# Remove version argument to avoid disrupting pairing of other arguments
131
+
# Not really necessary here, since the script terminates, but use in the future for other no-value arguments
# date is xsd:dateTime and doesn't need adjustment
420
-
eliflen(value) ==20:
421
-
timeString=value
422
-
precisionNumber=11# assume precision to days since Wikibase doesn't support greater resolution than that
423
-
# date form unknown, don't adjust
492
+
# date does not conform to any of the tested options
424
493
else:
425
-
#print('Warning: date for ' + dateColumnNameRoot + '_val:', rowData[dateColumnNameRoot + '_val'], 'does not conform to any standard format! Check manually.')
426
-
error=True
427
-
precisionNumber=''# must have a value to prevent an error, will be ignored since the write and save will be killed
494
+
# date is xsd:dateTime and doesn't need adjustment
495
+
ifvalidate_iso8601(value):
496
+
timeString=value
497
+
precisionNumber=11# assume precision to days since Wikibase doesn't support greater resolution than that
498
+
# date form unknown, don't adjust
499
+
else:
500
+
#print('Warning: date for ' + dateColumnNameRoot + '_val:', rowData[dateColumnNameRoot + '_val'], 'does not conform to any standard format! Check manually.')
501
+
error=True
502
+
precisionNumber=''# must have a value to prevent an error, will be ignored since the write and save will be killed
0 commit comments