immunobiotech commited on
Commit
1d756e1
·
verified ·
1 Parent(s): d293fdd

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -15
app.py CHANGED
@@ -2,20 +2,22 @@ import gradio as gr
2
  import folium
3
  from folium import plugins
4
  import requests
 
5
  import pandas as pd
6
  from datetime import datetime
7
  import time
8
  import numpy as np
9
  import plotly.graph_objects as go
10
  from plotly.subplots import make_subplots
 
11
 
12
- # OpenSky API 인증 정보
13
- USERNAME = "seawolf2357"
14
- PASSWORD = "Time2175!@"
15
 
16
  class OpenSkyApi:
17
  def __init__(self, username=None, password=None):
18
- self.auth = (username, password) if username and password else None
19
  self.base_url = "https://opensky-network.org/api"
20
 
21
  def get_states(self, time_secs=0, icao24=None, bbox=None):
@@ -32,15 +34,25 @@ class OpenSkyApi:
32
  "lomax": bbox[3]
33
  })
34
 
 
 
 
 
 
35
  try:
36
  response = requests.get(
37
  f"{self.base_url}/states/all",
38
  params=params,
39
  auth=self.auth,
 
40
  timeout=15
41
  )
 
42
  if response.status_code == 200:
43
  return StateVector(response.json())
 
 
 
44
  else:
45
  print(f"Error {response.status_code}: {response.text}")
46
  return None
@@ -71,10 +83,10 @@ class State:
71
  self.velocity = state_array[9]
72
  self.true_track = state_array[10]
73
  self.vertical_rate = state_array[11]
74
- self.sensors = state_array[12]
75
- self.baro_altitude = state_array[13]
76
- self.squawk = state_array[14]
77
- self.spi = state_array[15]
78
  self.position_source = state_array[16] if len(state_array) > 16 else None
79
 
80
  # OpenSky API 인스턴스 생성
@@ -113,8 +125,6 @@ def get_states(bounds=None, max_retries=3):
113
  return None
114
  return None
115
 
116
-
117
-
118
  def create_monitoring_dashboard(states):
119
  """Create monitoring dashboard using Plotly"""
120
  if not states:
@@ -270,8 +280,6 @@ def create_map(region="world"):
270
 
271
  return m._repr_html_(), create_monitoring_dashboard(states), stats
272
 
273
-
274
-
275
  # Custom CSS
276
  custom_css = """
277
  .gradio-container {
@@ -336,12 +344,15 @@ with gr.Blocks(css=custom_css) as demo:
336
  outputs=[map_html, dashboard_plot, stats_text]
337
  )
338
 
 
 
 
 
 
339
  # Launch with specific configurations
340
  demo.launch(
341
  show_error=True,
342
  server_name="0.0.0.0",
343
  server_port=7860,
344
  share=False
345
- )
346
-
347
-
 
2
  import folium
3
  from folium import plugins
4
  import requests
5
+ from requests.auth import HTTPBasicAuth
6
  import pandas as pd
7
  from datetime import datetime
8
  import time
9
  import numpy as np
10
  import plotly.graph_objects as go
11
  from plotly.subplots import make_subplots
12
+ import os
13
 
14
+ # OpenSky API 인증 정보를 환경 변수에서 가져오기
15
+ USERNAME = os.getenv("ID_AUTH")
16
+ PASSWORD = os.getenv("PW_AUTH")
17
 
18
  class OpenSkyApi:
19
  def __init__(self, username=None, password=None):
20
+ self.auth = HTTPBasicAuth(username, password) if username and password else None
21
  self.base_url = "https://opensky-network.org/api"
22
 
23
  def get_states(self, time_secs=0, icao24=None, bbox=None):
 
34
  "lomax": bbox[3]
35
  })
36
 
37
+ headers = {
38
+ 'User-Agent': 'Mozilla/5.0',
39
+ 'Accept': 'application/json'
40
+ }
41
+
42
  try:
43
  response = requests.get(
44
  f"{self.base_url}/states/all",
45
  params=params,
46
  auth=self.auth,
47
+ headers=headers,
48
  timeout=15
49
  )
50
+
51
  if response.status_code == 200:
52
  return StateVector(response.json())
53
+ elif response.status_code == 401:
54
+ print("Authentication failed. Please check your environment variables ID_AUTH and PW_AUTH.")
55
+ return None
56
  else:
57
  print(f"Error {response.status_code}: {response.text}")
58
  return None
 
83
  self.velocity = state_array[9]
84
  self.true_track = state_array[10]
85
  self.vertical_rate = state_array[11]
86
+ self.sensors = state_array[12] if len(state_array) > 12 else None
87
+ self.baro_altitude = state_array[13] if len(state_array) > 13 else None
88
+ self.squawk = state_array[14] if len(state_array) > 14 else None
89
+ self.spi = state_array[15] if len(state_array) > 15 else None
90
  self.position_source = state_array[16] if len(state_array) > 16 else None
91
 
92
  # OpenSky API 인스턴스 생성
 
125
  return None
126
  return None
127
 
 
 
128
  def create_monitoring_dashboard(states):
129
  """Create monitoring dashboard using Plotly"""
130
  if not states:
 
280
 
281
  return m._repr_html_(), create_monitoring_dashboard(states), stats
282
 
 
 
283
  # Custom CSS
284
  custom_css = """
285
  .gradio-container {
 
344
  outputs=[map_html, dashboard_plot, stats_text]
345
  )
346
 
347
+ # 환경 변수 확인
348
+ if not USERNAME or not PASSWORD:
349
+ print("Warning: Environment variables ID_AUTH and/or PW_AUTH are not set.")
350
+ print("The application will run with anonymous access, which has lower rate limits.")
351
+
352
  # Launch with specific configurations
353
  demo.launch(
354
  show_error=True,
355
  server_name="0.0.0.0",
356
  server_port=7860,
357
  share=False
358
+ )