Exemple #1
0
# Initialize our connections
try:
    # First connect to the database
    mongo = mongoOKC()
    mongo.connect()
except Exception as e:
    print 'Fatal exception, exiting.\n\t', e

db, collection = 'okc', 'samples'
mongo.set_profiles_path( db = db, collection = collection )
print 'Looking in mongodb://.../' + db + '/' + collection + '/'

# Get a list of users that have already been stored
# print mongo.db.command('collstats', 'samples')#, {'scale':1024})
print 'Database stats:'
pretty_print( mongo.stats() )
print ''
# user_list = mongo.get_user_list()
# print 'Database currently holds', len(user_list), 'profiles.'
# u = user_list[0]
# print mongo.find_one( search = {'info.username': u}, filter = None )

def get_ages(mongo):
    return [cursor['info']['age'] for cursor in mongo.find(search = None, filter = {'info.age':1}, limit = False)]

ages = get_ages(mongo)

print mongo.find(search = None, filter = {'info.count':1}, limit = False).count()
print len(ages)
print min(ages), 1.0*sum(ages)/len(ages), max(ages)
Exemple #2
0
# Note: Create a local file called logins.py, and in it define variables username, password, & test_profile.  This file is excluded via our .gitignore, to prevent sensitive data from being published onto GitHub.
import logins

OKC = okc_session.OKC()

# Change the following variable to easily select various test modes for loading a profile
load_type = 'web'

if load_type == 'web':
    # Load directly from www.okcupid.com
    OKC.login(logins.username, logins.password)
    soup, questions, photos = OKC.get_profile(logins.test_profile, get_questions = False, get_photos = False)

elif load_type == 'local':
    # Load from a local HTML file.  Recommend 'local' instead of 'web' as often as possible.
    soup = OKC.get_local_file('test_data/test.html')
    questions = None
    photos = None

elif load_type == 'write':
    # Write a local HTML file.  Probably just need to run this once, so you can use 'local'.
    # Note that the folder 'test_data' is listed in .gitignore, again to prevent sensitive data from being published onto GitHub.
    OKC.login(logins.username, logins.password)
    soup = OKC.get_profile_soup(logins.test_profile)
    OKC.write_local_html(soup, 'test_data/test.html')
    exit()


p = profile.Profile( soup, questions, photos )
pretty_print( p.data )