Skip to content

Instantly share code, notes, and snippets.

View achavez's full-sized avatar

Andrew Chavez achavez

View GitHub Profile
@achavez
achavez / travis-elex-formatter.py
Last active August 29, 2015 14:08
Travis County precinct-by-precinct results parser
import csv, sys
# This is a quick and dirty solution to walk the file that Travis County distributes
# the day after the election and create a new .csv file that has one row per race
# per precinct with the winner and his/her/its vote percentage
#
# CLI usage: python travis-elex-formatter.py input_file.csv output_file.csv
last_field = None
winner_total_votes = 0
@achavez
achavez / file_list.py
Last active August 29, 2015 14:07
Get all files in a directory with a specific file extension
import os
def list_files(source, extension):
matches = []
for root, dirnames, filenames in os.walk(source):
for filename in filenames:
if filename.endswith((extension)):
print filename
# Ex: Get all files in the directory docs with the extension PDF
@achavez
achavez / jou_scraper.py
Last active August 29, 2015 14:00
Scraper for schiefferschool.tcu.edu
from bs4 import BeautifulSoup
import requests, csv
# Settings
base_url = 'http://www.schiefferschool.tcu.edu/'
story_list_url = 'more_headlines.asp'
blacklist = ['931.htm', '1021.asp']
# Get a list of articles to scrape from the More Headlines page
news_page = requests.get(base_url + story_list_url)
@achavez
achavez / gist:9767499
Created March 25, 2014 17:59
Post to Slack using javascript
var url = // Webhook URL
var text = // Text to post
$.ajax({
data: 'payload=' + JSON.stringify({
"text": text
}),
dataType: 'json',
processData: false,
type: 'POST',
url: url