def login(real_user=None): if real_user is None: real_user = REAL_DEFAULT global rate_limiter try: test = rate_limiter.rate_limit except NameError: rate_limiter = RateLimiter(RATE_LIMIT) if real_user: return User(Session.login(REAL_USERNAME, REAL_PASSWORD, rate_limit=rate_limiter)) else: return User(Session.login(SHADOW_USERNAME, SHADOW_PASSWORD, rate_limit=rate_limiter))
def test_location_filter(): session = Session.login() location_cache = LocationQueryCache(session) location = 'Portland, OR' search_fetchable = SearchFetchable(location=location, location_cache=location_cache, radius=1) for profile in search_fetchable[:5]: assert profile.location == 'Portland, OR'
def login(self, username, password): """Logs into OKC, maintaining a session through which we can access data.""" try: self.session = Session.login(username, password) self.username = username except Exception as e: print 'Error logging in:', e
def test_attractiveness_filter(): session = Session.login() profile = SearchFetchable(session, attractiveness_min=4000, attractiveness_max=6000, count=1)[0] assert profile.attractiveness > 4000 assert profile.attractiveness < 6000
def test_language_filter(): session = Session.login() profile = SearchFetchable(session, language='french', count=1)[0] assert 'french' in [language_info[0].lower() for language_info in profile.details.languages] profile = SearchFetchable(session, language='Afrikaans', count=1)[0] assert 'afrikaans' in map(operator.itemgetter(0), profile.details.languages)
def login(self, username, password): """Logs into OKC, maintaining a session through which we can access data.""" try: self.session = Session.login(username, password) self.username = username print 'Connected successfully to OKCupid as user \"' + username + '\".' except Exception as e: print 'Error logging in:', e
def send(username, password, recipient_list, message): """If logged in, sends a message to a list of recipients""" session = Session.login(username, password) user = User(session=session) for recipient in recipient_list: user.message(username=recipient, message_text=message) return "success"
def test_pets_queries(): session = Session.login() profile = SearchFetchable(session, cats=['dislikes cats', 'likes cats'], count=1)[0] assert 'likes cats' in profile.details.pets.lower() profile = SearchFetchable(session, dogs='likes dogs', cats='has cats', count=1)[0] assert 'likes dogs' in profile.details.pets.lower() assert 'has cats' in profile.details.pets.lower()
def test_children_filter(): session = Session.login() profile = SearchFetchable(session, wants_kids="wants kids", count=1)[0] assert "wants" in profile.details.children.lower() profile = SearchFetchable(session, has_kids=["has kids"], wants_kids="doesn't want kids", count=0)[0] assert "has kids" in profile.details.children.lower() assert "doesn't want" in profile.details.children.lower()
def test_language_filter(): session = Session.login() profile = SearchFetchable(session, language='french', count=1)[0] assert 'french' in [ language_info[0].lower() for language_info in profile.details.languages ] profile = SearchFetchable(session, language='Afrikaans', count=1)[0] assert 'afrikaans' in map(operator.itemgetter(0), profile.details.languages)
def is_signed_in(screenname, password): """ Returns boolean that evalutes if OkCupid credentials are valid """ try: session = Session.login(screenname, password) user = User(session=session) except Exception as e: print (e) return "False" return "True"
def add_to_profile_json(): """ Adds Markov Chain self-summary to OkCupid profile """ text = request.form.get("text") screenname = session["screenname"] password = session["password"] session_ = Session.login(screenname, password) user = User(session=session_) user.profile.essays.self_summary = text return "success"
def test_height_filter(): session = Session.login() profile = SearchFetchable(session, height_min='5\'6"', height_max='5\'6"', gentation='girls who like guys', radius=25, count=1)[0] match = magicnumbers.imperial_re.search(profile.details.height) assert int(match.group(1)) == 5 assert int(match.group(2)) == 6 profile = SearchFetchable(session, height_min='2.00m', count=1)[0] match = magicnumbers.metric_re.search(profile.details.height) assert float(match.group(1)) >= 2.00 profile = SearchFetchable(session, height_max='1.5m', count=1)[0] match = magicnumbers.metric_re.search(profile.details.height) assert float(match.group(1)) <= 1.5
def test_easy_search_filters(): session = Session.login() query_test_pairs = [# ('bodytype', maps.bodytype), # TODO(@IvanMalison) this is an alist feature, # so it can't be tested for now. ('drugs', maps.drugs), ('smokes', maps.smokes), ('diet', maps.diet,), ('job', maps.job)] for query_param, re_map in query_test_pairs: for value in sorted(re_map.pattern_to_value.keys()): profile = SearchFetchable(**{ 'gentation': '', 'session': session, 'count': 1, query_param: value })[0] attribute = getattr(profile.details, query_param) assert value in (attribute or '').lower()
def send_message(screenname, password, minimum_age, maximum_age, location, radius, gentation, message, num): """ If logged in, sends to users on OkCupid that meet given parameters Returns a statement if no users could be found that match the given parameters """ session = Session.login(screenname, password) user = User(session=session) try: for profile in user.search(minimum_age=minimum_age, maximum_age=maximum_age, location=location, radius=radius, gentation=gentation)[:num]: # for profile in user.search(minimum_age=minimum_age, maximum_age=maximum_age)[:num]: profile.message(message) except Exception as e: print type(e) return "I couldn't find anyone with those specifications"
def seed_profile_data(): """ Logs user into OkCupid and keeps track of profiles being pulled """ # this must be valid login credentials, NOT 'username' and 'password' session = Session.login('username', 'password') locations = db.session.query(Zipcode.zipcodes).all() print locations user = User(session=session) print user for location in locations: i = 0 # this searches for up to 10,000 profiles a location while i < 10000: search_profile(user, location[0], i) # can query for up to 900 profiles at a time; more will error out the program i += 900
def test_easy_search_filters(): session = Session.login() query_test_pairs = [ # ('bodytype', maps.bodytype), # TODO(@IvanMalison) this is an alist feature, # so it can't be tested for now. ('drugs', maps.drugs), ('smokes', maps.smokes), ( 'diet', maps.diet, ), ('job', maps.job) ] for query_param, re_map in query_test_pairs: for value in sorted(re_map.pattern_to_value.keys()): profile = SearchFetchable( **{ 'gentation': '', 'session': session, 'count': 1, query_param: value })[0] attribute = getattr(profile.details, query_param) assert value in (attribute or '').lower()
def test_session_success(): Session.login()
def test_session_auth_failure(): with pytest.raises(AuthenticationError): Session.login(password='******')
def test_session_unicode(): Session.login(username='******', password='******')
import numpy.random import time import pickle # Read in known profiles to skip path = "C:\\Users\\Ben\\Desktop\\okcstuff\\python\\" readprof = open(path+'unames.pkl','rb') markedunames = pickle.load(readprof) readprof.close() #from okcupyd.json_search import SearchFetchable username = '' password = '' session = Session.login(username, password) user = okcupyd.User(session) # Get match profiles profiles = user.search(age_min=25, age_max=41) output = open('data.pkl', 'wb') # Lists for profile info usernames = [] userids = [] answeredquestions = [] myanswermatches = [] answers = [] # Hash tables for questions
def test_session_auth_failure(): with pytest.raises(AuthenticationError): Session.login(password="******")
def test_session_unicode(): Session.login(username="******", password="******")
def session(): with util.use_cassette(cassette_name='session_success'): return Session.login()