-
Notifications
You must be signed in to change notification settings - Fork 0
/
versioning_funcs.py
103 lines (80 loc) · 2.83 KB
/
versioning_funcs.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
from functions import *
import osmapi
class GetDatetimeLastUpdate:
default_return = (
-1,
default_missing_day,
default_missing_month,
default_missing_year,
)
def __init__(self):
self.api = osmapi.OsmApi()
def get_datetime_last_update_way(self, featureid):
try:
res = self.api.WayGet(featureid)
dt = res["timestamp"] # date time object
return res["version"], dt.day, dt.month, dt.year
except Exception as e:
print(e)
return self.default_return
def get_datetime_last_update_node(self, featureid):
try:
res = self.api.NodeGet(featureid)
dt = res["timestamp"] # date time object
return res["version"], dt.day, dt.month, dt.year
except Exception as e:
print(e)
return self.default_return
# def get_datetime_last_update(
# featureid,
# featuretype="way",
# onlylast=True,
# return_parsed=True,
# return_special_tuple=True,
# ):
# # TODO: use osmapi!
# h_url = get_feature_history_url(featureid, featuretype)
# try:
# response = requests.get(h_url)
# except:
# if onlylast:
# if return_parsed and return_special_tuple:
# return [None] * 4 # 4 Nones
# return ""
# else:
# return []
# if response.status_code == 200:
# tree = ElementTree.fromstring(response.content)
# element_list = tree.findall(featuretype)
# if element_list:
# date_rec = [element.attrib["timestamp"][:-1] for element in element_list]
# if onlylast:
# if return_parsed:
# if return_special_tuple:
# # parsed = datetime.strptime(date_rec[-1],'%Y-%m-%dT%H:%M:%S')
# parsed = parse_datetime_str(date_rec[-1])
# return len(date_rec), parsed.day, parsed.month, parsed.year
# else:
# # return datetime.strptime(date_rec[-1],'%Y-%m-%dT%H:%M:%S')
# return parse_datetime_str(date_rec[-1])
# else:
# return date_rec[-1]
# else:
# if return_parsed:
# return [parse_datetime_str(record) for record in date_rec]
# else:
# return date_rec
# else:
# if onlylast:
# return ""
# else:
# return []
# else:
# print("bad request, check feature id/type")
# if onlylast:
# return ""
# else:
# return []
# def get_datetime_last_update_node(featureid):
# # all default options
# return get_datetime_last_update(featureid, featuretype="node")