lots of typing fixes
This commit is contained in:
parent
51f580a304
commit
3665c34961
43 changed files with 260 additions and 178 deletions
|
@ -1,7 +1,7 @@
|
|||
from collections import defaultdict
|
||||
from datetime import datetime
|
||||
from datetime import timedelta
|
||||
from typing import Dict, Tuple
|
||||
from typing import Dict, Tuple, Union, Any
|
||||
|
||||
import requests
|
||||
|
||||
|
@ -11,7 +11,7 @@ from app.models.mirrors import Origin
|
|||
from app.terraform import BaseAutomation
|
||||
|
||||
|
||||
def check_origin(domain_name: str):
|
||||
def check_origin(domain_name: str) -> Dict[str, Any]:
|
||||
start_date = (datetime.utcnow() - timedelta(days=1)).strftime("%Y-%m-%dT%H%%3A%M")
|
||||
end_date = datetime.utcnow().strftime("%Y-%m-%dT%H%%3A%M")
|
||||
api_url = f"https://api.ooni.io/api/v1/measurements?domain={domain_name}&since={start_date}&until={end_date}"
|
||||
|
@ -19,7 +19,7 @@ def check_origin(domain_name: str):
|
|||
return _check_origin(api_url, result)
|
||||
|
||||
|
||||
def _check_origin(api_url: str, result: Dict):
|
||||
def _check_origin(api_url: str, result: Dict[str, Any]) -> Dict[str, Any]:
|
||||
print(f"Processing {api_url}")
|
||||
req = requests.get(api_url).json()
|
||||
if 'results' not in req or not req['results']:
|
||||
|
@ -38,7 +38,7 @@ def _check_origin(api_url: str, result: Dict):
|
|||
return result
|
||||
|
||||
|
||||
def threshold_origin(domain_name):
|
||||
def threshold_origin(domain_name: str) -> Dict[str, Any]:
|
||||
ooni = check_origin(domain_name)
|
||||
for country in ooni:
|
||||
total = sum([
|
||||
|
@ -58,7 +58,7 @@ def threshold_origin(domain_name):
|
|||
return ooni
|
||||
|
||||
|
||||
def set_ooni_alarm(origin_id: int, country: str, state: AlarmState, text: str):
|
||||
def set_ooni_alarm(origin_id: int, country: str, state: AlarmState, text: str) -> None:
|
||||
alarm = Alarm.query.filter(
|
||||
Alarm.origin_id == origin_id,
|
||||
Alarm.alarm_type == f"origin-block-ooni-{country}"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue