forked from rmjacobson/recgov_daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
campground.py
61 lines (54 loc) · 2.14 KB
/
campground.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
"""
campground.py
Class declarations for Campground and CampgroundList. Also contains misc functions for creating
and keeping track of campground data.
"""
RECGOV_BASE_URL = "https://www.recreation.gov/camping/campgrounds"
class Campground():
"""
Taken from https://github.com/CCInCharge/campsite-checker, has been useful for debug.
"""
def __init__(self, name="N/A", facility_id=None):
self.name = name # name of campground
self.id = facility_id # facility ID of campground
self.url = f"{RECGOV_BASE_URL}/{facility_id}" # recreation.gov URL for campground
self.sites_available = 0 # initialize to unavailable (aka 0)
self.error_count = 0 # initialize parsing error count to 0
# self.campsites = {} # TODO: develop way of storing available specific campsites
def pretty(self):
"""
Create string to pretty print Campground information.
"""
# TODO: add self.campsites when available
retstr = f"Campground:\n\t{self.name}\n"
retstr += f"\t{self.id}\n\t{self.url}\n\t{self.sites_available}\n\t{self.error_count}"
return retstr
def jsonify(self):
"""
Returns JSON representation of this object, as a dict
"""
json = {
"name": self.name,
"facilityID": self.id,
"url": self.url,
"available": int(self.sites_available),
"error_count": self.error_count
# TODO: "campsites": []
}
return json
class CampgroundList(list):
"""
Taken from https://github.com/CCInCharge/campsite-checker, has been useful for debug.
Inherits from list, contains several Campground objects.
Has a method to return a JSON string representation of its Campgrounds.
"""
def serialize(self):
"""
Make JSON string from Campgrounds list.
"""
if len(self) == 0:
return []
result = []
for campground in self:
result.append(campground.jsonify())
return result