-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodelr.py
More file actions
executable file
·37 lines (31 loc) · 1.27 KB
/
modelr.py
File metadata and controls
executable file
·37 lines (31 loc) · 1.27 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
import requests
def get_experiments_by_status(status=2):
url = 'http://model-r.jbrj.gov.br/ws/'
payload = {'status': status}
r = requests.get(url, params=payload)
return r.json()
def update_experiment_status(id_experiment, status):
url = 'https://model-r.jbrj.gov.br/ws/setstatus.php'
payload = {'id': id_experiment, 'status': status}
r = requests.get(url, params=payload)
update_status = r.json()
return update_status['experiment'][0]
def get_occurrences_by_status(experiment, status):
status = str(status)
all_points = experiment['occurrences']
return [point for point in all_points if point['idstatusoccurrence'] == status]
def write_occurrences_csv(list_of_points, output_file):
with open(output_file, 'w') as csvfile:
fieldnames = ['taxon', 'lon', 'lat']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames, extrasaction='ignore')
writer.writeheader()
for point in list_of_points:
writer.writerow(point)
# TODO raise Exception when a web service error occurs.
def inform_experiment_results(evaluate_info):
url = 'https://model-r.jbrj.gov.br/ws/setresult.php'
r = requests.post(url, data=evaluate_info)
return r.json()