ENDPOINT='https://commons.wikimedia.org/w/api.php'
NAMESPACE='Data'
-UPLOAD_MAX_RATE=15 # Per minute
+UPLOAD_MAX_RATE=15 # Per minute
+RESTART_AFTER_PATH='' # i.e. weather.gc.ca/Monthly/1013241.tab
USERNAME_PATH='login_username'
PASSWORD_PATH='login_password'
requestCSRFToken > "${CSRF_TOKEN_PATH}"
readCSRFToken
+# Prepare start offset
+if [ "${RESTART_AFTER_PATH}" == '' ]
+then
+ START_OFFSET_REACHED=1
+else
+ START_OFFSET_REACHED=0
+fi
+
MINUTE=$(date +%M)
MINUTE_UPLOADS=0
+
while IFS= read -r -d '' -u 9
do
+ # Prepare path
URI_PATH=${NAMESPACE}:$(realpath --relative-to="${SOURCE}" "${REPLY}")
+
+ # Check start offset
+ if [ ${START_OFFSET_REACHED} -eq 0 ]
+ then
+ if [ ${URI_PATH} == "${NAMESPACE}:${RESTART_AFTER_PATH}" ]
+ then
+ START_OFFSET_REACHED=1
+ fi
+
+ continue
+ fi
+
+ # Upload
BODY=$(curl -X POST -d 'action=edit' --data-urlencode "title=${URI_PATH}" --data-urlencode "text@${REPLY}" -d "token=${CSRF_TOKEN}" -d 'format=xml' -b "${COOKIE_JAR}" -c "${COOKIE_JAR}" "${ENDPOINT}")
RESULT=$(echo "${BODY}" | xmlstarlet sel -t -v '/api/edit/@result' -)