当前位置: 首页>>代码示例>>Python>>正文


Python Profile.populate方法代码示例

本文整理汇总了Python中models.Profile.populate方法的典型用法代码示例。如果您正苦于以下问题:Python Profile.populate方法的具体用法?Python Profile.populate怎么用?Python Profile.populate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Profile的用法示例。


在下文中一共展示了Profile.populate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_user_data

# 需要导入模块: from models import Profile [as 别名]
# 或者: from models.Profile import populate [as 别名]

#.........这里部分代码省略.........
      visitors = [user.key],
      visitor_count = 1)
    #logging.info('got the basic info')
    # Get extra photos
    res = br.follow_link(url_regex=r'/photos')
    #logging.info('followed link')
    soup = BeautifulSoup(res.read().decode('utf-8'))

    # Detect if it's an album page and build new soup
    if len(soup.find_all('div', {'class': 'photo'})) == 0:
      res = br.open(ROOT_URL + userId + '/photos#0')
      soup = BeautifulSoup(res.read().decode('utf-8'))

    for item in soup.find_all('div', {'class': 'photo'}):
      img = item.find('div', {'class': 'img'}).find('img')['src']
      if item.find('p', {'class': 'text'}) is not None:
        caption = item.find('p', {'class': 'text'}).text
      else:
        caption = ''
      img_more.append(img)
      img_more_captions.append(caption)

    user_data.img_more = img_more
    user_data.img_more_captions = img_more_captions

    #logging.info('entity created')
  
  # If this profile is new to this user
  elif user.key not in user_data.visitors:

    # Get the last online time
    if soup.find('span', {'class': 'fancydate'}) != None:
      last_online = soup.find('span', {'class': 'fancydate'}).text
    else:
      last_online = 'Online now!'

    user_data.populate(
      img = unicode(soup.find(id='thumb0_a').find('img')['src']),
      match = unicode(soup.find('span', {'class': 'match'}).text.split('%')[0]),
      friend = unicode(soup.find('span', {'class': 'friend'}).text.split('%')[0]),
      enemy = unicode(soup.find('span', {'class': 'enemy'}).text.split('%')[0]),
      age = unicode(soup.find(id='ajax_age').text),
      gender = unicode(soup.find(id='ajax_gender').text),
      orientation = unicode(soup.find(id='ajax_orientation').text),
      status = unicode(soup.find(id='ajax_status').text),
      location = unicode(soup.find(id='ajax_location').text),
      ethnicity = unicode(soup.find(id='ajax_ethnicities').text),
      height = unicode(soup.find(id='ajax_height').text),
      body_type = unicode(soup.find(id='ajax_bodytype').text),
      diet = unicode(soup.find(id='ajax_diet').text),
      smoking = unicode(soup.find(id='ajax_smoking').text),
      drinking = unicode(soup.find(id='ajax_drinking').text),
      drugs = unicode(soup.find(id='ajax_drugs').text),
      religion = unicode(soup.find(id='ajax_religion').text),
      sign = unicode(soup.find(id='ajax_sign').text),
      education = unicode(soup.find(id='ajax_education').text),
      job = unicode(soup.find(id='ajax_job').text),
      income = unicode(soup.find(id='ajax_income').text),
      children = unicode(soup.find(id='ajax_children').text),
      pets = unicode(soup.find(id='ajax_pets').text),
      languages = unicode(soup.find(id='ajax_languages').text),
      last_online = unicode(last_online),
      essay_text_0 = unicode(soup.find(id='essay_text_0')),
      essay_text_1 = unicode(soup.find(id='essay_text_1')),
      essay_text_2 = unicode(soup.find(id='essay_text_2')),
      essay_text_3 = unicode(soup.find(id='essay_text_3')),
      essay_text_4 = unicode(soup.find(id='essay_text_4')),
      essay_text_5 = unicode(soup.find(id='essay_text_5')),
      essay_text_6 = unicode(soup.find(id='essay_text_6')),
      essay_text_7 = unicode(soup.find(id='essay_text_7')),
      essay_text_8 = unicode(soup.find(id='essay_text_8')),
      essay_text_9 = unicode(soup.find(id='essay_text_9')),
      what_i_want = unicode(soup.find(id='what_i_want')))
    user_data.visitors.append(user.key)
    user_data.visitor_count += 1

    # Get extra photos
    res = br.follow_link(url_regex=r'/photos')
    #logging.info('followed link')
    soup = BeautifulSoup(res.read().decode('utf-8'))

    # Detect if it's an album page and build new soup
    if len(soup.find_all('div', {'class': 'photo'})) == 0:
      res = br.open(ROOT_URL + userId + '/photos#0')
      soup = BeautifulSoup(res.read().decode('utf-8'))

    for item in soup.find_all('div', {'class': 'photo'}):
      img = item.find('div', {'class': 'img'}).find('img')['src']
      if item.find('p', {'class': 'text'}) is not None:
        caption = item.find('p', {'class': 'text'}).text
      else:
        caption = ''
      img_more.append(img)
      img_more_captions.append(caption)

    user_data.img_more = img_more
    user_data.img_more_captions = img_more_captions

  user.profiles_visited_counter += 1
  ndb.put_multi([user, user_data])
开发者ID:robertdo,项目名称:cupid-crawler,代码行数:104,代码来源:browser.py


注:本文中的models.Profile.populate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。