-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgc_upload_fieldnotes.py
executable file
·65 lines (57 loc) · 1.94 KB
/
gc_upload_fieldnotes.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# (c) Bernhard Tittelbach <[email protected]>
# License: public domain, attribution appreciated
import sys
import os
import getopt
import geocachingsitelib as gc
def usage():
print "Sytax:"
print " %s [-u <user> -p <pass>] geocache_visits.txt" % (sys.argv[0])
print "Options:"
print " -h | --help Show Help"
print " -u username | --username=gc_user "
print " -p password | --password=gc_pass "
print " -i | --noninteractive Never prompt for pwd, just fail"
print "If username and password are not provided, we interactively"
print "ask for them the first time and store a session cookie. Unless -i is given"
try:
opts, args = getopt.gnu_getopt(sys.argv[1:], "u:p:hi", ["username=","password=","noninteractive","debug","help"])
except getopt.GetoptError, e:
print "ERROR: Invalid Option: " +str(e)
usage()
sys.exit(1)
fetch_all_pqs_ = False
list_pqs_ = False
create_pq_dir_ = False
gc.be_interactive = True
for o, a in opts:
if o in ["-h","--help"]:
usage()
sys.exit()
elif o in ["-u","--username"]:
gc.gc_username = a
elif o in ["-p","--password"]:
gc.gc_password = a
elif o in ["-i","--noninteractive"]:
gc.be_interactive = False
elif o in ["--debug"]:
gc.gc_debug = True
gcvisitfiles = filter(os.path.exists, args)
if len(gcvisitfiles) < 1:
print "ERROR: No fieldnote files found"
usage()
sys.exit(1)
for gcvisitfile in gcvisitfiles:
try:
with open(gcvisitfile, "rb") as fileObj:
print "%s: %s" % (gcvisitfile, gc.upload_fieldnote(fileObj))
except gc.NotLoggedInError, e:
print "ERROR:", e
sys.exit(1)
except Exception, e:
print "ERROR: upload of fieldnotefile %s failed" % (gcvisitfile)
if gc.gc_debug:
import traceback
traceback.print_exc()