Adding rating support for OKC browser and PROFILE_WALKER optimizer
This commit is contained in:
parent
720fd5ba1a
commit
16477b4649
3 changed files with 57 additions and 1 deletions
|
|
@ -261,4 +261,14 @@ class OkCBrowser(BaseBrowser):
|
|||
self.open('http://m.okcupid.com/profile', data=data)
|
||||
return True
|
||||
|
||||
@check_login
|
||||
def do_rate(self, id):
|
||||
# Need to be in quickmatch page
|
||||
abs_url, rating,params = self.page.get_rating_params()
|
||||
# print abs_url, rating, params
|
||||
data = urllib.urlencode(params)
|
||||
self.addheaders = [('Referer', self.page.url), ('Content-Type', 'application/x-www-form-urlencoded;charset=UTF-8')]
|
||||
self.open('http://m.okcupid.com%s' %abs_url, data=data)
|
||||
return True
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -81,6 +81,7 @@ class ProfilesWalker(Optimization):
|
|||
try:
|
||||
with self.browser:
|
||||
# profile = self.browser.get_profile(id)
|
||||
self.browser.do_rate(id)
|
||||
self.browser.visit_profile(id)
|
||||
self.logger.info(u'Visited profile %s ' % (id))
|
||||
|
||||
|
|
|
|||
|
|
@ -210,4 +210,49 @@ class QuickMatchPage(BasePage):
|
|||
element = self.parser.select(self.document.getroot(), '//*[@id="sn"]', method='xpath')[0]
|
||||
visitor_id = unicode(element.get('value'))
|
||||
return visitor_id
|
||||
|
||||
|
||||
def get_rating_params(self):
|
||||
# initialization
|
||||
userid = None
|
||||
tuid = None
|
||||
|
||||
# looking for CURRENTUSERID
|
||||
js = self.parser.select(self.document.getroot(), "//script", method='xpath')
|
||||
for script in js:
|
||||
script = script.text
|
||||
|
||||
if script is None:
|
||||
continue
|
||||
for line in script.splitlines():
|
||||
match = re.match('.*var\s*CURRENTUSERID\s*=\s*"(\d+)"', line)
|
||||
if match is not None:
|
||||
(userid,) = match.groups()
|
||||
|
||||
# Looking for target userid (tuid)
|
||||
element = self.parser.select(self.document.getroot(), '//*[@id="star_5_top"]', method='xpath')[0]
|
||||
onclick = element.get("onclick")
|
||||
|
||||
if onclick is None:
|
||||
pass
|
||||
for line in onclick.splitlines():
|
||||
match = re.match("^Quickmatch\.vote\(\d,\s*'(\w*)'*", line)
|
||||
if match is not None:
|
||||
(tuid,) = match.groups()
|
||||
|
||||
# Building params hash
|
||||
if userid and tuid:
|
||||
params = {
|
||||
'voterid': userid,
|
||||
'target_userid': tuid,
|
||||
'target_objectid': 0,
|
||||
'type': 'vote',
|
||||
'vote_type': 'personality',
|
||||
'score': 5,
|
||||
}
|
||||
return '/vote_handler', 1,params
|
||||
else:
|
||||
raise Exception('Unexpected reply page')
|
||||
|
||||
|
||||
# VoteHandler.process('vote', 'personality', stars, tuid, pass.succeed, pass.failure);
|
||||
# var params = {voterid: CURRENTUSERID,target_userid: tuid,target_objectid: 0,type: vote_or_note,vote_type: vote_type,score: rating}
|
||||
Loading…
Add table
Add a link
Reference in a new issue