-
Notifications
You must be signed in to change notification settings - Fork 69
/
hotornot.py
69 lines (52 loc) · 2.04 KB
/
hotornot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import urllib2
import xml.dom.minidom
apikey = '479NUNJHETN'
def getrandomratings(c):
url = 'http://services.hotornot.com/rest/?app_key=%s' % apikey
url += '&method=Rate.getRandomProfile&retrieve_num=%d' % c
url += '&get_rate_info=true&meet_users_only=true'
doc = xml.dom.minidom.parseString(urllib2.urlopen(url).read())
emids = doc.getElementsByTagName('emid')
ratings = doc.getElementsByTagName('rating')
result = []
for e, r in zip(emids, ratings):
if r.firstChild != None:
result.append( (e.firstChild.data, r.firstChild.data) )
return result
stateregions={'New England':['ct','mn','ma','nh','ri','vt'],
'Mid Atlantic':['de','md','nj','ny','pa'],
'South':['al','ak','fl','ga','ky','la','ms','mo',
'nc','sc','tn','va','wv'],
'Midwest':['il','in','ia','ks','mi','ne','nd','oh','sd','wi'],
'West':['ak','ca','co','hi','id','mt','nv','or','ut','wa','wy']}
def getpeopledata(ratings):
result = []
for emid, rating in ratings:
url = 'http://services.hotornot.com/rest/?app_key=%s' % apikey
url += '&method=MeetMe.getProfile&emid=%s&get_keywords=true' % emid
try:
rating = int(float(rating) + 0.5)
doc = xml.dom.minidom.parseString(urllib2.urlopen(url).read())
#print doc.toxml()
gender = doc.getElementsByTagName('gender')[0].firstChild.data
age = doc.getElementsByTagName('age')[0].firstChild.data
loc = doc.getElementsByTagName('location')[0].firstChild.data
region = None
for r, s in stateregions.iteritems():
if loc[0:2] in s: region = r
if region:
result.append( (gender, int(age), region, rating) )
except:
pass
return result
if __name__ == '__main__':
d = getrandomratings(50)
# hu, all results are always of the same gender?
pdata = getpeopledata(d)
print pdata
import drawtree
import treepredict
tree = treepredict.buildtree(pdata, treepredict.variance)
treepredict.prune(tree, 0.5)
drawtree.drawtree(tree, 'hottree.png')
print 'Wrote hottree.png'