Skip to content

Commit

Permalink
增加分数计算
Browse files Browse the repository at this point in the history
  • Loading branch information
高金 committed Feb 10, 2017
1 parent 79792da commit 56962c2
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
19 changes: 13 additions & 6 deletions lundaig.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import re
import random
import logging
import requests
from lxml import etree
import base64
Expand Down Expand Up @@ -58,8 +59,10 @@ def getimgsrc(offset,topic_id):
images = etree.HTML(contents[i]).xpath('//img/@src')
#如果图片不为0的话,则得到answer-id,点赞会用到
if len(images)!= 0:
xiaobing = []
fs = []
is_sex = False
try:
xiaobing = []
#如果图片大于3张,则随机选3张
if len(images) > 3:
images_ = random.sample(images,3)
Expand All @@ -77,19 +80,23 @@ def getimgsrc(offset,topic_id):
future.exception()))
else:
xiaobing.append(future.result())
# print('%r page is %d bytes' % (url, len(future.result())))
# xiaobing = [checkyanzhi(base64_imgage(image)).process() for image in images]
except:
xiaobing = []
# 获取分数
fs = [re.search(r"\d+\.?\d?",xx['content']['text']).group() for xx in xiaobing if re.search(r"\d+\.?\d?" ,xx['content']['text'])]
if len(fs) != 0:
if float(max(xxxx)) > 7.5:
is_sex = True
except Exception as ex:
logging.exception('yanzhi check error')
answer_id = ll.xpath('//meta[@itemprop="answer-id"]/@content')[i]
title = ll.xpath('//div[@class="feed-content"]/h2/a/text()')[i].strip()
href = ll.xpath('//div[@class="zm-item-rich-text expandable js-collapse-body"]/@data-entry-url')[i]
#时间戳
data_score = ll.xpath('//div[@class="feed-item feed-item-hook folding"]/@data-score')[i]
#存储到数据库
b = zhihudaiguang(imageurl=images,id=answer_id,title=title,href=href,content=contents,
data_score=data_score,xiaobing=xiaobing,topic_id=topic_id)
data_score=data_score,xiaobing=xiaobing,topic_id=topic_id,is_sex=is_sex,fs=fs)
b.save()

#把图片转成 base64
def base64_imgage(url):
ir = s.get(url,headers=HEADERS)
Expand Down
21 changes: 21 additions & 0 deletions mysite/pachong/migrations/0008_zhihudaiguang_fs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2017-02-09 03:03
from __future__ import unicode_literals

import django.contrib.postgres.fields
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('pachong', '0007_zhihudaiguang_is_check'),
]

operations = [
migrations.AddField(
model_name='zhihudaiguang',
name='fs',
field=django.contrib.postgres.fields.ArrayField(base_field=models.TextField(), default=[], size=None),
),
]
1 change: 1 addition & 0 deletions mysite/pachong/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class zhihudaiguang(models.Model):
data_score = models.FloatField()
xiaobing = JSONField(default=list())
topic_id = models.IntegerField(default=0)
fs = ArrayField(models.TextField(),default=[])

class lives(models.Model):
live = JSONField()
Expand Down
5 changes: 4 additions & 1 deletion upupup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# -*- coding: utf-8 -*-
from lundaig import zhihudaiguang,vote_up

import sys
reload(sys)
sys.setdefaultencoding('utf-8')
if __name__ == '__main__':
lists = zhihudaiguang.objects.filter(is_vote_up=0)
for i in lists:

for rate in i.xiaobing:
print rate['content']['text']

0 comments on commit 56962c2

Please sign in to comment.