Skip to content

Instantly share code, notes, and snippets.

@bchauSW
bchauSW / pairLettersInWords.py
Last active August 16, 2019 21:59
This script produces every possible pairing of letters from two words -- a letter from arg1 and a letter from arg2. Usage: python pairLettersInWords.py abcde fghij 12345
import sys
import itertools
if len(sys.argv) < 3:
print("Too few arguments -- at least 2 args are needed.")
exit(0)
print(len(sys.argv))
words = list(map(list, sys.argv[1:]))
@bchauSW
bchauSW / JudgeDemographics.py
Created August 3, 2019 20:59
This script extracts the demographics from this website and formats it into a readable format: https://www.fjc.gov/history/judges/biographical-directory-article-iii-federal-judges-export
import pandas as pd
from collections import Counter
df = pd.read_csv('judges.csv')
fields = ['Birth State', 'Gender', 'Race or Ethnicity', 'Party of Appointing President (1)']
for field in fields:
counts = Counter(df[field]).most_common()
with open(field + '.csv', 'w+') as f:
@bchauSW
bchauSW / sub2sub.py
Last active July 18, 2019 04:00
This script finds a person who posts to two specified subreddits.
import praw
reddit = praw.Reddit(client_id='clientid',
client_secret='clientsecret',
password='password',
user_agent='Script by me',
username='username')
checked_users = []
with open('users.txt', 'w+') as f:
@bchauSW
bchauSW / redditArticleAsAPM.py
Last active July 7, 2019 22:30
This script is triggered when a user is tagged in a news article submission comment, extracts the comment, and PM's the article to the tagging user.
import praw
import re
from praw.models import Comment
from newspaper import Article
import time
uname = 'username'
reddit = praw.Reddit(client_id='clientid',
client_secret='clientsecret',
password='password',
@bchauSW
bchauSW / redditDataParser.py
Last active December 4, 2020 14:58
This script uses the PRAW library to extract title data from https://www.reddit.com/r/r4r30Plus and format the data into a CSV file.
import praw
import re
from collections import Counter
reddit = praw.Reddit(client_id='clientid',
client_secret='clientsecret',
password='password',
user_agent='Script by me',
username='username')