Scroll indicator done
728x90

https://www.flightradar24.com/

- liveupdating1.py

#######
# This script will make regular API calls to http://data-live.flightradar24.com
# to obtain updated total worldwide flights data.
# **This version only loads the site. No callbacks.**
######
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import requests

url = "https://data-live.flightradar24.com/zones/fcgi/feed.js?faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&stats=1"
res = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})  # A fake header is necessary to access the site
data = res.json()
counter = 0
for element in data["stats"]["total"]:
    counter += data["stats"]["total"][element]

app = dash.Dash()

app.layout = html.Div([
    html.Div([
        html.Iframe(src = 'https://www.flightradar24.com', height = 500, width = 1200)
    ]),

    html.Div([
    html.Pre('Active flights worldwide: {}'.format(counter))
    ])
])

if __name__ == '__main__':
    app.run_server()

- liveupdating3.py

#######
# This script will make regular API calls to http://data-live.flightradar24.com
# to obtain updated total worldwide flights data.
# ** This version continuously updates the number of flights worldwide,
#    AND GRAPHS THOSE RESULTS OVER TIME! **
######
import dash
import dash_core_components as dcc
import dash_html_components as html
from dash.dependencies import Input, Output
import plotly.graph_objs as go
import requests

app = dash.Dash()

app.layout = html.Div([
    html.Div([
        html.Iframe(src = 'https://www.flightradar24.com', height = 500, width = 1200)
    ]),

    html.Div([
    html.Pre(
        id='counter_text',
        children='Active flights worldwide:'
    ),
    dcc.Graph(id='live-update-graph',style={'width':1200}),
    dcc.Interval(
        id='interval-component',
        interval=6000, # 6000 milliseconds = 6 seconds
        n_intervals=0
    )])
])
counter_list = []

@app.callback(Output('counter_text', 'children'),
              [Input('interval-component', 'n_intervals')])
def update_layout(n):
    url = "https://data-live.flightradar24.com/zones/fcgi/feed.js?faa=1&mlat=1&flarm=1&adsb=1&gnd=1&air=1&vehicles=1&estimated=1&stats=1"
    # A fake header is necessary to access the site:
    res = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'})
    data = res.json()
    counter = 0
    for element in data["stats"]["total"]:
        counter += data["stats"]["total"][element]
    counter_list.append(counter)
    return 'Active flights worldwide: {}'.format(counter)

@app.callback(Output('live-update-graph','figure'),
              [Input('interval-component', 'n_intervals')])
def update_graph(n):
    fig = go.Figure(
        data = [go.Scatter(
        x = list(range(len(counter_list))),
        y = counter_list,
        mode='lines+markers'
        )])
    return fig

if __name__ == '__main__':
    app.run_server()

 


lambda function

: 1회용의 간단한 함수를 만드는 것

  • 재사용성
  • 익명 함수 (Anonymous Function)
def add(x, y):
	return x+y
lambda x, y : x + y

 

filter

age = [1,2,3,4,5]
for a in filter(lambda x: x>3, age):
	print(a, end=" ")

 

list, tuple, dictionary, set

list / tuple : 둘다 인덱스로 접근 but,  tuple은 변경 불가능

dictionary : index 대신 key로 접근

set : 중복 불가

 

reduce

from functools import reduce

a = [1,2,3,4]
n = reduce(lambda x,y: x+y, a)
print(n)
10

 

list comprehension

  • list에만 적용가능
  • [ (표현식) for (변수) in {반복자/연속열} if (조건 표현식) ]
  • [ {표현식} for {변수} in {반복자/연속열} ]

 

iter, next

반복자 객체를 만들어주는 함수

 

728x90