Skip to content

Commit

Permalink
Merge pull request #18 from ivandiaz-tomtom/master
Browse files Browse the repository at this point in the history
Update datetime to always follow the same format
  • Loading branch information
joostschouppe authored Jul 17, 2023
2 parents 6761ecf + e078833 commit ec1de35
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/on_demand_trigger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
required: true
type: number
last_processed_date:
description: 'Last processed data in YY-MM-DD format'
description: 'Last processed date in YY-MM-DD format, use only for manually trigger actions.'
required: false
type: string

Expand Down
4 changes: 2 additions & 2 deletions code/process_new_signs.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from os import environ
from fetch_signs import fetch_all_features_by_type
from utils import get_first_day_previous_month
from utils import get_process_date
from sign_processing import extract_new_signs, save_geojson, upload_to_maproulette

logging.basicConfig(format='%(asctime)s | %(levelname)s: %(message)s', level=logging.NOTSET)
Expand All @@ -10,7 +10,7 @@
feature_type = "awv:Verkeersborden.Vlaanderen_Borden"
feature_file = "./python_output/feature_output.csv"
geojson_file = "./python_output/geojson_output.json"
process_date = environ['LAST_PROCESSED_DATE'] if environ.get('LAST_PROCESSED_DATE') else get_first_day_previous_month()
process_date = get_process_date()
maproulette_api_key = environ.get("MAPROULETTE_API_KEY")
challenge_id = environ['CHALLENGE_ID']

Expand Down
17 changes: 10 additions & 7 deletions code/utils.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
from datetime import datetime, timedelta
import numpy as np
from os import environ

def get_process_date():
date_format = '%Y-%m-%d'
if environ.get('LAST_PROCESSED_DATE'):
return np.datetime64(datetime.strptime(environ.get('LAST_PROCESSED_DATE'), date_format).date())
return get_first_day_previous_month()

def get_first_day_current_month():
input_dt = datetime.today().date()
day_num = input_dt.strftime("%d")
result = input_dt - timedelta(days=int(day_num) - 1)
return np.datetime64(result)
return np.datetime64(datetime.today().replace(day=1).date())

def get_first_day_previous_month():
input_dt = datetime.today().date()
result = (input_dt - timedelta(days=input_dt.day)).replace(day=1)
return np.datetime64(result)
last_day_previous_month = datetime.today().replace(day=1) - timedelta(days=1)
return np.datetime64(last_day_previous_month.replace(day=1).date())

0 comments on commit ec1de35

Please sign in to comment.