summaryrefslogtreecommitdiffstats
path: root/misc_scripts/adsbexchange_krakenmap.py
blob: f8dab15278b49ee8addd3b88dab3968b673a2717 (plain) (blame)
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
# Uses the ADS-B Exchange RapidAPI service to get live data from ADS-B exchange
# Note RapidAPI requires a subscription at $10 a month, and you only get 10,000 requests per month.
# You may wish to limit your 

RAPID_API_KEY: "MY_RAPID_API_KEY"

KRAKEN_PRO_USER_EMAIL: "your@email.com"
KRAKEN_PRO_PASSWORD: "password"

# You may wish to limit your request rate more to avoid going over the limit of your account
REQUEST_RATE = 10

KRAKEN_RPO_API_SERVER = 'https://kraken.tynet.eu:8842'


import requests
import time

# Enter your RapidAPI URL here
url = "https://adsbexchange-com1.p.rapidapi.com/v2/lat/-36.2/lon/174.3/dist/250/"

headers = {
        "X-RapidAPI-Key": RAPID_API_KEY,
        "X-RapidAPI-Host": "adsbexchange-com1.p.rapidapi.com"
}

#response = requests.request("GET", url, headers=headers)
#print(response.text)


# Your Kraken Pro Cloud username and password
login = {'email': KRAKEN_PRO_USER_EMAIL, 'password': KRAKEN_PRO_PASSWORD}

x = requests.post(KRAKEN_RPO_API_SERVER + '/login', json = login)
token = x.text
print(x.text)

run = True
while run:
    response = requests.request("GET", url, headers=headers)
    data = response.json()

    beaconData = []
    for aircraft in data['ac']:
        try:
            beaconData.append({'id': str(aircraft['flight']), 'lat': aircraft['lat'], 'lon': aircraft['lon'], 'speed': int(aircraft['gs']), 'height': aircraft['alt_geom'], 'heading': aircraft['track']})

            #print (aircraft['flight'])
            #print (aircraft['lat'])
            #print (aircraft['lon'])
            #print (aircraft['gs'])
            #print (aircraft['alt_geom'])
        except:
            #print('excepted')
            pass # probably lat/lon missing

    x = requests.post(API_SERVER + '/beacons', json = beaconData, headers = {'Authorization': token})
    #print(x)
    time.sleep(REQUEST_RATE)