Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove unused file / fix name / add comment #97

Merged
merged 4 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix-etst
  • Loading branch information
chyroc committed Jul 27, 2017
commit aa85e529e0730f53be3901c2aaac92a64dc2146c
2 changes: 1 addition & 1 deletion test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def test_search_gzh(self):
'专业中高考教育',
'晟嘉高考',
'新东方在线高考辅导'],
[i['name'] for i in gzh_list])
[i['wechat_name'] for i in gzh_list])

@unittest.skip
def test_search_gzh_error(self):
Expand Down
16 changes: 8 additions & 8 deletions test/test_api_structuring.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def test_get_gzh_by_search(self):
authentications = []
assert_equal(10, len(gzh_list))
for gzh in gzh_list:
names.append(gzh['name'])
names.append(gzh['wechat_name'])
wechat_ids.append(gzh['wechat_id'])
post_perms.append(gzh['post_perm'])
introductions.append(gzh['introduction'])
authentications.append(gzh['authentication'])

assert_in('mp.weixin.qq.com/profile?src=3&timestamp=', gzh['url'])
assert_in('mp.weixin.qq.com/profile?src=3&timestamp=', gzh['profile_url'])
assert_in('mp.weixin.qq.com/rr?src=', gzh['qrcode'])
assert_in('img01.sogoucdn.com/', gzh['img'])
assert_in('img01.sogoucdn.com/', gzh['headimage'])

assert_equal(['山东高考指南',
'高考家长圈',
Expand Down Expand Up @@ -110,9 +110,9 @@ def test_get_article_by_search(self):

gzh = i['gzh']

assert_in('mp.weixin.qq.com/profile?src=3&timestamp', gzh['article_list_url'])
assert_in('mp.weixin.qq.com/profile?src=3&timestamp', gzh['profile_url'])
assert_in('wx.qlogo.cn/mmhead', gzh['headimage'])
gzh_names.append(gzh['name'])
gzh_names.append(gzh['wechat_name'])
isvs.append(gzh['isv'])

# article
Expand Down Expand Up @@ -163,10 +163,10 @@ def test_get_gzh_info_by_history(self):

assert_equal('槽边往事', gzh_info['name'])
assert_equal('bitsea', gzh_info['wechat_id'])
assert_equal('和菜头的微信Blog,用于分享各种新鲜资讯', gzh_info['principal'])
assert_equal('和菜头的微信Blog,用于分享各种新鲜资讯', gzh_info['authentication'])
assert_equal('http://wx.qlogo.cn/mmhead/Q3auHgzwzM6zmSwQkvHdgXDtnpAyLYjuib8QdW6ibKKGo8zcZVbYxiaUw/0',
gzh_info['img'])
assert_equal(' ', gzh_info['desc'])
gzh_info['headimage'])
assert_equal(' ', gzh_info['introduction'])

def test_get_article_by_history_json(self):
file_name = '{}/{}/{}'.format(os.getcwd(), fake_data_path, 'bitsea-history.html')
Expand Down
18 changes: 9 additions & 9 deletions wechatsogou/structuring.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ def get_gzh_by_search(text):
list[dict]
{
'profile_url': '', # 最近10条群发页链接
'img': '', # 头像
'name': '', # 名称
'headimage': '', # 头像
'wechat_name': '', # 名称
'wechat_id': '', # 微信id
'post_perm': '', # 最近一月群发数
'qrcode': '', # 二维码
Expand All @@ -41,17 +41,17 @@ def get_gzh_by_search(text):
relist = []
for li in lis:
url = li.xpath('div/div[1]/a/@href')
img = li.xpath('div/div[1]/a/img/@src')
name = get_elem_text(li.xpath('div/div[2]/p[1]')[0])
headimage = li.xpath('div/div[1]/a/img/@src')
wechat_name = get_elem_text(li.xpath('div/div[2]/p[1]')[0])
info = get_elem_text(li.xpath('div/div[2]/p[2]')[0])
post_perm = 0 # TODO 月发文 <script>var account_anti_url = "/websearch/weixin/pc/anti_account.jsp?.......";</script>
qrcode = li.xpath('div/div[3]/span/img[1]/@src')
introduction = get_elem_text(li.xpath('dl[1]/dd')[0])
authentication = li.xpath('dl[2]/dd/text()')
relist.append({
'profile_url': url[0],
'img': img[0],
'name': name.replace('red_beg', '').replace('red_end', ''),
'headimage': headimage[0],
'wechat_name': wechat_name.replace('red_beg', '').replace('red_end', ''),
'wechat_id': info.replace('微信号:', ''),
'post_perm': post_perm,
'qrcode': qrcode[0] if qrcode else '',
Expand Down Expand Up @@ -126,7 +126,7 @@ def get_article_by_search(text):
time = re.findall('timeConvert\(\'(.*?)\'\)', time)
time = list_or_empty(time, int)
profile_url = gzh_info.xpath('@href')
gzh_headimage = gzh_info.xpath('@data-headimage')
headimage = gzh_info.xpath('@data-headimage')
wechat_name = gzh_info.xpath('text()')
gzh_isv = gzh_info.xpath('@data-isv')

Expand All @@ -140,7 +140,7 @@ def get_article_by_search(text):
},
'gzh': {
'profile_url': list_or_empty(profile_url),
'headimage': list_or_empty((gzh_headimage)),
'headimage': list_or_empty(headimage),
'wechat_name': list_or_empty(wechat_name),
'isv': list_or_empty(gzh_isv, int),
}
Expand Down Expand Up @@ -182,7 +182,7 @@ def get_gzh_info_by_history(text):
'wechat_id': profile_wechat_id[0].replace('微信号: ', '').strip('\n'),
'introduction': profile_desc[0],
'authentication': profile_principal[0],
'img': profile_img[0]
'headimage': profile_img[0]
}

@staticmethod
Expand Down