Exemple #1
0
    def visit(self, username, update_pics=False):
        """Visit another user's profile. Automatically update the
        `essays`, `details`, and `looking_for` attributes of the
        visited profile. Accept either a string or a Profile object as
        an argument. Note that unless your profile is set to browse
        anonymously on OKCupid, you are likely to show up on this
        user's visitors list.
        Parameters
        ---------
        username : str, Profile
            Username of the profile to visit. Can be either a string or a
            Profile object.
        update_pics : Bool
            Determines whether or not update_pics() is automatically
            called for this profile.
        Returns
        ---------
        Profile
            An instance of Profile containing the visited user's
            information.
        """
        if isinstance(username, Profile):
            prfl = username
        else: # string
            prfl = Profile(self._session, username)
        params = {
            'cf': 'leftbar_match',
            'leftbar_match': 1,
            }
        profile_request = self._session.post('http://www.okcupid.com/profile/{0}'.format(prfl.name), data=params)

        try:
            profile_tree = html.fromstring(profile_request.content.decode('utf8'))
        except ParserError:
            # lxml is unable to parse some profiles
            # TODO: consider stripping it beforehand
            return None

        prfl.match, prfl.enemy = helpers.get_percentages(profile_tree)
        prfl.age, prfl.gender, prfl.orientation, prfl.status = helpers.get_additional_info(profile_tree)
        if len(profile_tree.xpath("//div[@id = 'rating']")):
            prfl.rating = helpers.get_rating(profile_tree.xpath("//div[@id = 'rating']")[0])
        elif len(profile_tree.xpath("//button[@class = 'flatbutton white binary_rating_button like liked']")):
           prfl.rating = 5
        helpers.update_essays(profile_tree, prfl.essays)
        helpers.update_looking_for(profile_tree, prfl.looking_for)
        helpers.update_details(profile_tree, prfl.details)
        # If update_pics is False, you will need to call Profile.update_pics()
        # manually if you wish to access urls in this profile's pics attribute,
        # however this method will be approximately 3 seconds quicker because
        # it makes only 1 request instead of 2.
        if update_pics:
            prfl.update_pics()
        if prfl._id is None:
            prfl._id = helpers.get_profile_id(profile_tree)
        return prfl
Exemple #2
0
 def __init__(self, username, password):
     self.username = username
     self.inbox = []
     self.outbox = []
     self.drafts = []
     self.questions = []
     self.visitors = []
     self._session = Session()
     credentials = {'username': username, 'password': password, 'dest': '/home'}
     helpers.login(self._session, credentials)
     self.age, self.orientation, self.status, self.gender = helpers.get_additional_info(self._session)
     self.update_mailbox(pages=1)
     self.update_visitors()
Exemple #3
0
 def visit(self, username, update_pics=False):
     """Visit another user's profile. Automatically update the
     `essays`, `details`, and `looking_for` attributes of the
     visited profile. Accept either a string or a Profile object as
     an argument. Note that unless your profile is set to browse
     anonymously on OKCupid, you are likely to show up on this
     user's visitors list.
     Parameters
     ---------
     username : str, Profile
         Username of the profile to visit. Can be either a string or a
         Profile object.
     update_pics : Bool
         Determines whether or not update_pics() is automatically
         called for this profile.
     Returns
     ---------
     Profile
         An instance of Profile containing the visited user's
         information.
     """
     if isinstance(username, Profile):
         prfl = username
     else: # string
         prfl = Profile(self._session, username)
     params = {
         'cf': 'leftbar_match',
         'leftbar_match': 1,
         }
     profile_request = self._session.post('http://www.okcupid.com/profile/{0}'.format(prfl.name), data=params)
     profile_tree = html.fromstring(profile_request.content.decode('utf8'))
     prfl.match, prfl.enemy = helpers.get_percentages(profile_tree)
     prfl.age, prfl.gender, prfl.orientation, prfl.status = helpers.get_additional_info(profile_tree)
     if len(profile_tree.xpath("//div[@id = 'rating']")):
         prfl.rating = helpers.get_rating(profile_tree.xpath("//div[@id = 'rating']")[0])
     elif len(profile_tree.xpath("//button[@class = 'flatbutton white binary_rating_button like liked']")):
        prfl.rating = 5
     helpers.update_essays(profile_tree, prfl.essays)
     helpers.update_looking_for(profile_tree, prfl.looking_for)
     helpers.update_details(profile_tree, prfl.details)
     # If update_pics is False, you will need to call Profile.update_pics()
     # manually if you wish to access urls in this profile's pics attribute,
     # however this method will be approximately 3 seconds quicker because
     # it makes only 1 request instead of 2.
     if update_pics:
         prfl.update_pics()
     if prfl._id is None:
         prfl._id = helpers.get_profile_id(profile_tree)
     return prfl
Exemple #4
0
 def __init__(self, username=USERNAME, password=PASSWORD):
     self.username = username
     self.inbox = []
     self.outbox = []
     self.drafts = []
     self.questions = []
     self.visitors = []
     self._session = Session()
     credentials = {'username': username, 'password': password, 'dest': '/home'}
     helpers.login(self._session, credentials)
     profile_response = self._session.get('https://www.okcupid.com/profile')
     profile_tree = html.fromstring(profile_response.content.decode('utf8'))
     self.age, self.gender, self.orientation, self.status = helpers.get_additional_info(profile_tree)
     self.update_mailbox(pages=1)
     self.update_visitors()
Exemple #5
0
 def __init__(self, username=USERNAME, password=PASSWORD):
     self.username = username
     self.inbox = []
     self.outbox = []
     self.drafts = []
     self.questions = []
     self.visitors = []
     self._session = Session()
     headers = {
         'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36'
     }
     credentials = {'username': username, 'password': password}
     helpers.login(self._session, credentials, headers)
     profile_response = self._session.get('https://www.okcupid.com/profile')
     profile_tree = html.fromstring(profile_response.content.decode('utf8'))
     self.age, self.gender, self.orientation, self.status = helpers.get_additional_info(profile_tree)
     self.update_mailbox(pages=1)
     self.update_visitors()
Exemple #6
0
 def __init__(self, username, password):
     self.username = username
     self.inbox = []
     self.outbox = []
     self.drafts = []
     self.questions = []
     self.visitors = []
     self._session = Session()
     credentials = {
         'username': username,
         'password': password,
         'dest': '/home'
     }
     helpers.login(self._session, credentials)
     self.age, self.orientation, self.status, self.gender = helpers.get_additional_info(
         self._session)
     self.update_mailbox(pages=1)
     self.update_visitors()