本文整理汇总了Python中article.Article.get方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get方法的具体用法?Python Article.get怎么用?Python Article.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类article.Article
的用法示例。
在下文中一共展示了Article.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_sentiments
# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import get [as 别名]
def update_sentiments(self):
from watson_developer_cloud import ToneAnalyzerV3Beta
tone_analyzer = ToneAnalyzerV3Beta(username='03774a07-f588-4619-8801-506d251f384b',
password='kkxjxbSSypDJ',
version='2016-02-11')
client = connections.get_connection()
search = Search(using=client, index='articles', doc_type='article')
q = Q('bool', must=[Q('missing', field='watson_analyzed')])
search = search.query(q)
counter = 0
for result in search.scan():
doc = Article.get(result.meta.id)
try:
analysis = tone_analyzer.tone(text=doc.body)
tone_categories = analysis['document_tone']['tone_categories']
emotion_tones = list(filter(lambda x: x['category_id'] == 'emotion_tone', tone_categories))[0]
doc.tone = {}
for tone in emotion_tones['tones']:
doc.tone[tone['tone_id']] = tone['score']
doc.watson_success = True
except WatsonException:
continue
finally:
doc.watson_analyzed = True
doc.save()
counter += 1
print(counter)
if counter == 0:
raise RealError()
示例2: __init__
# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import get [as 别名]
def __init__(self, user_id, article_id):
self.user_id = user_id
es = ElasticStorage.get_instance(dev=False)
doc = ESArticle.get(article_id)
self.anger = doc.tone.anger
self.disgust = doc.tone.disgust
self.fear = doc.tone.fear
self.joy = doc.tone.anger
self.sadness = doc.tone.anger
self.total_articles = 1
示例3: post
# 需要导入模块: from article import Article [as 别名]
# 或者: from article.Article import get [as 别名]
def post(self):
user_id = json.loads(request.data.decode('utf-8'))['user_id']
article_id = json.loads(request.data.decode('utf-8'))['article_id']
user = Users.query.filter_by(user_id=user_id).first()
if user:
es = ElasticStorage.get_instance(dev=False)
doc = ESArticle.get(article_id)
user.anger += doc.tone.anger
user.disgust += doc.tone.disgust
user.fear += doc.tone.fear
user.joy += doc.tone.anger
user.sadness += doc.tone.anger
user.total_articles += 1
else:
u = Users(user_id, article_id)
db.session.add(u)
db.session.commit()
return ('', 204)