- Generate key
ssh-keygen
...
cp ./key-name* ~/.ssh
- Go to GitHub repo and add key-name.pub
def get_engine(): | |
import sqlalchemy | |
import os | |
# os.environ["DB_URL"] = "postgresql://USER:PASS@HOST:PORT/DATABASE" | |
engine = sqlalchemy.create_engine(os.environ["DB_URL"]) | |
return engine | |
def close_engine(engine): | |
engine.dispose() |
SSH_HOST = "" | |
SSH_USER = "" | |
SSH_FILE_PATH = "" | |
COMPRESSION = "zip" | |
from paramiko import SSHClient | |
client = SSHClient() | |
client.load_system_host_keys() | |
client.connect(SSH_HOST, username=SSH_USER) |
aws s3 cp s3://my_bucket/my_table /tmp/my_table --recursive \ | |
&& gcloud config set account <name>@<project>.iam.gserviceaccount.com \ | |
&& gcloud config set project <project> \ | |
&& gcloud auth activate-service-account <name>@<project>.iam.gserviceaccount.com --key-file /my_path_to/google_credentials.json | |
&& gsutil cp -r /tmp/my_table gs://bucket_name/my_table \ | |
&& bq mk --dataset my_dataset \ | |
&& bq mk --table --schema my_table_schema.json my_dataset.my_table \ | |
&& bq query --nouse_legacy_sql 'delete from my_dataset.my_table where <date_range_where_clause>;' \ | |
&& bq load --source_format=CSV --quote "" -F='\t' my_dataset.my_table gs://bucket_name/my_table/0000_part_00 \ | |
&& bq load --source_format=CSV --quote "" -F='\t' my_dataset.my_table gs://bucket_name/my_table/0001_part_00 \ |
unload (' | |
select * from my_table_name | |
where <date_range_where_clause> | |
') | |
to 's3://my-bucket/my_table_name/' | |
credentials 'aws_access_key_id=<key_id>;aws_secret_access_key=<secret_key>' | |
delimiter '\t' | |
allowoverwrite | |
; |
for symbol in ("BTC", "ETH", "LTC", "XLM"): | |
dag = create_dag(symbol=symbol) | |
globals()["{}_dag".format(symbol.lower())] = dag |
def create_dag(symbol): | |
with DAG( | |
"email_{}_price".format(symbol.lower()), | |
default_args={"start_date": "2020-01-01"}, | |
schedule_interval="0 0 * * *", | |
) as dag: | |
get_price_task = PythonOperator( | |
task_id="get_price", | |
python_callable=get_price, | |
op_kwargs=dict( |
from airflow import DAG | |
from airflow.operators.python_operator import PythonOperator | |
from crypto_prices import get_price, send_email | |
with DAG( | |
"email_bitcoin_price", | |
default_args={"start_date": "2020-01-01"}, | |
schedule_interval="0 0 * * *", | |
) as dag: |
# 1. Create new RSA key with "ssh-keygen" | |
# 2. Add as deploy key for repo on github | |
# 3. Add a new block to your ~/.ssh/config like below | |
# 4. Clone the repo with "git@github-repo-name:User/repo" | |
Host github.com | |
HostName github.com | |
IdentityFile /path/to/your/personal/github/private/key | |
Host github-repo-name |
def get_valid_filename(s): | |
""" | |
Return the given string converted to a string that can be used for a clean | |
filename. Remove leading and trailing spaces; convert other spaces to | |
underscores; and remove anything that is not an alphanumeric, dash, | |
underscore, or dot. | |
# https://github.com/django/django/blob/master/django/utils/text.py | |
""" | |
s = str(s).strip().replace(' ', '_') | |
s = re.sub(r'(?u)[^-\w.]', '', s) |