okcupyd Package

okcupyd Package

okcupyd.__init__.interactive()[source]
class okcupyd.__init__.User(session=None)

Bases: object

Encapsulate a logged in okcupid user.

copy(profile_or_user)

Create a Copy instance with the provided object as the source and this User as the destination.

Parameters:profile_or_user – A User or Profile object.
delete_threads(thread_ids_or_threads)

Call delete_threads().

Parameters:thread_ids_or_threads – A list whose members are either MessageThread instances or okc_ids of message threads.
classmethod from_credentials(username, password)
Parameters:
  • username (str) – The username to log in with.
  • password (str) – The password to log in with.
get_profile(username)

Get the Profile associated with the supplied username.

Parameters:username – The username of the profile to retrieve.
get_question_answer_id(question, fast=False, bust_questions_cache=False)

Get the index of the answer that was given to question

See the documentation for get_user_question() for important caveats about the use of this function.

Parameters:
  • question (BaseQuestion) – The question whose answer_id should be retrieved.
  • fast (bool) – Don’t try to look through the users existing questions to see if arbitrarily answering the question can be avoided.
  • bust_questions_cache (bool) –
    param bust_questions_cache:
     clear the

    questions attribute of this users Profile before looking for an existing answer. Be aware that even this does not eliminate all race conditions.

get_user_question(question, fast=False, bust_questions_cache=False)

Get a UserQuestion corresponding to the given Question.

HUGE CAVEATS: If the logged in user has not answered the relevant question, it will automatically be answered with whatever the first answer to the question is.

For the sake of reducing the number of requests made when this function is called repeatedly this function does not bust the cache of this User‘s okcupyd.profile.Profile.questions attribute. That means that a question that HAS been answered could still be answered by this function if this User‘s questions was populated previously (This population happens automatically – See Fetchable for details about when and how this happens).

Parameters:
  • question (BaseQuestion) – The question for which a UserQuestion should be retrieved.
  • fast (bool) – Don’t try to look through the users existing questions to see if arbitrarily answering the question can be avoided.
  • bust_questions_cache (bool) – clear the questions attribute of this users Profile before looking for an existing answer. Be aware that even this does not eliminate all race conditions.
message(username, message_text)

Message an okcupid user. If an existing conversation between the logged in user and the target user can be found, reply to that thread instead of starting a new one.

Parameters:
  • username (str) – The username of the user to which the message should be sent.
  • message_text (str) – The body of the message.
quickmatch()

Return a Profile obtained by visiting the quickmatch page.

search(**kwargs)

Call SearchFetchable() to get a Fetchable object that will lazily perform okcupid searches to provide Profile objects matching the search criteria.

Defaults for gender, gentation, location and radius will be provided if none are given.

Parameters:kwargs – See the SearchFetchable() docstring for details about what parameters are available.
username

Return the username associated with the User.

okcupyd.__init__.AttractivenessFinder(*args, **kwargs)
class okcupyd.__init__.Statistics(user, message_threads=None, filters=(), attractiveness_finder=None)

Bases: object

attractiveness_filter(attractiveness_finder=None, min_attractiveness=0, max_attractiveness=10000)
average_attractiveness
average_conversation_length
average_first_message_length
count
has_attractiveness
has_messages
has_response
initiated
no_responses
portion_initiated
portion_received
received
response_rate
threads
time_filter(min_date=None, max_date=None)
with_filters(*filters, **kwargs)
okcupyd.__init__.save_file(filename, data)
class okcupyd.__init__.PhotoUploader(session=None, user_id=None, authcode=None)

Bases: object

Upload photos to okcupid.com.

confirm(pic_id, **kwargs)
delete(photo_id, album_id=0)

Delete a photo from the logged in users account.

Parameters:
  • photo_id – The okcupid id of the photo to delete.
  • album_id – The album from which to delete the photo.
upload(incoming)
upload_and_confirm(incoming, **kwargs)

Upload the file to okcupid and confirm, among other things, its thumbnail position.

Parameters:
  • incoming – A filepath string, Info object or a file like object to upload to okcupid.com. If an info object is provided, its thumbnail positioning will be used by default.
  • caption – The caption to add to the photo.
  • thumb_nail_left – For thumb nail positioning.
  • thumb_nail_top – For thumb nail positioning.
  • thumb_nail_right – For thumb nail positioning.
  • thumb_nail_bottom – For thumb nail positioning.
upload_by_filename(filename)
upload_file(file_object, image_type='jpeg')
upload_from_info(info)
class okcupyd.__init__.Session(requests_session)

Bases: object

A requests.Session with convenience methods for interacting with okcupid.com

build_path(path, secure=None)
default_login_headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36'}
do_login(username, password)
get_current_user_profile()

Get the okcupyd.profile.Profile associated with the supplied username.

Parameters:username – The username of the profile to retrieve.
get_profile(username)

Get the profile associated with the supplied username :param username: The username of the profile to retrieve.

classmethod login(username=None, password=None, requests_session=None)

Get a session that has authenticated with okcupid.com. If no username and password is supplied, the ones stored in okcupyd.settings will be used.

Parameters:
  • username (str) – The username to log in with.
  • password (str) – The password to log in with.
okc_delete(path, secure=None, **kwargs)
okc_get(path, secure=None, **kwargs)
okc_post(path, secure=None, **kwargs)
okc_put(path, secure=None, **kwargs)

attractiveness_finder Module

class okcupyd.attractiveness_finder.AttractivenessFinderDecorator(attractiveness_finder=None)[source]

Bases: object

class okcupyd.attractiveness_finder.CheckForExistenceAttractivenessFinder(attractiveness_finder=None)[source]

Bases: okcupyd.attractiveness_finder.AttractivenessFinderDecorator

find_attractiveness(username, *args, **kwargs)[source]
class okcupyd.attractiveness_finder.RoundedAttractivenessFinder(attractiveness_finder=None)[source]

Bases: okcupyd.attractiveness_finder.AttractivenessFinderDecorator

find_attractiveness(*args, **kwargs)[source]
class okcupyd.attractiveness_finder.CachedAttractivenessFinder(attractiveness_finder=None)[source]

Bases: okcupyd.attractiveness_finder.AttractivenessFinderDecorator

find_attractiveness(username, **kwargs)[source]

details Module

class okcupyd.details.Detail(id_name=None, presenter=None, updater=None)[source]

Bases: object

Represent a detail belonging to an okcupid.com profile.

NO_DEFAULT = <object object at 0x7f8cbadf5c10>
classmethod comma_separated_presenter(text)[source]
classmethod mapping_multi_updater(mapping)[source]
classmethod auto_indexed_updater(*options)[source]
classmethod mapping_updater(mapping, id_name=None)[source]
static default_updater(id_name, value)[source]
id_name[source]
update(value)[source]
class okcupyd.details.DeclarativeDetail[source]

Bases: object

updater = None
presenter = None
class okcupyd.details.Details(profile)[source]

Bases: object

Represent the details belonging to an okcupid.com profile.

classmethod name_detail_pairs()[source]
refresh()[source]
id_to_display_name_value[source]
as_dict[source]
convert_and_update(data)[source]
update(data)[source]
bodytype

The bodytype detail of an okcupid.com user’s profile.

orientation

The orientation detail of an okcupid.com user’s profile.

smokes

The smoking detail of an okcupid.com user’s profile.

drugs

The drugs detail of an okcupid.com user’s profile.

drinks

The drinking detail of an okcupid.com user’s profile.

job

The job detail of an okcupid.com user’s profile.

status

The status detail of an okcupid.com user’s profile.

monogamy

The monogamous detail of an okcupid.com user’s profile.

children

The children detail of an okcupid.com user’s profile.

education

The education detail of an okcupid.com user’s profile.

pets

The pets detail of an okcupid.com user’s profile.

diet

The diet detail of an okcupid.com user’s profile.

religion

The religion detail of an okcupid.com user’s profile.

sign

The sign detail of an okcupid.com user’s profile.

height

The height detail of an okcupid.com user’s profile.

ethnicities[source]

The ethnicities detail of an okcupid.com user’s profile.

income[source]

The income detail of an okcupid.com user’s profile.

languages[source]

The languages detail of an okcupid.com user’s profile.

okcupyd.details.declarative_detail

alias of languages

okcupyd.details.is_declarative_detail(x)
okcupyd.details.detail

The status detail of an okcupid.com user’s profile.

errors Module

exception okcupyd.errors.AuthenticationError[source]

Bases: exceptions.Exception

exception okcupyd.errors.NoCorrespondentError[source]

Bases: exceptions.Exception

essay Module

class okcupyd.essay.Essays(profile)[source]

Bases: object

Interface to reading and writing essays.

static build_essay_property(essay_index, essay_name)[source]
essay_names = ['self_summary', 'my_life', 'good_at', 'people_first_notice', 'favorites', 'six_things', 'think_about', 'friday_night', 'private_admission', 'message_me_if']

A list of the attribute names that are used to store the text of of essays on instances of this class.

short_name_to_title[source]
refresh()[source]
favorites
friday_night
good_at
message_me_if
my_life
people_first_notice
private_admission
self_summary
six_things
think_about

filter Module

class okcupyd.filter.Filters[source]

Bases: object

Registrar for functions that construct filters for submission in requests to okcupid.com

build_documentation_lines()[source]

Build a parameter documentation string that can appended to the docstring of a function that uses this Filters instance to build filters.

build_paramter_string(key)[source]
static any_decider(function, incoming, accepted_keys)[source]
static all_decider(function, incoming, accepted_keys)[source]
static all_not_none_decider(function, incoming, accepted_keys)[source]
static any_not_none_decider(function, incoming, accepted_keys)[source]
filters(**kwargs)[source]
build(**kwargs)[source]
register_filter_builder[source]

Register a filter function with this Filters instance. This function is curried with curry – that is, it can be invoked partially before it is fully evaluated. This allows us to pass kwargs to this function when it is used as a decorator:

@register_filter_builder(keys=('real_name',),
                         decider=Filters.any_decider)
def my_filter_function(argument):
    return '4,{0}'.format(argument)
Parameters:
  • function – The filter function to register.
  • keys – Keys that should be used as the argument names for function, if none are provided, the filter functions argument names will be used instead.
  • decider – a function of signature (function, incoming_keys, accepted_keys) that returns True if the filter function should be called and False otherwise. Defaults to all_not_none_decider()
  • acceptable_values – A list of acceptable values for the parameter of the filter function (or a list of lists if the filter function takes multiple parameters)
  • types – The type of the parameter accepted by the incoming filter function (or a list of types if the function takes multiple parameters)
  • descriptions – A description for the incoming filter function’s argument (or a list of descriptions if the filter function takes multiple arguments)
okcupyd.filter.gentation_filter(gentation)[source]
okcupyd.filter.age_filter(age_min=18, age_max=99)[source]
okcupyd.filter.location_filter(radius)[source]

helpers Module

class okcupyd.helpers.MessageInfo

Bases: tuple

MessageInfo(thread_id, message_id)

message_id

Alias for field number 1

thread_id

Alias for field number 0

class okcupyd.helpers.Messager(session)[source]

Bases: object

Send Messages to an okcupid user.

message_request_parameters(username, message, thread_id, authcode)[source]
send(username, message, authcode=None, thread_id=None)[source]
okcupyd.helpers.parse_fancydate(fancydate_text)[source]
okcupyd.helpers.parse_date_updated(date_updated_text)[source]
okcupyd.helpers.parse_contextual_date(date_updated_text)[source]
okcupyd.helpers.parse_slashed_date(date_updated_text)[source]
okcupyd.helpers.parse_abbreviated_date(date_updated_text)[source]
okcupyd.helpers.parse_time(date_updated_text)[source]
okcupyd.helpers.parse_day_of_the_week(date_updated_text)[source]
okcupyd.helpers.date_from_weekday(weekday)[source]
okcupyd.helpers.datetime_to_string(a_datetime)[source]
okcupyd.helpers.get_locid(session, location)[source]

Make a request to locquery resource to translate a string location search into an int locid. Returns ———- int

An int that OKCupid maps to a particular geographical location.
okcupyd.helpers.format_last_online(last_online)[source]

Return the upper limit in seconds that a profile may have been online. If last_online is an int, return that int. Otherwise if last_online is a str, convert the string into an int. Returns ———- int

okcupyd.helpers.update_looking_for(profile_tree, looking_for)[source]

Update looking_for attribute of a Profile.

okcupyd.helpers.update_details(profile_tree, details)[source]

Update details attribute of a Profile.

okcupyd.helpers.get_default_gentation(gender, orientation)[source]

Return the default gentation for the given gender and orientation.

okcupyd.helpers.replace_chars(astring)[source]

Replace certain unicode characters to avoid errors when trying to read various strings. Returns ———- str

okcupyd.helpers.add_newlines(tree)[source]

Add a newline character to the end of each <br> element.

looking_for Module

okcupyd.looking_for.status_filter(status)[source]
class okcupyd.looking_for.LookingFor(profile)[source]

Bases: object

Represent the looking for attributes belonging to an okcupid.com profile.

raw_fields[source]
gentation[source]

The sex/orientation that the user is looking for.

ages[source]

The age range that the user is interested in.

single[source]

Whether or not the user is only interested in people that are single.

near_me[source]

Whether the user is only interested in people that are close to them.

kinds[source]

The kinds of relationship tha the user is looking for.

update(ages=None, single=None, near_me=None, kinds=None, gentation=None)[source]

Update the looking for attributes of the logged in user.

Parameters:
  • ages (tuple) – The ages that the logged in user is interested in.
  • single (bool) – Whether or not the user is only interested in people that are single.
  • near_me (bool) – Whether or not the user is only interested in people that are near them.
  • kinds (list) – What kinds of relationships the user should be updated to be interested in.
  • gentation (str) – The sex/orientation of people the user is interested in.
class Ages

Bases: tuple

Ages(min, max)

max

Alias for field number 1

min

Alias for field number 0

magicnumbers Module

class okcupyd.magicnumbers.maps[source]

Bases: object

bodytype = <okcupyd.util.REMap object at 0x7f8cb9cb7cd0>
orientation = <okcupyd.util.REMap object at 0x7f8cb9cc3290>
smokes = <okcupyd.util.REMap object at 0x7f8cb9ccd550>
drugs = <okcupyd.util.REMap object at 0x7f8cb9ccd5d0>
drinks = <okcupyd.util.REMap object at 0x7f8cb9ccd750>
ethnicities = <okcupyd.util.REMap object at 0x7f8cb9ccd790>
job = <okcupyd.util.REMap object at 0x7f8cb9ccd7d0>
status = <okcupyd.util.REMap object at 0x7f8cb9ccd810>
monogamy = <okcupyd.util.REMap object at 0x7f8cb9ccd850>
strictness = <okcupyd.util.REMap object at 0x7f8cb9ccd890>
has_kids = <okcupyd.util.REMap object at 0x7f8cb9ccd8d0>
wants_kids = <okcupyd.util.REMap object at 0x7f8cb9ccd910>
education_status = <okcupyd.util.REMap object at 0x7f8cb9ccd950>
education_level = <okcupyd.util.REMap object at 0x7f8cb9ccd990>
religion = <okcupyd.util.REMap object at 0x7f8cb9ccd9d0>
seriousness = <okcupyd.util.REMap object at 0x7f8cb9ccda10>
sign = <okcupyd.util.REMap object at 0x7f8cb9ccda50>
importance = <okcupyd.util.REMap object at 0x7f8cb9ccda90>
dogs = <okcupyd.util.REMap object at 0x7f8cb9ccdad0>
cats = <okcupyd.util.REMap object at 0x7f8cb9ccdb10>
language_level = <okcupyd.util.REMap object at 0x7f8cb9ccdb50>
diet_strictness = <okcupyd.util.REMap object at 0x7f8cb9ccdb90>
diet = <okcupyd.util.REMap object at 0x7f8cb9ccdbd0>
income = <okcupyd.util.REMap object at 0x7f8cb9ccdc10>
class okcupyd.magicnumbers.MappingUpdater(mapping)[source]

Bases: object

class okcupyd.magicnumbers.SimpleFilterBuilder(filter_number, mapping, offset=0)[source]

Bases: object

get_number(values)[source]
get_filter(values)[source]
class okcupyd.magicnumbers.filters[source]

Bases: object

bodytype = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccdd10>
smokes = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccdd50>
drinks = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccdd90>
drugs = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccddd0>
education_level = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccde10>
job = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccde50>
income = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccde90>
religion = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccded0>
monogamy = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccdf10>
diet = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccdf50>
sign = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccdf90>
ethnicities = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb9ccdfd0>
dogs = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb55bd050>
cats = <okcupyd.magicnumbers.SimpleFilterBuilder object at 0x7f8cb55bd090>
okcupyd.magicnumbers.inches_to_centimeters(inches)[source]
okcupyd.magicnumbers.get_height_filter(height_min=None, height_max=None)[source]
okcupyd.magicnumbers.parse_height_string(height_string)[source]
okcupyd.magicnumbers.get_kids_filter(has_kids=(), wants_kids=())[source]
okcupyd.magicnumbers.get_kids_int(has_kids, wants_kids)[source]
okcupyd.magicnumbers.subtract_has_kids_exponents(value)[source]
okcupyd.magicnumbers.yield_exponents_of_two(value)[source]
okcupyd.magicnumbers.get_language_query(language)[source]
okcupyd.magicnumbers.get_join_date_filter(join_date)[source]
okcupyd.magicnumbers.get_question_filter(question, question_answers=None)[source]

messaging Module

okcupyd.messaging.ThreadFetcher(session, mailbox_number)[source]
class okcupyd.messaging.ThreadHTMLFetcher(session, mailbox_number)[source]

Bases: object

fetch(start_at)[source]
class okcupyd.messaging.MessageFetcher(session, message_thread, read_messages=False)[source]

Bases: object

params[source]
messages_tree[source]
refresh()[source]
fetch()[source]
message_elements[source]
class okcupyd.messaging.Message(message_element, message_thread)[source]

Bases: object

Represent a message sent on okcupid.com

id[source]
Returns:The id assigned to this message by okcupid.com.
sender[source]
Returns:A Profile instance belonging to the sender of this message.
recipient[source]
Returns:A Profile instance belonging to the recipient of this message.
content[source]
Returns:The text body of the message.
time_sent[source]
class okcupyd.messaging.MessageThread(session, thread_element)[source]

Bases: object

Represent a message thread between two users.

classmethod delete_threads(session, thread_ids_or_threads, authcode=None)[source]
Parameters:
  • session – A logged in Session.
  • thread_ids_or_threads – A list whose members are either MessageThread instances or okc_ids of message threads.
  • authcode – Authcode to use for this request. If none is provided A request to the logged in user’s messages page will be made to retrieve one.
messages = None

A Fetchable of Message objects.

id[source]
Returns:The id assigned to this message by okcupid.com.
correspondent_id[source]
Returns:The id assigned to the correspondent of this message.
correspondent[source]
Returns:The username of the user with whom the logged in user is conversing in this MessageThread.
read[source]
Returns:Whether or not the user has read all the messages in this MessageThread.
date[source]
datetime[source]
with_deleted_user[source]
initiator[source]
Returns:A Profile instance belonging to the initiator of this MessageThread.
respondent[source]
Returns:A Profile instance belonging to the respondent of this MessageThread.
correspondent_profile[source]
Returns:The Profile of the user with whom the logged in user is conversing in this MessageThread.
user_profile[source]
Returns:A Profile belonging to the logged in user.
message_count[source]
has_messages[source]
got_response[source]
Returns:Whether or not the MessageThread. has received a response.
delete()[source]

Delete this thread for the logged in user.

photo Module

class okcupyd.photo.PhotoUploader(session=None, user_id=None, authcode=None)[source]

Bases: object

Upload photos to okcupid.com.

upload(incoming)[source]
upload_from_info(info)[source]
upload_by_filename(filename)[source]
upload_file(file_object, image_type='jpeg')[source]
confirm(pic_id, **kwargs)[source]
upload_and_confirm(incoming, **kwargs)[source]

Upload the file to okcupid and confirm, among other things, its thumbnail position.

Parameters:
  • incoming – A filepath string, Info object or a file like object to upload to okcupid.com. If an info object is provided, its thumbnail positioning will be used by default.
  • caption – The caption to add to the photo.
  • thumb_nail_left – For thumb nail positioning.
  • thumb_nail_top – For thumb nail positioning.
  • thumb_nail_right – For thumb nail positioning.
  • thumb_nail_bottom – For thumb nail positioning.
delete(photo_id, album_id=0)[source]

Delete a photo from the logged in users account.

Parameters:
  • photo_id – The okcupid id of the photo to delete.
  • album_id – The album from which to delete the photo.
class okcupyd.photo.Info(photo_id, tnl, tnt, tnr, tnb)[source]

Bases: object

Represent a photo that appears on a okcupid.com user’s profile.

base_uri = 'https://k0.okccdn.com/php/load_okc_image.php/images/'
cdn_re = <_sre.SRE_Pattern object at 0x1b40940>
classmethod from_cdn_uri(cdn_uri)[source]
thumb_nail_left = None

The horizontal position of the left side of this photo’s thumbnail.

thumb_nail_top = None

The vertical position of the top side of this photo’s thumbnail.

thumb_nail_right = None

The horizontal position of the right side of this photo’s thumbnail.

thumb_nail_bottom = None

The vertical position of the bottom side of this photo’s thumbnail.

jpg_uri[source]
Returns:A uri from which this photo can be downloaded in jpg format.

profile Module

class okcupyd.profile.Profile(session, username, **kwargs)[source]

Bases: object

Represent the profile of an okcupid user.

Many of the attributes on this object are cached_property instances which lazily load their values, and cache them once they have been accessed. This makes it so that this object avoids making unnecessary HTTP requests to retrieve the same piece of information twice.

Because of this caching behavior, care must be taken to invalidate cached attributes on the object if an up to date view of the profile is needed. It is recommended that you call refresh() to accomplish this, but it is also possible to use bust_self() to bust individual properties if necessary.

username = None

The username of the user to whom this profile belongs.

questions = None

A Fetchable of Question instances, each corresponding to a question that has been answered by the user to whom this profile belongs. The fetchable consists of UserQuestion instead when the profile belongs to the logged in user.

details = None

A Details instance belonging to the same user that this profile belongs to.

refresh(reload=False)[source]
Parameters:reload – Make the request to return a new profile tree. This will result in the caching of the profile_tree attribute. The new profile_tree will be returned.
is_logged_in_user[source]
Returns:True if this profile and the session it was created with belong to the same user and False otherwise.
profile_tree[source]
Returns:a lxml.etree created from the html of the profile page of the account associated with the username that this profile was insantiated with.
message_request_parameters(content, thread_id)[source]
authcode[source]
photo_infos[source]
Returns:list of Info instances for each photo displayed on okcupid.
looking_for[source]
Returns:A LookingFor instance associated with this profile.
rating[source]

Deprecated. Use liked() instead.

Returns:the rating that the logged in user has given this user or 0 if no rating has been given.
liked[source]
Returns:Whether or not the logged in user liked this profile
contacted[source]
Retuns:A boolean indicating whether the logged in user has contacted the owner of this profile.
responds[source]
Returns:The frequency with which the user associated with this profile responds to messages.
id[source]
Returns:The id that okcupid.com associates with this profile.
essays[source]
Returns:A Essays instance that is associated with this profile.
age[source]
Returns:The age of the user associated with this profile.
match_percentage[source]
Returns:The match percentage of the logged in user and the user associated with this object.
enemy_percentage[source]
Returns:The enemy percentage of the logged in user and the user associated with this object.
location[source]
Returns:The location of the user associated with this profile.
gender[source]

The gender of the user associated with this profile.

orientation[source]

The sexual orientation of the user associated with this profile.

message[source]

Message the user associated with this profile.

Parameters:
  • message – The message to send to this user.
  • thread_id – The id of the thread to respond to, if any.
attractiveness[source]
Returns:The average attractiveness rating given to this profile by the okcupid.com community.
toggle_like()[source]

Toggle whether or not the logged in user likes this profile.

like()[source]

Like this profile.

unlike()[source]

Unlike this profile.

rate(rating)[source]

Rate this profile as the user that was logged in with the session that this object was instantiated with.

Parameters:rating – The rating to give this user.
find_question(question_id, question_fetchable=None)[source]
Parameters:
  • question_id – The id of the question to search for
  • question_fetchable – The question fetchable to iterate through if none is provided self.questions will be used.
question_fetchable(**kwargs)[source]
Returns:A Fetchable instance that contains objects representing the answers that the user associated with this profile has given to okcupid.com match questions.
authcode_get(path, **kwargs)[source]

Perform an HTTP GET to okcupid.com using this profiles session where the authcode is automatically added as a query parameter.

authcode_post(path, **kwargs)[source]

Perform an HTTP POST to okcupid.com using this profiles session where the authcode is automatically added as a form item.

profile_copy Module

class okcupyd.profile_copy.Copy(source_profile_or_user, dest_user)[source]

Bases: object

Copy photos, essays and other attributes from one profile to another.

copy_methods = ['photos', 'essays', 'looking_for', 'details', 'questions']
questions()[source]

Copy questions to the destination user. When this class was initialized with a Profile, this will delete any existing questions answers on the destination account.

photos()[source]

Copy photos to the destination user.

essays()[source]

Copy essays from the source profile to the destination profile.

looking_for()[source]

Copy looking for attributes from the source profile to the destination profile.

details()[source]

Copy details from the source profile to the destination profile.

all()[source]

Invoke all of questions(), details(), essays(), photos(), looking_for()

question Module

class okcupyd.question.BaseQuestion(question_element)[source]

Bases: object

The abstract abse class of Question and UserQuestion. Contains all the shared functinality of the aforementined classes. The two are quite different in some ways and can not always be used interchangably. See their respective docstrings for more details.

answered[source]
id[source]
Returns:The integer id given to this question by okcupid.com.
text[source]
class okcupyd.question.Question(question_element)[source]

Bases: okcupyd.question.BaseQuestion

Represent a question answered by a user other than the logged in user.

Note: Because of the way that okcupid presents question data it is actually not very easy to get the index of the answer to a question that belongs to a user other than the logged in user. It is possible to retrieve this value (see okcupyd.user.User.get_question_answer_id() and get_answer_id_for_question()), but it can take quite a few requests to do so. For this reason, the answer_id is NOT included as an attribute on this object, despite its inclusion in UserQuestion.

return_none_if_unanswered(function)[source]
their_answer[source]

The answer that the user whose Profile this question was retrieved from provided to this Question.

my_answer[source]

The answer that the user whose Session was used to create this Question provided.

their_answer_matches[source]
Returns:whether or not the answer provided by the user answering the question is acceptable to the logged in user.
Return type:rbool
my_answer_matches[source]
Returns:bool indicating whether or not the answer provided by the logged in user is acceptable to the user answering the question.
their_note[source]
Returns:The note the answering user provided as explanation for their answer to this question.
my_note[source]
Returns:The note the logged in user provided as an explanation for their answer to this question.
class okcupyd.question.UserQuestion(question_element)[source]

Bases: okcupyd.question.BaseQuestion

Represent a question answered by the logged in user.

get_answer_id_for_question(question)[source]

Get the answer_id corresponding to the answer given for question by looking at this UserQuestion‘s answer_options. The given Question instance must have the same id as this UserQuestion.

That this method exists is admittedly somewhat weird. Unfortunately, it seems to be the only way to retrieve this information.

answer_id[source]
answer_options[source]
Returns:A list of AnswerOption instances representing the available answers to this question.
explanation[source]
Returns:The explanation written by the logged in user for this question (if any).
answer_text_to_option[source]
answer[source]
Returns:A AnswerOption instance corresponding to the answer the user gave to this question.
class okcupyd.question.AnswerOption(option_element)[source]

Bases: object

is_users[source]
Returns:Whether or not this was the answer selected by the logged in user.
is_match[source]
Returns:Whether or not this was the answer is acceptable to the logged in user.
text[source]
Returns:The text of this answer.
id[source]
Returns:The integer index associated with this answer.
class okcupyd.question.Questions(session, importances=('not_important', 'little_important', 'somewhat_important', 'very_important', 'mandatory'), user_id=None)[source]

Bases: object

Interface to accessing and answering questions belonging to the logged in user.

headers = {'origin': 'https://www.okcupid.com', 'accept-language': 'en-US,en;q=0.8', 'accept-encoding': 'gzip,deflate', 'accept': 'application/json, text/javascript, */*; q=0.01', 'referer': 'https://www.okcupid.com/questions', 'x-requested-with': 'XMLHttpRequest', 'content-type': 'application/x-www-form-urlencoded; charset=UTF-8'}
importance_name_to_number = {'not_important': 5, 'little_important': 4, 'mandatory': 0, 'very_important': 1, 'somewhat_important': 3}

Human readable importance name to integer used to represent them on okcupid.com

path = 'questions/ask'
respond_from_user_question(user_question, importance)[source]

Respond to a question in exactly the way that is described by the given user_question.

Parameters:
  • user_question (UserQuestion) – The user question to respond with.
  • importance (int see importance_name_to_number) – The importance that should be used in responding to the question.
respond_from_question(question, user_question, importance)[source]

Copy the answer given in question to the logged in user’s profile.

Parameters:
  • question – A Question instance to copy.
  • user_question – An instance of UserQuestion that corresponds to the same question as question. This is needed to retrieve the answer id from the question text answer on question.
  • importance – The importance to assign to the response to the answered question.
respond(question_id, user_response_ids, match_response_ids, importance, note='', is_public=1, is_new=1)[source]

Respond to an okcupid.com question.

Parameters:
  • question_id – The okcupid id used to identify this question.
  • user_response_ids – The answer id(s) to provide to this question.
  • match_response_ids – The answer id(s) that the user considers acceptable.
  • importance – The importance to attribute to this question. See importance_name_to_number for details.
  • note – The explanation note to add to this question.
  • is_public – Whether or not the question answer should be made public.
clear()[source]

USE WITH CAUTION. Delete the answer to every question that the logged in user has responded to.

okcupyd.question.QuestionProcessor(question_class)[source]
class okcupyd.question.QuestionHTMLFetcher(session, uri, **additional_parameters)[source]

Bases: object

classmethod from_username(session, username, **kwargs)[source]
fetch(start_at)[source]
okcupyd.question.QuestionFetcher(session, username, question_class=<class 'okcupyd.question.Question'>, is_user=False, **kwargs)[source]

search Module

okcupyd.search.search_filters = Filters([<function option_filter at 0x7f8cb54930c8>, <function option_filter at 0x7f8cb5482410>, <function get_kids_filter at 0x7f8cb55bb1b8>, <function option_filter at 0x7f8cb5482d70>, <function option_filter at 0x7f8cb54828c0>, <function get_language_query at 0x7f8cb55bb398>, <function attractiveness_filter at 0x7f8cb5482140>, <function question_count_filter at 0x7f8cb54821b8>, <function option_filter at 0x7f8cb54829b0>, <function status_filter at 0x7f8cb54822a8>, <function get_question_filter at 0x7f8cb55bb488>, <function option_filter at 0x7f8cb5482b90>, <function age_filter at 0x7f8cb55bbc08>, <function get_join_date_filter at 0x7f8cb55bb410>, <function option_filter at 0x7f8cb5482aa0>, <function location_filter at 0x7f8cb55bbc80>, <function get_height_filter at 0x7f8cb55bb0c8>, <function option_filter at 0x7f8cb5482500>, <function last_online_filter at 0x7f8cb5482230>, <function gentation_filter at 0x7f8cb55bb578>, <function option_filter at 0x7f8cb5482c80>, <function option_filter at 0x7f8cb54825f0>, <function option_filter at 0x7f8cb5482e60>, <function option_filter at 0x7f8cb54826e0>, <function option_filter at 0x7f8cb5482f50>, <function option_filter at 0x7f8cb54827d0>])

A Filters object that stores all of the filters that are accepted by SearchFetchable().

okcupyd.search.attractiveness_filter(attractiveness_min, attractiveness_max)[source]
okcupyd.search.question_count_filter(question_count_min)[source]
okcupyd.search.last_online_filter(last_online)[source]
okcupyd.search.status_filter(status)[source]
okcupyd.search.build_option_filter(key)[source]
class okcupyd.search.MatchCardExtractor(div)[source]

Bases: object

id[source]
username[source]
age[source]
location[source]
match_percentage[source]
enemy_percentage[source]
contacted[source]
as_dict[source]
okcupyd.search.SearchFetchable(session=None, **kwargs)[source]

Search okcupid.com with the given parameters. Parameters are registered to this function through register_filter_builder() of search_filters.

Returns:

A Fetchable of Profile instances.

Parameters:
  • session (Session) – A logged in session.
  • location – A location string which will be used to filter results.
  • gender – The gender of the user performing the search.
  • keywords – A list or space delimeted string of words to search for.
  • order_by – The criteria to use for ordering results. expected_values: ‘match’, ‘online’, ‘special_blend’
  • age_max (int) – The maximum age of returned search results.
  • age_min (int) – The minimum age of returned search results.
  • attractiveness_max (int) – The maximum attractiveness of returned search results.
  • attractiveness_min (int) – The minimum attractiveness of returned search results.
  • bodytype (str) – expected values: ‘jacked’, ‘rather not say’, ‘fit’, ‘athletic’, ‘used up’, ‘average’, ‘full figured’, ‘overweight’, ‘curvy’, ‘thin’, ‘a little extra’, ‘skinny’
  • cats (str) – expected values: ‘likes cats’, ‘dislikes cats’, ‘has cats’
  • diet (str) – expected values: ‘anything’, ‘vegetarian’, ‘vegan’, ‘kosher’, ‘other’, ‘halal’
  • dogs (str) – expected values: ‘dislikes dogs’, ‘has dogs’, ‘likes dogs’
  • drinks (str) – expected values: ‘desperately’, ‘often’, ‘socially’, ‘very often’, ‘not at all’, ‘rarely’
  • drugs (str) – expected values: ‘never’, ‘often’, ‘sometimes’
  • education_level (str) – expected values: ‘law school’, ‘two[- ]year college’, ‘university’, ‘space camp’, ‘high ?school’, ‘college’, ‘ph.d program’, ‘med school’, ‘masters program’
  • ethnicities (str) – expected values: ‘latin’, ‘pacific islander’, ‘middle eastern’, ‘hispanic’, ‘indian’, ‘black’, ‘asian’, ‘white’, ‘other’, ‘native american’
  • gentation (str) – The gentation of returned search results. expected values: ‘men and women who like bi women’, ‘gay girls only’, ‘bi guys only’, ‘gay guys only’, ‘’, ‘straight girls only’, ‘women who like men’, ‘bi men and women’, ‘guys who like girls’, ‘straight guys only’, ‘bi girls only’, ‘men and women who like bi men’, ‘guys and girls who like bi guys’, ‘both who like bi women’, ‘gay women only’, ‘gay men only’, ‘women’, ‘everybody’, ‘straight men only’, ‘girls who like girls’, ‘bi men only’, ‘both who like bi men’, ‘bi women only’, ‘guys who like guys’, ‘bi guys and girls’, ‘guys and girls who like bi girls’, ‘both who like bi guys’, ‘men who like women’, ‘girls who like guys’, ‘women who like women’, ‘both who like bi girls’, ‘straight women only’, ‘men who like men’
  • has_kids – expected values: ‘has a kid’, “doesn’t have kids”, ‘has kids’
  • height_max – The maximum height of returned search results. expected values: ‘A height int in inches’, ‘An imperial height string e.g. 5‘4”’, ‘A metric height string e.g. 1.54m’
  • height_min – The minimum height of returned search results. expected values: ‘A height int in inches’, ‘An imperial height string e.g. 5‘4”’, ‘A metric height string e.g. 1.54m’
  • income (str) – expected values: ‘$30,000-$40,000’, ‘$20,000-$30,000’, ‘$80,000-$100,000’, ‘$100,000-$150,000’, ‘$250,000-$500,000’, ‘less than $20,000’, ‘More than $1,000,000’, ‘$500,000-$1,000,000’, ‘$60,000-$70,000’, ‘$70,000-$80,000’, ‘$40,000-$50,000’, ‘$50,000-$60,000’, ‘$150,000-$250,000’
  • job (str) – expected values: ‘art’, ‘sales’, ‘engineering’, ‘politics’, ‘education’, ‘technology’, ‘management’, ‘entertainment’, ‘media’, ‘administration’, ‘writing’, ‘other’, ‘music’, ‘medicine’, ‘transportation’, ‘finance’, ‘retired’, ‘government’, ‘marketing’, ‘unemployed’, ‘construction’, ‘student’, ‘hospitality’, ‘law’, ‘rather not say’, ‘science’, ‘banking’, ‘military’
  • join_date (int) – expected values: ‘week’, ‘year’, ‘day’, ‘hour’, ‘month’
  • language – expected values: ‘portuguese’, ‘irish’, ‘chinese’, ‘czech’, ‘slovenian’, ‘sign language’, ‘hebrew’, ‘indonesian’, ‘rotuman’, ‘spanish’, ‘maori’, ‘slovak’, ‘mongolian’, ‘basque’, ‘urdu’, ‘polish’, ‘arabic’, ‘hungarian’, ‘esperanto’, ‘breton’, ‘italian’, ‘belarusan’, ‘icelandic’, ‘estonian’, ‘gujarati’, ‘occitan’, ‘serbian’, ‘sardinian’, ‘ancient greek’, ‘german’, ‘other’, ‘chechen’, ‘dutch’, ‘sanskrit’, ‘korean’, ‘farsi’, ‘hindi’, ‘danish’, ‘bulgarian’, ‘latin’, ‘khmer’, ‘latvian’, ‘hawaiian’, ‘ukrainian’, ‘welsh’, ‘georgian’, ‘lithuanian’, ‘malay’, ‘french’, ‘japanese’, ‘catalan’, ‘armenian’, ‘yiddish’, ‘swedish’, ‘russian’, ‘vietnamese’, ‘thai’, ‘afrikaans’, ‘tamil’, ‘cebuano’, ‘tagalog’, ‘finnish’, ‘norwegian’, ‘lisp’, ‘albanian’, ‘turkish’, ‘ilongo’, ‘romanian’, ‘c++’, ‘greek’, ‘persian’, ‘tibetan’, ‘frisian’, ‘english’, ‘croatian’, ‘swahili’, ‘bengali’
  • last_online (str) – expected values: ‘day’, ‘today’, ‘week’, ‘month’, ‘year’, ‘decade’
  • monogamy (str) – expected values: ‘(:?[^\-]monogamous)|(:?^monogamous)’, ‘non-monogamous’
  • question (UserQuestion) – A question whose answer should be used to match search results, or a question id. If a question id, question_answers must be supplied.
  • question_answers (list) – A list of acceptable question answer indices.
  • question_count_min (int) – The minimum number of questions answered by returned search results.
  • radius (int) – The maximum distance from the specified location of returned search results.
  • religion (str) – expected values: ‘judaism’, ‘catholicism’, ‘buddhism’, ‘christianity’, ‘atheism’, ‘agnosticism’, ‘other’, ‘hinduism’, ‘islam’
  • sign (str) – expected values: ‘libra’, ‘sagittarius’, ‘cancer’, ‘scorpio’, ‘aquarius’, ‘taurus’, ‘leo’, ‘virgo’, ‘capricorn’, ‘gemini’, ‘aries’, ‘pisces’
  • smokes (str) – expected values: ‘yes’, ‘sometimes’, ‘trying to quit’, ‘no’, ‘when drinking’
  • status (str) – The relationship status of returned search results. expected values: ‘not single’, ‘married’, ‘single’, ‘any’
  • wants_kids – expected values: ‘wants’, “doesn’t want”, ‘might want’
class okcupyd.search.SearchHTMLFetcher(session=None, **options)[source]

Bases: object

fetch(start_at=None, count=None)[source]
okcupyd.search.search(session=None, count=1, **kwargs)[source]

session Module

class okcupyd.session.Session(requests_session)[source]

Bases: object

A requests.Session with convenience methods for interacting with okcupid.com

default_login_headers = {'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.94 Safari/537.36'}
classmethod login(username=None, password=None, requests_session=None)[source]

Get a session that has authenticated with okcupid.com. If no username and password is supplied, the ones stored in okcupyd.settings will be used.

Parameters:
  • username (str) – The username to log in with.
  • password (str) – The password to log in with.
do_login(username, password)[source]
build_path(path, secure=None)[source]
get_profile(username)[source]

Get the profile associated with the supplied username :param username: The username of the profile to retrieve.

get_current_user_profile()[source]

Get the okcupyd.profile.Profile associated with the supplied username.

Parameters:username – The username of the profile to retrieve.
okc_delete(path, secure=None, **kwargs)
okc_get(path, secure=None, **kwargs)
okc_post(path, secure=None, **kwargs)
okc_put(path, secure=None, **kwargs)
okcupyd.session.build_okc_method(method_name)[source]

settings Module

Module where the default username and password for logging in to okcupid are housed.

okcupyd.settings.USERNAME = None

The username that will be used to log in to okcupid

okcupyd.settings.PASSWORD = None

The password that will be used to log in to okcupid

statistics Module

class okcupyd.statistics.Statistics(user, message_threads=None, filters=(), attractiveness_finder=None)[source]

Bases: object

threads[source]
has_messages[source]
has_response[source]
no_responses[source]
initiated[source]
received[source]
has_attractiveness[source]
time_filter(min_date=None, max_date=None)[source]
attractiveness_filter(attractiveness_finder=None, min_attractiveness=0, max_attractiveness=10000)[source]
with_filters(*filters, **kwargs)[source]
count[source]
response_rate[source]
average_first_message_length[source]
average_conversation_length[source]
average_attractiveness[source]
portion_initiated[source]
portion_received[source]

user Module

class okcupyd.user.User(session=None)[source]

Bases: object

Encapsulate a logged in okcupid user.

classmethod from_credentials(username, password)[source]
Parameters:
  • username (str) – The username to log in with.
  • password (str) – The password to log in with.
profile = None

A Profile object belonging to the logged in user.

inbox = None

A Fetchable of MessageThread objects corresponding to messages that are currently in the user’s inbox.

outbox = None

A Fetchable of MessageThread objects corresponding to messages that are currently in the user’s outbox.

drafts = None

A Fetchable of MessageThread objects corresponding to messages that are currently in the user’s drafts folder.

visitors = None

A Fetchable of Profile objects of okcupid.com users that have visited the user’s profile.

questions = None

A Questions object that is instantiated with the owning User instance’s session.

attractiveness_finder = None

An _AttractivenessFinder object that is instantiated with the owning User instance’s session.

photo = None

A PhotoUploader that is instantiated with the owning User instance’s session.

get_profile(username)[source]

Get the Profile associated with the supplied username.

Parameters:username – The username of the profile to retrieve.
username[source]

Return the username associated with the User.

message(username, message_text)[source]

Message an okcupid user. If an existing conversation between the logged in user and the target user can be found, reply to that thread instead of starting a new one.

Parameters:
  • username (str) – The username of the user to which the message should be sent.
  • message_text (str) – The body of the message.
search(**kwargs)[source]

Call SearchFetchable() to get a Fetchable object that will lazily perform okcupid searches to provide Profile objects matching the search criteria.

Defaults for gender, gentation, location and radius will be provided if none are given.

Parameters:kwargs – See the SearchFetchable() docstring for details about what parameters are available.
delete_threads(thread_ids_or_threads)[source]

Call delete_threads().

Parameters:thread_ids_or_threads – A list whose members are either MessageThread instances or okc_ids of message threads.
get_user_question(question, fast=False, bust_questions_cache=False)[source]

Get a UserQuestion corresponding to the given Question.

HUGE CAVEATS: If the logged in user has not answered the relevant question, it will automatically be answered with whatever the first answer to the question is.

For the sake of reducing the number of requests made when this function is called repeatedly this function does not bust the cache of this User‘s okcupyd.profile.Profile.questions attribute. That means that a question that HAS been answered could still be answered by this function if this User‘s questions was populated previously (This population happens automatically – See Fetchable for details about when and how this happens).

Parameters:
  • question (BaseQuestion) – The question for which a UserQuestion should be retrieved.
  • fast (bool) – Don’t try to look through the users existing questions to see if arbitrarily answering the question can be avoided.
  • bust_questions_cache (bool) – clear the questions attribute of this users Profile before looking for an existing answer. Be aware that even this does not eliminate all race conditions.
get_question_answer_id(question, fast=False, bust_questions_cache=False)[source]

Get the index of the answer that was given to question

See the documentation for get_user_question() for important caveats about the use of this function.

Parameters:
  • question (BaseQuestion) – The question whose answer_id should be retrieved.
  • fast (bool) – Don’t try to look through the users existing questions to see if arbitrarily answering the question can be avoided.
  • bust_questions_cache (bool) –
    param bust_questions_cache:
     clear the

    questions attribute of this users Profile before looking for an existing answer. Be aware that even this does not eliminate all race conditions.

quickmatch()[source]

Return a Profile obtained by visiting the quickmatch page.

copy(profile_or_user)[source]

Create a Copy instance with the provided object as the source and this User as the destination.

Parameters:profile_or_user – A User or Profile object.

xpath Module

class okcupyd.xpath.XPathBuilder(nodes=(), relative=True, direct_child=False)[source]

Bases: object

xpath[source]
or_[source]
text_[source]
add_node(**kwargs)[source]
update_final_node(updated_final_node)[source]
attribute_contains(attribute, contains_string)[source]
with_classes(*classes)[source]
select_attribute_(attribute, elem=None)[source]
text_contains_(contained_text)[source]
with_class(*classes)
apply_(tree)[source]
one_(tree)[source]
get_text_(tree)[source]
class okcupyd.xpath.XPathNode(element='*', attributes=None, predicates=None, direct_child=False, use_or=False, selected_attribute=None)[source]

Bases: object

text = <object object at 0x7f8cbadf5c30>
static contains_class(class_attribute, contained_class)[source]
static contains_attribute(attribute, contained_string)[source]
static attribute_equal(attribute, value)[source]
make_or[source]
separator[source]
xpath[source]
predicate_joiner[source]
predicate_string[source]
selected_attribute_string[source]
with_classes(classes)[source]
add_contains_predicates(kv_pairs)[source]
text_contains(contained_text)[source]
okcupyd.xpath.xpb