Skip to content
Draft
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
26 changes: 21 additions & 5 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,26 @@ jobs:

steps:
- uses: actions/checkout@main
- name: Install poetry
run: pipx install poetry
- uses: actions/setup-python@main

- uses: actions/setup-python@v5
with:
python-version-file: '.python-version'

- uses: astral-sh/setup-uv@v5
with:
enable-cache: true

- uses: awalsh128/cache-apt-pkgs-action@latest
with:
cache: 'poetry'
- run: poetry install
packages: gdal-bin libgdal-dev

- name: Setup uv python environment
run: uv venv

- name: uv lock check
run: uv lock --locked --offline

- name: uv sync
run: uv sync --all-extras

- uses: pre-commit/action@main
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.8
3.9
44 changes: 20 additions & 24 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,36 +1,32 @@
FROM python:3.8-slim-buster
FROM python:3.9-slim-bookworm AS base
COPY --from=ghcr.io/astral-sh/uv:0.7.4 /uv /uvx /bin/

LABEL maintainer="IFRC"
LABEL org.opencontainers.image.source="https://github.com/IFRCGo/go-risk-module-api"

ENV PYTHONUNBUFFERED=1

ENV UV_COMPILE_BYTECODE=1
ENV UV_LINK_MODE=copy
ENV UV_PROJECT_ENVIRONMENT="/usr/local/"

WORKDIR /code

RUN apt-get -y update \
RUN --mount=type=cache,target=/root/.cache/uv \
--mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
apt-get update -y \
&& apt-get install -y --no-install-recommends \
git \
g++ \
curl \
wait-for-it \
gdal-bin \
libgdal-dev


ARG CPLUS_INCLUDE_PATH=/usr/include/gdal
ARG C_INCLUDE_PATH=/usr/include/gdal
RUN pip install GDAL==2.4.0

COPY pyproject.toml poetry.lock /code/

# Upgrade pip and install python packages for code
RUN pip install --upgrade --no-cache-dir pip poetry \
&& poetry --version \
# Configure to use system instead of virtualenvs
&& poetry config virtualenvs.create false \
&& poetry install --no-root \
# Remove installer
&& pip uninstall -y poetry virtualenv-clone virtualenv
# Build required packages
gdal-bin build-essential gcc g++ libc-dev libgdal-dev libproj-dev \
# Helper packages
git curl wait-for-it procps \
&& uv lock --locked --offline \
&& uv sync --frozen --no-install-project --all-groups \
# Clean-up
&& apt-get remove -y build-essential gcc g++ libc-dev libgdal-dev libproj-dev \
&& apt-get autoremove -y \
&& rm -rf /var/lib/apt/lists/*


COPY . /code/
11 changes: 5 additions & 6 deletions common/management/commands/update_country_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ def handle(self, *args, **options):
independent = data["independent"]
is_deprecated = data["is_deprecated"]
record_type = data["record_type"]
print(record_type)
iso3 = data["iso3"]
if iso3:
country = Country.objects.filter(iso3=iso3.lower())
if country.exists():
country = country.last()
country.independent = independent
country.is_deprecated = is_deprecated
country.record_type = record_type
country.save(update_fields=["independent", "is_deprecated", "record_type"])
for country_item in country:
country_item.independent = independent
country_item.is_deprecated = is_deprecated
country_item.record_type = record_type
country_item.save(update_fields=["independent", "is_deprecated", "record_type"])
cluster_country_name = [
"West Africa Country Cluster",
"Tunis Country Cluster",
Expand Down
6 changes: 3 additions & 3 deletions imminent/management/commands/import_gwis_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def handle(self, *args, **kwargs):
# Get all the countries with iso3 codes that are not deprecated and independent
country_iso3 = list(Country.objects.filter(is_deprecated=False, independent=True).values_list("iso3", flat=True))

for year in range(2024, 2025):
for year in range(2003, 2026):
for iso3 in country_iso3:
if iso3:
self.import_monthly_data(iso3, year)
Expand All @@ -41,7 +41,7 @@ def import_monthly_data(self, iso3, year):
self.create_gwis_entry(iso3, month, year, GWIS.DSRTYPE.MONTHLY)

def import_cumulative_data(self, iso3, year):
url = f"https://api2.effis.emergency.copernicus.eu/statistics/v2/dsr/cumulative?country={iso3.upper()}&year={year}"
url = f"https://api2.effis.emergency.copernicus.eu/statistics/v2/dsr/monthly?country={iso3.upper()}&year={year}"
response = requests.get(url, verify=False)

if response.status_code != 200:
Expand All @@ -55,7 +55,7 @@ def import_cumulative_data(self, iso3, year):
cumulative_response = response_data.get("dsrcumulative", [])

for month in cumulative_response:
self.create_gwis_entry(iso3, month, year, GWIS.DSRTYPE.CUMULATIVE)
self.create_gwis_entry(iso3, month, year, GWIS.DSRTYPE.CUMMULATIVE)

def create_gwis_entry(self, iso3, data, year, dsr_type):
country = Country.objects.filter(iso3=iso3).first()
Expand Down
Loading
Loading