Skip to content

Instantly share code, notes, and snippets.

Joshua Ruihley jroo

View GitHub Profile
View take_it_on_the_run.py
#songsincode
def another():
return "you've been messing around"
def friend(x):
return another() if x else friend(1)
i=friend(0)
@jroo
jroo / session_from_year.py
Created Jun 12, 2009
returns session number of Congress for a provided year
View session_from_year.py
#returns session number of Congress for a provided year
def session_from_year(year):
return 2 - (year % 2)
View string_date_to_date.py
#python string date to date
date_str = "June 8, 1976"
release_date = time.strftime('%Y-%m-%d', time.strptime(date_str, '%B %d, %Y'))
@jroo
jroo / grab_gao_pastyear.py
Created Mar 22, 2009
returns list of GAO reports for past year
View grab_gao_pastyear.py
import datetime, time
import urllib2
from BeautifulSoup import BeautifulSoup
#returns list of GAO reports for past year
def grab_gao():
doc_type = "GAO"
page = urllib2.urlopen("http://gao.gov/docsearch/pastyear.html")
soup = BeautifulSoup(page)
report_list = []
@jroo
jroo / congress_from_year.py
Created Feb 22, 2009
returns number of Congress in session for provided year
View congress_from_year.py
#returns number of Congress in session for provided year
def congress_from_year(year):
if year < 1789:
return None
else:
return int((year-1789)/2) + 1
@jroo
jroo / extract_gao_id.py
Created Feb 22, 2009
extract GAO report ID's from text and return as a list
View extract_gao_id.py
import re
#extract GAO report ID's from text and return as a list
def extract_gao_id(haystack):
p = re.compile('GAO-\d{2}-?\d{1,4}\w?')
needle_list = p.findall(haystack)
return needle_list
@jroo
jroo / extract_ordercodes.py
Created Feb 22, 2009
extract CRS report order codes from string and return as list
View extract_ordercodes.py
import re
#extract CRS report order codes from string and return as list
def extract_ordercodes(haystack):
p = re.compile('R\d{5}|RL\d{5}|RS\d{5}|IB\d{5}')
needle_list = p.findall(haystack)
return needle_list
@jroo
jroo / extract_laws.py
Created Feb 22, 2009
return list of U.S. public law numbers extracted from string
View extract_laws.py
import re
# return list of public law numbers extracted from string
def extract_laws(haystack):
p = re.compile('P\.L\.\s?\d{1,3}-\d{1,3}')
needle_list = p.findall(haystack)
return needle_list
@jroo
jroo / extract_legislation.py
Created Feb 22, 2009
return list of congressional bill numbers extracted from string
View extract_legislation.py
# return list of bill numbers extracted from string
import re
def extract_legislation(haystack):
haystack = haystack.upper()
p = re.compile('S\.?\s?CON\.?\s?RES\.?\s?\d{1,5}|H\.?\s?CON\s?RES\.?\s?\d{1,5}|S\.?\s?J\.?\s?RES\.?\s\d{1,5}|H\.?\s?J\.?\s?RES\.?\s\d{1,5}|S\.?\s?RES\.?\s?\d{1,5}|H\.?\s?RES\.?\s?\d{1,5}|H\.?\s?\R\.?\s?\d{1,5}|S\.?\s?\d{1,5}')
needle_list = p.findall(haystack)
return needle_list
You can’t perform that action at this time.