forked from geowatch/geowatch-util
/
base.py
47 lines (35 loc) · 1.07 KB
/
base.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
"""
Base classes and functions used throughout GeoWatch libraries
"""
import datetime
import dateutil.parser
FORMAT_TILE_REQUEST = "{d};{tilesource},{z},{x},{y},{ext}"
FORMAT_GEOJSON = "{d};{geojson}"
FORMAT_TILE_REQUEST_LOG = "{status} {tileorigin} {tilesource} {z} {x} {y} {ext} {ip} {datetime}"
def parse_date(date_string):
"""
parses date string to datetime object
"""
d = None
try:
d = dateutil.parser.parse(date_string)
except:
d = None
return d
def is_expired(date, now, ttl):
"""
is date expired
"""
return now >= (date + datetime.timedelta(seconds=ttl))
class GeoWatchError(Exception):
"""
generic error used throughout GeoWatch
"""
def __init__(self, * args, ** kwargs):
super(GeoWatchError, self).__init__(self, * args, ** kwargs)
class GeoWatchModeError(GeoWatchError):
"""
Mode error used throughout GeoWatch. Mode must be consumer, producer, or duplex
"""
def __init__(self, * args, ** kwargs):
super(GeoWatchModeError, self).__init__(self, * args, ** kwargs)