-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloader.py
61 lines (49 loc) · 2.19 KB
/
loader.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
import csv
from dateutil.parser import parse
from adoptarbol.tree.models import Tree
def load(filename):
with open(filename, encoding='utf-8') as f:
reader = csv.reader(f)
header = next(reader)
def pos_for(field):
return header.index(field)
def float_or_none(string):
try:
return(float(string))
except ValueError:
return None
for row in reader:
# codigo = str(row[pos_for('codigo')]),
print('Procesando ', row)
tree = {'code': row[pos_for('codigo')],
'common_name': row[pos_for('especie')],
'scientific_name': row[pos_for('cientifico')],
'family': row[pos_for('familia')],
'coord_utm_e': float_or_none(row[pos_for('utm_x')].replace(',', '.')),
'coord_utm_n': float_or_none(row[pos_for('utm_y')].replace(',', '.')),
'coord_utm_zone_letter': row[pos_for('utm_zone')],
'coord_utm_zone_n': row[pos_for('utm_south')],
'coord_lat': float_or_none(row[pos_for('lat')].replace(',', '.')),
'coord_lon': float_or_none(row[pos_for('long')].replace(',', '.')),
'photo': row[pos_for('fotos')],
'diameter': row[pos_for('dia')],
'height': row[pos_for('alt')],
'circ': row[pos_for('circ')],
'base_area': float_or_none(row[pos_for('areabasal')].replace(',', '.')),
'size_class': row[pos_for('clasetamano')],
'quality': float_or_none(row[pos_for('calidad')].replace(',', '.')),
'relevance': row[pos_for('relevancia')],
'notes': row[pos_for('notas')],
'phenology': row[pos_for('fenologia')],
'observation': row[pos_for('obs')],
'surveyed_on': parse(row[pos_for('fechahora')]),
}
t = Tree(**tree)
t.save()
"""
if __name__ == '__main__':
app = create_app(CONFIG)
manager = Manager(app)
with app.app_context():
load()
"""