def getprofile(self, params): """Retrieve user profile and send it to the server.""" log = logging.getLogger("GETPROFILE") # The only parameter we get is the user name username = params # Download search result pages log.info("BEGIN %s", params) try: profile, friends = get_user_encoded_profile(username) log.info("GOT PROFILE FOR USER %s", username) # Setup form and headers # Although we used "upload" code, this is a plain POST upload_headers = dict(self.headers) form_data = {'username' : username, 'profile' : profile, 'friends-list' : FINDUSERS_SEPARATOR.join(friends), 'friends-list-count' : str(len(friends)), 'client-id' : self.id} # Upload the article log.info("UPLOADING TO SERVER %s", params) upload_url = self.base_url + '/getprofile/' + username response = upload_aux.upload_form(upload_url, form_data, upload_headers) except PageNotFound: response = self.report_not_found_user(username, log) log.info("END %s", params) # Ok. Command, handled. Now what? # Do what the server told us to. # Command MUST be SLEEP. We will sleep for at least self.MIN_SLEEP command = response.read() self._handleCommand(command, do_sleep=True)
def findusers(self, params): """Retrieve pages from the users search and send it to the server.""" # Retrieve the search gender (male, female) and search page gender, page_num = params[0], int(params[1:]) assert gender in FINDUSERS_VALID_GENDERS # Download search result pages logging.info("FINDUSERS %s BEGIN", params) retriever = FindUsersRetriver() found_users = retriever.get_users_from_pages(gender, page_num) logging.info("FINDUSERS %s GOT FINDUSERS DATA", params) # Setup form and headers # Although we used "upload" code, this is a plain POST upload_headers = dict(self.headers) form_data = {'page-id' : params, 'page-users' : FINDUSERS_SEPARATOR.join(found_users), 'page-users-count' : str(len(found_users)), 'client-id' : self.id} # Upload the article upload_url = self.base_url + '/findusers/' + params response = upload_aux.upload_form(upload_url, form_data, upload_headers) logging.info("FINDUSERS %s END", params) # Ok. Command, handled. Now what? # Do what the server told us to. # Command MUST be SLEEP. We will sleep for at least self.MIN_SLEEP command = response.read() self._handleCommand(command, do_sleep=True)