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
''' | |
creates local settings for a django project | |
- define secret key | |
- use a local sqlite3 database | |
reference: http://stackoverflow.com/questions/4909958/django-local-settings | |
''' | |
import os |
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 sqlalchemy import create_engine | |
# follows django database settings format, replace with your own settings | |
DATABASES = { | |
'production':{ | |
'NAME': 'dbname', | |
'USER': 'user', | |
'PASSWORD': 'pass', | |
'HOST': 'rdsname.clqksfdibzsj.us-east-1.rds.amazonaws.com', |
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 boto3 | |
from StringIO import StringIO | |
def write_df_to_s3(df, s3_bucket, s3_key, encoding='utf-8', index=False, **kwargs): | |
""" | |
Writes a pandas dataframe to a csv on AWS S3 | |
Arguments: | |
df (pd.DataFrame): dataframe to write | |
s3_bucket (str): s3 bucket name, e.g. "my-bucket" |
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 sqlalchemy import create_engine | |
from datetime import date | |
from s3fs import S3FileSystem | |
def create_db_engine(database=None,user=None,password=None,host=None,port=5432): | |
""" | |
Create sqlalchemy postgres engine from settings | |
""" |
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
# stick this file inside a folder whose contents you want to git ignore | |
[^.]* |
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
# 99_delete_awslogs_agent_state.sh: deletes awslogs agent state file so that | |
# agent starts monitoring logs for the most recently created container | |
files: | |
/opt/elasticbeanstalk/hooks/appdeploy/post/99_delete_awslogs_agent_state.sh: | |
mode: "000755" | |
owner: root | |
group: root | |
content: | | |
#!/bin/bash |
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
""" | |
AWS ECS django settings | |
""" | |
import requests | |
from .settings import * # may look different for your project | |
def get_ecs_task_ips(): | |
""" |
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 google.oauth2 import service_account | |
from google_auth_oauthlib.flow import InstalledAppFlow | |
SCOPE = ['https://www.googleapis.com/auth/drive'] # example scope | |
def get_google_credentials_oauth2(client_secrets_file, port=5555): | |
""" | |
get credentials via oauth flow |
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 google.oauth2 import service_account | |
from google_auth_oauthlib.flow import InstalledAppFlow | |
def get_oauth2_credentials(client_secrets_file, port=5555, scopes=SCOPES): | |
""" | |
Get google credentials via oauth flow | |
Opens up a browser for user to sign in | |
Requires client secrets file (select application type = 'other' when creating client in google console) | |
Sets default local web server port to 5555, since 8080 not usually available locally, but port can be specified as |
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
gdoc = gdocrevisions.GoogleDoc(...) | |
slices = [] # save things here | |
gdoc.content.reset() # reset document | |
for i, revision in enumerate(gdoc.revisions): | |
gdoc.content.apply(revision) # apply revision | |
if i%100==1: # every 100th revision | |
slices.append(gdoc.content.render()) # save document state to slices | |
OlderNewer