Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoest committed Apr 10, 2024
2 parents fd3887c + a089451 commit 828a459
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 10 deletions.
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
CORE_API=
DC_PATH=
DF_LINK=
DF_LINK=
MOODLE_AUTH=
MOODLE_LINK
26 changes: 17 additions & 9 deletions monitor/core_requests.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,58 @@
import requests
from cachetools import cached, TTLCache
from dotenv import load_dotenv
import os

from .helpers import split_compare


load_dotenv()

api_key = os.getenv('CORE_API')
df_link = os.getenv('DF_LINK')
moodle_auth = os.getenv('MOODLE_AUTH')
moodle_link = os.getenv('MOODLE_LINK')


headers = {
'Accept': 'application/json'
}

'Accept': 'application/json'
}

eud_header = {'X-API-KEY': api_key,
'accept': 'application/json',
'User-Agent': 'VATGER'}
eud_header = {
'X-API-KEY': api_key,
'Accept': 'application/json',
'User-Agent': 'VATGER'
}


@cached(cache=TTLCache(maxsize=float('inf'), ttl=60*60*12))
def get_station_data() -> list[dict]:
r = requests.get('https://raw.githubusercontent.com/VATGER-Nav/datahub/main/data.json', headers=headers)
return r.json()


@cached(cache=TTLCache(maxsize=float('inf'), ttl=60*60))
def get_endorsements(type: str) -> list[dict]:
return requests.get(f'https://core.vateud.net/api/facility/endorsements/{type}', headers=eud_header).json()['data']


@cached(cache=TTLCache(maxsize=float('inf'), ttl=60*60))
def get_logins() -> list[dict]:
r = requests.get(df_link, headers=headers).json()['data']
connections = [x for x in r if (x['callsign'][:2] in ['ED', 'ET'] and x['callsign'][:4] != 'EDYY')]
return connections


@cached(cache=TTLCache(maxsize=float('inf'), ttl=60*60))
def get_roster() -> list[dict]:
return requests.get(f'https://core.vateud.net/api/facility/roster', headers=eud_header).json()['data']['controllers']
return requests.get(f'https://core.vateud.net/api/facility/roster', headers=eud_header).json()['data'][
'controllers']


@cached(cache=TTLCache(maxsize=1024, ttl=60*60))
def get_rating(id: int) -> int:
return requests.get(f'https://api.vatsim.net/api/ratings/{id}/').json()['rating']


@cached(cache=TTLCache(maxsize=float('inf'), ttl=60))
def check_course_completion(course: dict, cid: int) -> bool:
course_id = course['link'].split('id=')[-1]
headers = {
Expand All @@ -62,6 +69,7 @@ def check_course_completion(course: dict, cid: int) -> bool:
return False


@cached(cache=TTLCache(maxsize=float('inf'), ttl=60*60))
def required_courses(callsign: str, cid: int) -> list[dict]:
"""
Expand Down
Binary file modified requirements.txt
Binary file not shown.

0 comments on commit 828a459

Please sign in to comment.