Skip to content

Instantly share code, notes, and snippets.

View aparrish's full-sized avatar

Allison Parrish aparrish

View GitHub Profile
import urllib2
import simplejson
import re
import requests
from bs4 import BeautifulSoup
from random import choice
# The request also includes the userip parameter which provides the end
# user's IP address. Doing so will help distinguish this legitimate
@aparrish
aparrish / foxnews.py
Created April 27, 2012 21:51
foxnews tweets
import urllib
import json
resp = urllib.urlopen("https://api.twitter.com/1/statuses/user_timeline.json?screen_name=foxnews&count=200")
tweets = json.loads(resp.read())
for tweet in tweets:
print tweet['text']
@aparrish
aparrish / romnye.txt
Created May 31, 2012 16:17
list of single-word wikipedia topics ending in -ica
.africa
Aarktica
Ablephica
Academica
Académica
Acaenica
Acalica
Acanthodica
Acelica
Acoustica
@aparrish
aparrish / random_followers.py
Created June 11, 2012 15:47
random sample of twitter followers for a given screen name
# return a random sample of your twitter followers
# run like so:
# $ python random_followers.py <screen_name>
# where <screen_name> is the account you want followers for
import sys, random, json, urllib
sname = sys.argv[1]
ids_raw = urllib.urlopen(
"https://api.twitter.com/1/followers/ids.json?screen_name="+sname).read()
@aparrish
aparrish / star-n-b.txt
Created November 13, 2012 21:50
other things and blues
ajar-n-b
almodovar-n-b
babar-n-b
bazaar-n-b
dan bejar-n-b
bizarre-n-b
car-n-b
cigar-n-b
czar-n-b
côte-d'ivoire-n-b
@aparrish
aparrish / twitter_request_example.py
Created December 13, 2012 16:42
Here's how to make an OAuth1-signed request to the Twitter API with the requests library.
# Run on the command line like so:
# $ python your_consumer_key your_consumer_secret your_access_token your_token_secret
import requests
from requests.auth import OAuth1
import sys
consumer_key, consumer_secret, access_token, token_secret = \
[unicode(x) for x in sys.argv[1:]]
@aparrish
aparrish / fitbit_auth_example.py
Created January 6, 2013 15:43
A simple Tornado application that implements OAuth login and authenticated requests for Fitbit.
# simple tornado app that implements fitbit oauth login.
# requires tornado 2.4-ish. run on the command line like so:
# $ python fitbit_auth_example.py --port=<your port> \
# --fitbit_consumer_key=<your consumer key> \
# --fitbit_consumer_secret=<your consumer secret>
#
# make sure to set your fitbit app's callback URL to
# http://your-app-url.example.com/login
import tornado.web
@aparrish
aparrish / three_legged_oauth_helper.py
Created January 14, 2013 04:38
interactive python script to assist in getting access tokens for OAuth v1 APIs. requires python's OAuth2 library (pip install oauth2)
# an interactive python script to assist in getting access tokens for OAuth v1
# APIs. requires python's OAuth2 library (pip install oauth2)
#
# run from the command line like so:
#
# $ python three_legged_oauth_helper.py --consumer_key=<ckey> \
# --consumer_secret=<csecret> \
# --request_token_url=<request_token_url> \
# --authorize_url=<authorize_url> \
# --access_token_url=<access_token_url>
@aparrish
aparrish / facebook_app_token.py
Last active February 6, 2021 22:23
simple python script to fetch an access token for a Facebook application (not a user token)
# fetch an access token for a Facebook application
#
# run like so:
#
# $ python facebook_app_token.py --app_id=<your app id> --secret=<your secret>
#
# ... where <your app id> is your Facebook application ID, and <your secret>
# is the application secret for that application (both can be retrieved from
# the Facebook developer app)
@aparrish
aparrish / improved_concordance.py
Created February 22, 2013 03:31
a simple concordance: read a text file from standard input, create a dictionary relating each word in the input text to a list of lines in which that word occurs. when running the program, supply a single parameter on the command line to print out all lines in the input text containing that word.
import sys
concordance = dict()
for line in sys.stdin:
line = line.strip()
line_words = line.split(" ")
for word in line_words:
if word in concordance:
concordance[word].append(line)