Skip to content

Instantly share code, notes, and snippets.

@shaunagm
shaunagm / sample_code.py
Created October 2, 2023 19:37
Sample code for Oct 2 2023 training
"""
This file functions as a brief introduction to Parsons. To install Parsons, follow this
guide: https://parsons.pubpub.org/installation. If you're used to installing with pip, the tldr is
"pip install parsons".
"""
# print("Let's do this!")
"""
This is a Parsons Table. It's how we store data using Parsons. You can create a Table from a variety of sources,
@shaunagm
shaunagm / accumulator.py
Created June 6, 2023 19:05
"accumulator" - internal helper script from TMC that may be usefully moved into Parsons
import petl
from parsons import Redshift, Table
from parsons.utilities.files import close_temp_file
from canalespy import logger
VALID_STRATEGIES = ['copy', 'local_file', 'upsert']
@shaunagm
shaunagm / snippets.py
Created February 2, 2023 00:58
snippets for Parsons "Intro to Python" training
# Here's some data to play with!
data = [
{'first_name': 'Megan', 'last_name': 'Rapinoe', 'age': '37', 'date_updated': '1674121763'},
{'first_name': 'Tobin', 'last_name': 'Heath', 'age': '34', 'date_updated': '1664121763'},
{'first_name': 'Crystal', 'last_name': 'Dunn', 'age': '31', 'date_updated': '1664121763'},
{'first_name': 'Midge', 'last_name': 'Purce', 'age': '26', 'date_updated': '1664121763'},
{'first_name': 'Sophia', 'last_name': 'Smith', 'age': '23', 'date_updated': '1664121763'}
]
@shaunagm
shaunagm / digidems_demo_script.py
Created August 17, 2022 17:41
demo script for digidems webinar Aug 2022
#############
### SETUP ###
#############
from parsons import MobilizeAmerica, GoogleSheets
mobilize = MobilizeAmerica()
sheets = GoogleSheets() # don't forget to set GOOGLE_DRIVE_CREDENTIALS environmental variable
@shaunagm
shaunagm / day3script.py
Created July 14, 2022 16:35
Script for Day 3 of Intro to Parsons Training
from parsons import MobilizeAmerica, ActionNetwork, GoogleSheets, Table
#########################
### Getting your data ###
#########################
"""Typically you'd load data directly from your third party platform:"""
# mobilize = MobilizeAmerica()
@shaunagm
shaunagm / day2script.py
Last active July 13, 2022 21:13
Script for Day 2 of Intro to Parsons Training
##############################
### Get data from Mobilize ###
##############################
from parsons import MobilizeAmerica
"""Don't forget to set the MOBILIZE_AMERICA_API_KEY environment variable"""
mobilize = MobilizeAmerica()
mobilize.uri = "https://staging-api.mobilize.us/v1/" # only necessary since we're using a "developer sandbox"
@shaunagm
shaunagm / repower_parsons_training.py
Created July 9, 2022 18:54
Sample code for the re:power parsons training
"""
This file functions as a brief introduction to Parsons. To install Parsons, follow this
guide: https://parsons.pubpub.org/installation. If you're used to installing with pip, the tldr is
"pip install parsons".
"""
# print("Let's do this!")
@shaunagm
shaunagm / etl_training_script.py
Last active April 24, 2023 18:04
Script for "Intro to ETL" Training (Part 1)
#-----------------------------------------------------------
# Import Necessary Packages
#-----------------------------------------------------------
import json
from parsons import Table, MobilizeAmerica, GoogleSheets
from datetime import datetime
#-----------------------------------------------------------
# Instantiate Classes/Connect to Mobilize and Google Sheets
@shaunagm
shaunagm / script.py
Created April 21, 2022 16:33
Parsons authentication training script
"""
This script was created for the Parsons "All About Authentication" training.
"""
from parsons import Table, Twilio, GoogleSheets
twilio = Twilio()
sheets = GoogleSheets()
# Get data from google sheets
from parsons import Table
# Download NC Voter data file from: https://s3.amazonaws.com/dl.ncsbe.gov/data/ncvoter_Statewide.zip
# Extract (very large, I had to use an external haard drive)
# load the file into a Parsons table
# note #1 - need to specify encoding as it's not default UTF-8
# used "file -i ncvoter_Statewide.txt" on Linux to find file's encoding which was charset=iso-8859-1
# python codecs list says charset=iso-8859-1 is called latin_1