Blame view

flaskr/legacy/atmosfair.py 1.41 KB
71016b9a   Goutte   Add the sample fi...
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
import json

import requests


# Sample file for getting data out of atmosfair,
# to be refactored as a Driver somehow.
# This is not used as-is in this project.


def request_info_atmosfair_de(from_airport, to_airport):
    json_value = {
        "amount": 0,
        "returnFlight": True,
        "flightCount": 1,
        "passengerCount": 1,
        "entireAircraft": False,
        "legs": [{
            "airport": json.loads(from_airport)[0],
            "travelClass": None, "charter": None,
            "aircraft": None
        }, {
            "airport": json.loads(to_airport)[0],
            "travelClass": None, "charter": None,
            "aircraft": None
        }],
        "proportion": 1
    }
    #    print(json_value)
    r = requests.post(
        'https://co2offset.atmosfair.de/api/flight/activity',
        json=json_value
    )
    return r


def request_airport_atmosfair_de(code_aita):
    r = requests.get(
        "https://co2offset.atmosfair.de/api/airport",
        "query=" + code_aita
    )
    return r


if __name__ == '__main__':
    from_airport = request_airport_atmosfair_de("CDG")
    to_airport = request_airport_atmosfair_de("IAD")

    r = request_info_atmosfair_de(from_airport.text, to_airport.text)
    print(r.text)
    print(r.json().get('co2'))
    print(r.json().get('rfi'))
    print(r.json().get('legs'))
    airlineemissions = r.json().get('airlineEmissions')
    print airlineemissions