Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.10.1 #820

Merged
merged 16 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/deploy-acceptance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ jobs:
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_USER_WEB: ${{ secrets.SSH_USER_WEB }}
CFA_USER: ${{ secrets.CFA_USER }}
CFA_PASS: ${{ secrets.CFA_PASS }}
UZIS_TOKEN: ${{ secrets.UZIS_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Prepare config file
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/deploy-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ jobs:
SSH_PORT: ${{ secrets.SSH_PORT }}
SSH_USER: ${{ secrets.SSH_USER }}
SSH_USER_WEB: ${{ secrets.SSH_USER_WEB }}
CFA_USER: ${{ secrets.CFA_USER }}
CFA_PASS: ${{ secrets.CFA_PASS }}
UZIS_TOKEN: ${{ secrets.UZIS_TOKEN }}
steps:
- uses: actions/checkout@v4
- name: Prepare config file
Expand Down
7 changes: 3 additions & 4 deletions app/fetcher/centers_api_fetcher.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import os
from datetime import datetime
from typing import Optional

import numpy as np
import requests
from pandas import DataFrame

from app import db
from app import db, app
from app.fetcher.fetcher import Fetcher
from app.models import OckovaciMisto

Expand All @@ -26,8 +25,8 @@ def get_modified_time(self) -> Optional[datetime]:
return datetime.today()

def fetch(self, import_id: int) -> None:
user = os.environ.get('CFA_USER')
password = os.environ.get('CFA_PASS')
user = app.config['CFA_USER']
password = app.config['CFA_PASS']

r = requests.get(self._url, auth=(user, password))
df = DataFrame(r.json()['results'])
Expand Down
4 changes: 2 additions & 2 deletions app/fetcher/fetcher_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def _init_fetchers(self, dataset: str) -> None:
# inits requested fetchers
if dataset == 'all':
# self._fetchers.append(CentersFetcher()) # replaced by CentersApiFetcher
# self._fetchers.append(CentersApiFetcher())
self._fetchers.append(CentersApiFetcher())
# self._fetchers.append(OpeningHoursFetcher())
# self._fetchers.append(HealthFacilitiesFetcher())
# self._fetchers.append(DistributedFetcher()) # not updated since 2022-11-29
Expand Down Expand Up @@ -115,7 +115,7 @@ def _init_fetchers(self, dataset: str) -> None:

elif dataset == 'all_hourly':
self._fetchers.append(CentersApiFetcher())
self._fetchers.append(ReservationsApiFetcher(full_update=False))
# self._fetchers.append(ReservationsApiFetcher(full_update=False)) # API not available anymore

elif dataset == 'all_monthly':
self._fetchers.append(HealthFacilitiesNrpzsFetcher())
Expand Down
7 changes: 3 additions & 4 deletions app/fetcher/hospital_analysis_fetcher.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
from datetime import datetime
from typing import Optional

import pandas as pd
import requests

from app import db
from app import db, app
from app.fetcher.fetcher import Fetcher
from app.models import AnalyzaHospitalizaci

Expand All @@ -18,9 +17,9 @@ class HospitalAnalysisFetcher(Fetcher):
HOSPITAL_ANALYSIS_CSV = 'https://onemocneni-aktualne.mzcr.cz/api/account/{}/file/modely%252Fmodely_05_hospitalizovani_analyza.csv'

def __init__(self):
token = os.environ.get('ODL_UZIS_TOKEN')
token = app.config['UZIS_TOKEN']
url = self.HOSPITAL_ANALYSIS_CSV.format(token)
super().__init__(AnalyzaHospitalizaci.__tablename__, url)
super().__init__(AnalyzaHospitalizaci.__tablename__, url, check_date=False)

def get_modified_time(self) -> Optional[datetime]:
headers = requests.head(url=self._url).headers
Expand Down
2 changes: 1 addition & 1 deletion app/fetcher/infected_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self):
super().__init__(Nakazeni.__tablename__, self.INFECTED_CSV)

def fetch(self, import_id: int) -> None:
df = pd.read_csv(self._url)
df = pd.read_csv(self._url, dtype={'nakaza_v_zahranici': 'object', 'nakaza_zeme_csu_kod': 'object'})

df = df[['datum', 'vek', 'kraj_nuts_kod']]

Expand Down
7 changes: 3 additions & 4 deletions app/fetcher/opening_hours_fetcher.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import os
from datetime import datetime
from typing import Optional

import requests
from pandas import DataFrame

from app import db
from app import db, app
from app.fetcher.fetcher import Fetcher
from app.models import OckovaciMisto, ProvozniDoba

Expand All @@ -25,8 +24,8 @@ def get_modified_time(self) -> Optional[datetime]:
return datetime.today()

def fetch(self, import_id: int) -> None:
user = os.environ.get('CFA_USER')
password = os.environ.get('CFA_PASS')
user = app.config['CFA_USER']
password = app.config['CFA_PASS']

# select only walkin centers
mista = db.session.query(OckovaciMisto.id).filter(OckovaciMisto.typ == 'WALKIN').all()
Expand Down
4 changes: 4 additions & 0 deletions config.ci.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

basedir = os.path.abspath(os.path.dirname(__file__))


Expand All @@ -9,3 +10,6 @@ class Config(object):
TWITTER_CONSUMER_SECRET = '__TWITTER_CONSUMER_SECRET__'
TWITTER_ACCESS_TOKEN_KEY = '__TWITTER_ACCESS_TOKEN_KEY__'
TWITTER_ACCESS_TOKEN_SECRET = '__TWITTER_ACCESS_TOKEN_SECRET__'
CFA_USER = '__CFA_USER_SECRET__'
CFA_PASS = '__CFA_PASS_SECRET__'
UZIS_TOKEN = '__UZIS_TOKEN_SECRET__'
4 changes: 4 additions & 0 deletions config.docker.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

basedir = os.path.abspath(os.path.dirname(__file__))


Expand All @@ -9,3 +10,6 @@ class Config(object):
TWITTER_CONSUMER_SECRET = 'SECRET_TOKEN'
TWITTER_ACCESS_TOKEN_KEY = 'SECRET_TOKEN'
TWITTER_ACCESS_TOKEN_SECRET = 'SECRET_TOKEN'
CFA_USER = 'CFA_USER'
CFA_PASS = 'CFA_PASS'
UZIS_TOKEN = 'UZIS_TOKEN'
6 changes: 5 additions & 1 deletion config.sample.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os

basedir = os.path.abspath(os.path.dirname(__file__))


Expand All @@ -8,4 +9,7 @@ class Config(object):
TWITTER_CONSUMER_KEY = 'SECRET_TOKEN'
TWITTER_CONSUMER_SECRET = 'SECRET_TOKEN'
TWITTER_ACCESS_TOKEN_KEY = 'SECRET_TOKEN'
TWITTER_ACCESS_TOKEN_SECRET = 'SECRET_TOKEN'
TWITTER_ACCESS_TOKEN_SECRET = 'SECRET_TOKEN'
CFA_USER = 'CFA_USER'
CFA_PASS = 'CFA_PASS'
UZIS_TOKEN = 'UZIS_TOKEN'
11 changes: 11 additions & 0 deletions migrations/versions/e1bc70696bb8_.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,17 @@ def upgrade():
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('PfizerBA.45', 'Comirnaty Original/Omicron BA.4/BA.5', 1, 'Pfizer4', true) ON CONFLICT (vakcina) DO NOTHING")
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('ModernaBA.1', 'Spikevax bivalent Original/Omicron BA.1', 1, 'Moderna2', true) ON CONFLICT (vakcina) DO NOTHING")

op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('Comirnaty 6m-4', 'Comirnaty 6m-4', 2, 'Pfizer5', true) ON CONFLICT (vakcina) DO NOTHING")
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('Comirnaty Omicron XBB.1.5.', 'Comirnaty Omicron XBB.1.5.', 2, 'Pfizer6', true) ON CONFLICT (vakcina) DO NOTHING")
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('Comirnaty Omicron XBB.1.5. 5-11', 'Comirnaty Omicron XBB.1.5. 5-11', 2, 'Pfizer7', true) ON CONFLICT (vakcina) DO NOTHING")
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('COMIRNATY OMICRON XBB.1.5 6m-4', 'COMIRNATY OMICRON XBB.1.5 6m-4', 2, 'Pfizer8', true) ON CONFLICT (vakcina) DO NOTHING")

op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('Covovax', 'Covovax', 2, 'Covovax', true) ON CONFLICT (vakcina) DO NOTHING")
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('Nuvaxovid XBB 1.5', 'Nuvaxovid XBB 1.5', 2, 'Novavax2', true) ON CONFLICT (vakcina) DO NOTHING")
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('SPIKEVAX BIVALENT ORIGINAL/OMICRON BA.4-5', 'SPIKEVAX BIVALENT ORIGINAL/OMICRON BA.4-5', 2, 'SPIKEVAX BIVALENT ORIGINAL/OMICRON BA.4-5', true) ON CONFLICT (vakcina) DO NOTHING")
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('Sputnik V', 'Sputnik V', 2, 'Sputnik V', true) ON CONFLICT (vakcina) DO NOTHING")
op.execute("insert into vakciny (vyrobce, vakcina, davky, vakcina_sklad, aktivni) VALUES('Valneva', 'Valneva', 2, 'Valneva', true) ON CONFLICT (vakcina) DO NOTHING")


def downgrade():
pass
4 changes: 2 additions & 2 deletions scripts/cron
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# daily fetcher
00 6 * * * bash /home/ockovani/prd/app/scripts/execute_action.sh 15481697
# hourly fetcher - not needed anymore
# 38 7-22 * * * bash /home/ockovani/prd/app/scripts/execute_action.sh 15481698
# hourly fetcher
30 7-22 * * * bash /home/ockovani/prd/app/scripts/execute_action.sh 15481698
# monthly fetcher
00 5 5 * * bash /home/ockovani/prd/app/scripts/execute_action.sh 16635318
# post tweet - disabled
Expand Down
2 changes: 1 addition & 1 deletion scripts/execute_action.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
source /etc/env/ockovani.env
source /home/ockovani/ockovani.env
curl -X POST "https://api.github.com/repos/msusicky/ockovani-covid/actions/workflows/$1/dispatches" -H "Authorization: token $GH_TOKEN" -H "Accept: application/vnd.github.v3+json" -d '{ "ref": "main" }'
Loading