Skip to content

Instantly share code, notes, and snippets.

View anna-anisienia's full-sized avatar

Anna Geller anna-anisienia

View GitHub Profile
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',
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
@anna-anisienia
anna-anisienia / mysql_conn.py
Created September 29, 2020 20:34
context manager
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
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)
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
with open('data.txt', 'w') as myfile:
myfile.write('Hello from context manager!')
with open('data.txt', 'r') as myfile:
data = myfile.read()
print(data)
# 'Hello from context manager!'
myfile = open('data.txt', 'w')
myfile.write('Hello from context manager!')
myfile.close()
myfile = open('data.txt', 'w')
try:
myfile.write('Hello from context manager!')
finally:
myfile.close()
-- 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;