Skip to content

Commit

Permalink
included date and adjusted the schedule
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrian Gasper authored and Andrian Gasper committed Jan 19, 2024
1 parent 5a8049e commit fc1f7e0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
12 changes: 6 additions & 6 deletions deploy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from authenticate import client
from variables import FUNCTION_NAME, FUNCTION_EXTERNAL_ID
from variables import FUNCTION_NAME, FUNCTION_DESCRIPTION, FUNCTION_EXTERNAL_ID, FUNCTION_FOLDER, FUNCTION_RUNTIME, FUNCTION_SCHEDULE_NAME, FUNCTION_SCHEDULE


if __name__ == "__main__":
Expand All @@ -12,15 +12,15 @@
func = client.functions.create(
name=FUNCTION_NAME,
external_id=FUNCTION_EXTERNAL_ID,
folder=".",
description="Scrape finn realestate data",
runtime="py311",
folder=FUNCTION_FOLDER,
description=FUNCTION_DESCRIPTION,
runtime=FUNCTION_RUNTIME,
)
print(f"Created function with external_id: {FUNCTION_EXTERNAL_ID}")

schedule = client.functions.schedules.create(
name="run-every-hour",
cron_expression="0 * * * *",
name=FUNCTION_SCHEDULE_NAME,
cron_expression=FUNCTION_SCHEDULE,
function_id=func.id,
)
print(f"Created schedule for function with external_id: {FUNCTION_EXTERNAL_ID}")
2 changes: 2 additions & 0 deletions handler.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import pandas as pd
import time
from datetime import datetime
from cognite.client import CogniteClient
from scraper import scraper
from variables import DATABASE_NAME, TABLE_NAME, ID_COLUMN_NAME
Expand Down Expand Up @@ -28,6 +29,7 @@ def main(client, nr_of_pages, price_from, price_to):
df = pd.DataFrame(scraped_data).fillna('NaN')
if ID_COLUMN_NAME in df.columns:
df = df.set_index(ID_COLUMN_NAME)
df["Date"] = str(datetime.now().date())
client.raw.rows.insert_dataframe(DATABASE_NAME, TABLE_NAME, df)
else:
print(f"Column '{ID_COLUMN_NAME}' not found in scraped data.")
Expand Down
5 changes: 5 additions & 0 deletions variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

FUNCTION_NAME = "scrape_finn_realestate_data"
FUNCTION_EXTERNAL_ID = "fn_001_scrape_finn_realestate_data"
FUNCTION_DESCRIPTION = "Scrape finn realestate data"
FUNCTION_FOLDER = "."
FUNCTION_RUNTIME = "py311"
FUNCTION_SCHEDULE_NAME = "run-every-hour"
FUNCTION_SCHEDULE = "0 */2 * * *"

PRICE_MIN_MIN = 0
PRICE_MIN_MAX = 20000000
Expand Down

0 comments on commit fc1f7e0

Please sign in to comment.