-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_source.py
43 lines (35 loc) · 1.42 KB
/
data_source.py
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
import math
import requests
import datetime
# Function to fetch MUF and foF2 values for a specified station code
def fetch_station_values():
url = "https://prop.kc2g.com/api/stations.json"
response = requests.get(url)
data = response.json()
target_station_code = "EA036"
for station_data in data:
if station_data['station']['code'] == target_station_code:
muf_value = station_data.get('mufd')
fof2_value = station_data.get('fof2')
timestamp = station_data.get('time')
return {'muf': muf_value, 'fof2': fof2_value, 'time': timestamp}
# Function to fetch MUF and foF2 values for a specified station code
def fetch_essn_values():
url = "https://prop.kc2g.com/api/essn.json?days=1"
response = requests.get(url)
data = response.json()
info_array = data['24h']
essn_values = [] # List to hold all entries
for essn_data in info_array:
timestamp = essn_data.get('time')
ssn = math.floor(int(essn_data.get('ssn')))
sfi = math.floor(int(essn_data.get('sfi')))
# Append the data to the list
essn_values.append({
'time': datetime.datetime.fromtimestamp(timestamp),
'ssn': ssn,
'sfi': sfi
})
# Sort the list by time and get the most recent entry
most_recent_entry = max(essn_values, key=lambda x: x['time']) if essn_values else None
return most_recent_entry