def vote_already_exists(username, article_url):
'''
Check if the user with the given username
has already voted on the specified article.
Returns True or False
'''
req_data = bson.BSON.encode({
"key": key,
"database": "feedlark",
"collection": "vote",
"query": {
"$and": [{
"article_url": article_url,
},{
"username": username
}
]
},
"projection": {}
})
get_response = gearman_client.submit_job('db-get', str(req_data))
result = bson.BSON(get_response.result).decode()
if result['status'] != 'ok':
log(2, 'Error getting votes for user {} for article {}'.format(username, article_url))
return False
return 'docs' in result and len(result['docs']) > 0
评论列表
文章目录