Api   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 46
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A get_airlines() 0 2 1
A __init__() 0 9 3
A get_airports() 0 2 1
A get_flight() 0 3 1
A get_zones() 0 2 1
A get_flights() 0 3 1
1
# -*- coding: utf-8 -*-
2
from .helpers import *
3
import time
4
5
6
class Api:
7
    """Flight Radar 24 API"""
8
9
    balanceJsonUrl = 'https://www.flightradar24.com/balance.json'
10
    balanceUrl = None
11
    baseUrl = 'https://www.flightradar24.com'
12
    apiUrl = 'https://api.flightradar24.com/common/v1'
13
    liveDataUrl = 'https://data-live.flightradar24.com'
14
15
    metaDataEndPoints = {
16
        'airports': '/_json/airports.php',
17
        'airlines': '/_json/airlines.php',
18
        'zones': '/js/zones.js.php'
19
    }
20
21
    realTimeDataEndPoints = {
22
        'flight': '/flight/list.json?&fetchBy=flight&page=1&limit=25&query=',  # add flight number e.g: TK1
23
        'flights': '/zones/fcgi/feed.js?faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&gliders=1&stats=1&maxage=14400&airline=!'
24
    }
25
26
    def __init__(self):
27
        response = api_request(self.balanceJsonUrl)
28
        tmp_weight = 0
29
        tmp_uri = None
30
        for uri, weight in response.items():
31
            if weight > tmp_weight:
32
                tmp_uri = uri
33
                tmp_weight = weight
34
        self.balanceUrl = tmp_uri
35
36
    def get_airports(self):
37
        return api_request(self.baseUrl + self.metaDataEndPoints['airports'])
38
39
    def get_airlines(self):
40
        return api_request(self.baseUrl + self.metaDataEndPoints['airlines'])
41
42
    def get_flights(self, airline):
43
        endpoint = self.liveDataUrl + self.realTimeDataEndPoints['flights'] + airline+'&_=' + str(time.time())
44
        return api_request(endpoint)
45
46
    def get_flight(self, flight_id):
47
        endpoint = self.apiUrl + self.realTimeDataEndPoints['flight'] + flight_id
48
        return api_request(endpoint)
49
50
    def get_zones(self):
51
        return api_request(self.baseUrl + self.metaDataEndPoints['zones'])
52