Skip to content

Instantly share code, notes, and snippets.

@russelldavies
Created May 5, 2015 12:35
Show Gist options
  • Save russelldavies/110050fd827d713c5243 to your computer and use it in GitHub Desktop.
Save russelldavies/110050fd827d713c5243 to your computer and use it in GitHub Desktop.
OK Cupid Questions
"""
Script to find out when a person answered their questions on OK Cupid.
For some reason OKC displays when someone has answered a question when you
answer the same question in relation to their profile.
Kind of useless but interesting to see that most people insomniacs.
"""
from datetime import datetime
from functools import partial
import re
import sys
import requests
get = None
post = None
def login(username, password):
global get, post
headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.90 Safari/537.36'}
payload = {'username': username, 'password': password, 'okc_api': 1}
r = requests.post('https://www.okcupid.com/login', data=payload,
headers=headers)
if not r.ok:
print('Bad username or password')
return False
get = partial(requests.get, headers=headers, cookies=r.cookies)
post = partial(requests.post, headers=headers, cookies=r.cookies)
return True
def parse_answers(profile_name):
url = 'http://www.okcupid.com/profile/{}/questions?unanswered=1'.format(profile_name)
while url is not None:
r = get(url)
match = re.search(r'<li class="next"><a href="(/profile/.+)">Next', r.text)
if match:
url = 'http://www.okcupid.com' + match.group(1)
else:
url = None
targetid = re.search(r'<div id="action_bar" class="clearfix" data-userid="(\d+)">', r.text).group(1)
for qid in re.findall(r'data-qid="(\d+)"', r.text):
payload = {
'ajax': 1,
'submit': 1,
'answer_question': 1,
'skip': 0,
'show_all': 0,
'targetid': int(targetid),
'qid': int(qid),
'is_new': 0,
'answers': 1,
'matchanswers': 'irrelevant',
'importance': 5,
'is_public': 1,
'note': 'auto',
'delete_note': 0,
}
r = post('http://www.okcupid.com/questions/ask', data=payload)
if r.json()['target'] == 0:
continue
date_answered = datetime.utcfromtimestamp(r.json()['target']['date_answered'])
# In UTC
print(date_answered)
if __name__ == '__main__':
if len(sys.argv) != 4:
print('Usage: {} username password profile_name'.format(sys.argv[0]))
sys.exit(1)
if login(sys.argv[1], sys.argv[2]):
parse_answers(sys.argv[3])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment