This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from prefect.tasks.prefect.flow_run import FlowRunTask | |
from prefect import Flow | |
from prefect.schedules import Schedule | |
from prefect.schedules.clocks import CronClock | |
schedule_parent_flow = Schedule(clocks=[CronClock("0 2 * * *")]) | |
with Flow("MasterFlow", schedule=schedule_parent_flow) as flow: | |
staging_area = FlowRunTask(flow_name='staging_area', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from prefect.schedules import Schedule | |
from prefect.schedules.clocks import CronClock | |
import pendulum | |
schedule = Schedule(clocks=[CronClock("0 2 * * *", | |
start_date=pendulum.datetime(2020, 8, 28, | |
tz="Europe/Berlin") | |
)]) | |
schedule.next(3) # to see next 3 schedules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import contextlib | |
import mysql.connector | |
@contextlib.contextmanager | |
def get_mysql_conn(db): | |
""" | |
Context manager to automatically close DB connection. | |
We retrieve credentials from Environment variables |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from mysql_conn import get_mysql_conn | |
with get_mysql_conn(db='mytestdb') as conn: | |
df = pd.read_sql('SELECT * FROM mytable', conn) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import contextlib | |
import boto3 | |
s3 = boto3.client('s3', aws_access_key_id='my_aws_access_key', | |
aws_secret_access_key='my_aws_secret_key', | |
region_name='eu-central-1') | |
@contextlib.contextmanager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('data.txt', 'w') as myfile: | |
myfile.write('Hello from context manager!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with open('data.txt', 'r') as myfile: | |
data = myfile.read() | |
print(data) | |
# 'Hello from context manager!' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myfile = open('data.txt', 'w') | |
myfile.write('Hello from context manager!') | |
myfile.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
myfile = open('data.txt', 'w') | |
try: | |
myfile.write('Hello from context manager!') | |
finally: | |
myfile.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Get the 100 most recently added data points | |
SELECT time, truck_id, model, | |
measure_name, measure_value::double | |
FROM "sampleDB"."IoT" | |
ORDER BY time DESC LIMIT 100; |