-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgeocache.py
142 lines (128 loc) · 5.4 KB
/
geocache.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
import logging
from geopy import distance, util
log = logging.getLogger('geocachepython.Geocache')
class Geocache:
"""Geocache class - Describes all attributes of a geocache.
Further info......
"""
def __init__(self, cacheDateIN, gcidIN, urlIN, difficultyIN, terrainIN, cacheNameIN, latIN, lonIN, foundIN, cacheIDIN, availableIN, archivedIN, placedByIN, ownerIDIN, ownerIN, cacheTypeIN, containerIN, countryIN, stateIN, shortDescIN, longDescIN, hintIN, dateFoundIN, foundLogIDIN, dateImportedIN, travelbugIN, ftfIN, countyIN):
"""Creates a new Geocache object.
Setting geocache attributes as passed in by parameter.
"""
self.cacheDate = cacheDateIN
self.gcid = gcidIN
self.url = urlIN
self.difficulty = difficultyIN
self.terrain = terrainIN
self.cacheName = cacheNameIN
self.lat = latIN
self.lon = lonIN
self.found = foundIN
self.cacheID = cacheIDIN
self.available = availableIN
self.archived = archivedIN
self.placedBy = placedByIN
self.ownerID = ownerIDIN
self.owner = ownerIN
self.cacheType = cacheTypeIN
self.container = containerIN
self.country = countryIN
self.state = stateIN
self.shortDesc = shortDescIN
self.longDesc = longDescIN
self.hint = hintIN
self.dateFound = dateFoundIN
self.foundLogID = foundLogIDIN
self.dateImported = dateImportedIN
self.travelbug = travelbugIN
self.ftf = ftfIN
self.county = countyIN
#print "cache created in memory successfully"
def checkUpdateCache(self, otherCache):
"""Checks if otherCache needs updating from info in self."""
oldDate = otherCache.dateImported
newDate = self.dateImported
log.debug("Date of old cache: %s. Date of new cache: %s" %(oldDate,newDate))
if oldDate == newDate:
log.debug("Same import date, no updates were made")
return 0
else:
log.debug("Dates differ update necessary")
#need to check which is newer -
#TODO change to straight alphabetical check
log.debug("year: %s" %newDate[:4])
if newDate[:4] > oldDate[:4]:
log.debug("newer year")
self.updateCache(otherCache)
return 1
elif newDate[:4] == oldDate[:4]:
log.debug("month: %s" %newDate[5:7])
if newDate[5:7] > oldDate[5:7]:
log.debug("newer month")
self.updateCache(otherCache)
return 1
elif newDate[5:7] == oldDate[5:7]:
log.debug("day: %s" %newDate[8:10])
if newDate[8:10] > oldDate[8:10]:
log.debug("newer day")
self.updateCache(otherCache)
return 1
elif newDate[8:10] == oldDate[8:10]:
log.debug("same day - check times")
log.debug("Must be older")
return 0
def updateCache(self, otherCache):
"""Updates all attributes of otherCache with values from self.
ftf status is unchanged, since this cannot be imported
"""
log.debug("updating cache...")
otherCache.cacheDate = self.cacheDate
otherCache.gcid = self.gcid
otherCache.url = self.url
otherCache.difficulty = self.difficulty
otherCache.terrain = self.terrain
otherCache.cacheName = self.cacheName
otherCache.lat = self.lat
otherCache.lon = self.lon
otherCache.found = self.found
otherCache.cacheID = self.cacheID
otherCache.available = self.available
otherCache.archived = self.archived
otherCache.placedBy = self.placedBy
otherCache.ownerID = self.ownerID
otherCache.owner = self.owner
otherCache.cacheType = self.cacheType
otherCache.container = self.container
otherCache.country = self.country
otherCache.state = self.state
otherCache.shortDesc = self.shortDesc
otherCache.longDesc = self.longDesc
otherCache.hint = self.hint
otherCache.dateFound = self.dateFound
otherCache.foundLogID = self.foundLogID
otherCache.dateImported = self.dateImported
otherCache.travelbug = self.travelbug
#don't change ftf status, since won't be imported
def checkUnique(self, caches):
"""check this cache against others for doubles - if found run checkUpdateCache
return 1 for a unique cache
"""
for otherCache in caches:
if otherCache.gcid == self.gcid:
log.debug("Possible match: ")
if self.checkUpdateCache(otherCache):
log.debug("updated cache")
else:
log.debug("nothing new")
return 0
return 1
def distanceToHome(self, home):
"""Returns distance from self to current home location in kilometers."""
return distance.distance(home, util.parse_geo("%s %s" % (self.lat, self.lon))).kilometers
#end Geocache class
# Check if running as a program
if __name__ == '__main__':
print "Run Debug Suite"
else:
# No, I must have been imported as a module
pass