Skip to content

Instantly share code, notes, and snippets.

@alexdelorenzo
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexdelorenzo/9459232 to your computer and use it in GitHub Desktop.
Save alexdelorenzo/9459232 to your computer and use it in GitHub Desktop.
semicolon's okcupid
"""Import the modules"""
In [1]: from OKQuestions import OKQuestions as OKQS
In [2]: from bs4 import BeautifulSoup as BS
In [3]: from OKSession import OKSession as OKS
In [4]: from OKProfile import OKProfile as OKP
In [5]: from OKBrowse import OKBrowse as OKB
"""Login"""
In [6]: my_session = OKS('throwaway_12', 'passwd')
"""Grab a profile, parse it, and fetch the first page of match questions"""
In [7]: tfries = OKP(my_session, 'TFries4')
In [8]: tfries.read()
In [9]: tfries.questions.read()
In [10]: tfries.questions
Out[10]: TFries4's answers to 10 questions of 133 total.
In [11]: [val for val in tfries.questions.answers.values()]
Out[11]:
[#55744: No.,
#40441: Yes.,
#18594: Answer publicly to see my answer,
#6722: Answer publicly to see my answer,
#31581: Sure, no problem.,
#348: Answer publicly to see my answer,
#20725: Rarely / never,
#6350: Answer publicly to see my answer,
#28478: Answer publicly to see my answer,
#784: Yes]
In [12]:
In [12]: for question_id, question_obj in tfries.questions.answers.items():
....: print(question_obj.question, question_obj.answer)
....:
If you were going to have a child, would you want the other parent to be of the same ethnicity as you? No.
If you were to die, would whoever goes through your personal belongings be shocked by what they find? Yes.
Do superficial people, who place a high emphasis on physical appearance, annoy you? Answer publicly to see my answer
Which best describes your personal feelings about sports? Answer publicly to see my answer
Your significant other's ex is coming into town and he/she wants to go out to dinner with them alone. How do you react? Sure, no problem.
Which do you like more? Be honest. Answer publicly to see my answer
Do you space out or daydream a lot? Rarely / never
How would you describe your body? Answer publicly to see my answer
If a blind date used a coupon while paying for dinner, how would you feel? Answer publicly to see my answer
Would you be okay with your significant other spending a lot of time with one of his/her exes (as a friend)? Yes
"""Parse ALL of the questions"""
In [13]: tfries.questions
Out[13]: TFries4's answers to 10 questions of 133 total.
In [14]: tfries.questions.get_all()
In [15]: tfries.questions
Out[15]: TFries4's answers to 114 questions of 133 total.
In [16]: tfries.questions.total, tfries.questions.total_accessible
Out[16]: ('133', '100')
"""I'm feeling lucky search"""
In [17]: browse = OKB(my_session)
In [18]: browse.read()
In [19]: browse.results
Out[19]: OrderedDict([('goddesschik', goddesschik's profile at 140642689530512), ('rhea2988', rhea2988's profile at 140642689755984), ('mymetalheart', mymetalheart's profile at 140642689756176), ('pinkvelvet0x', pinkvelvet0x's profile at 140642689755536), ('mlny74', mlny74's profile at 140642687128528), ('TeamSanity', TeamSanity's profile at 140642687128656), ('sexyxceci', sexyxceci's profile at 140642687128336), ('OkCupidNga', OkCupidNga's profile at 140642687128976), ('_Lania_', _Lania_'s profile at 140642694986128)])
In [20]: len(browse.results)
Out[20]: 9
"""Search results are cumulative upon invoking read()"""
In [21]: browse.read()
In [22]: len(browse.results)
Out[22]: 18
In [23]: browse.read()
In [24]: len(browse.results)
Out[24]: 24
""" Let's see how we'd use this to get data in aggregate""""
In [25]: profiles = [profile for profile in browse.results.values()]
In [26]: [profile.username for profile in profiles]
Out[26]:
['goddesschik',
'rhea2988',
'mymetalheart',
'pinkvelvet0x',
'mlny74',
'TeamSanity',
'sexyxceci',
'OkCupidNga',
'_Lania_',
'alymarie506',
'ebrahits',
'lovely315',
'cottonandwool',
'pardonmyaccent',
'folktroubadour',
'LadieBug698',
'tde2011',
'ajb6023',
's_curve',
'WindyMtns',
'Reale78',
'Telicity',
'luckieapple',
'CityJen']
In [27]: five_profiles = profiles[:5]
""" Parse their questions """
In [28]: [pro.questions.read() for pro in five_profiles]
Out[28]: [None, None, None, None, None]
In [29]: questions = [pro.questions for pro in five_profiles]
In [30]: questions
Out[30]:
[goddesschik's answers to 10 questions of 86 total.,
rhea2988's answers to 10 questions of 822 total.,
mymetalheart's answers to 10 questions of 163 total.,
pinkvelvet0x's answers to 10 questions of 686 total.,
mlny74's answers to 10 questions of 47 total.]
In [31]: lotsa_answers = questions[0]
In [32]: lotsa_answers
Out[32]: rhea2988's answers to 10 questions of 822 total.
"""There are apparently thousands of questions. This can handle that"""
In [34]: lotsa_answers.get_all()
In [35]: lotsa_answers
Out[35]: rhea2988's answers to 816 questions of 822 total.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment