-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgclog.py
More file actions
executable file
·56 lines (39 loc) · 1.42 KB
/
gclog.py
File metadata and controls
executable file
·56 lines (39 loc) · 1.42 KB
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
#!/usr/bin/env python3
import sys
from xml.etree.ElementTree import parse
from datetime import datetime
import subprocess
from time import sleep
class Geocache:
def __init__(self,gccode,date,result,comment):
self.gccode = gccode
self.date = date
self.result = result
if comment == None:
comment = "TFTC!"
self.comment = comment
def helper(log):
gccode = log[0].text
date_string = log[1].text
result = log[2].text
comment = log[3].text
date = date_string
return Geocache(gccode,date,result,comment)
def main():
logfile_filename = sys.argv[1]
logfile_xml = parse(logfile_filename)
myfind_filename = sys.argv[2]
myfind_xml = parse(myfind_filename)
found_geocaches = set()
for geocache in myfind_xml.getroot()[7:]:
found_geocaches.add(geocache[1].text)
logs_raw = [helper(log) for log in logfile_xml.getroot()]
to_be_logged = [geocache for geocache in logs_raw if geocache.gccode not in found_geocaches ]
to_be_logged = [geocache for geocache in to_be_logged if geocache.result == 'found it']
for log in to_be_logged:
string_url = "http://www.geocaching.com/geocache/%s?date=%s&type=%s&comment=%s"
url = string_url % (log.gccode,log.date,log.result,log.comment)
subprocess.check_output(['firefox','-new-tab',url])
sleep(5)
if __name__ == "__main__":
main()