Example #1
0
def record_reactions():
    """
    用于记录交互行为
    :return:
    """
    try:
        user_id = request.args['openid']
        media_id = request.args['media_id']
        thumb_id = request.args['thumb_id']
        article_id = hashlib.md5(media_id + thumb_id).hexdigest()
        article = DAO_utils.mongo_get_article(article_id)
        redirect_url = article.a_url
        # if code:
        #     token_url = 'https://api.weixin.qq.com/sns/oauth2/access_token'
        #     raw_auth_result = requests.get(token_url, {'appid': APPID, 'secret': SECRET, 'code': code})
        #     auth_result = json.loads(raw_auth_result)
        #     user_id = auth_result.get('openid')
        reaction_id = hashlib.md5(user_id + article_id + str(time.time())).hexdigest()
        reaction = Reaction(reaction_id=reaction_id, reaction_type='read', reaction_a_id=article_id,
                            reaction_user_id=user_id,
                            reaction_date=datetime.datetime.utcnow())
        # todo db连接是否需要长期保持?
        DAO_utils.mongo_insert_reactions(reaction)
        # else:
        #     print 'user did not agree to auth'
        return redirect(redirect_url)
    except Exception, e:
        print e
        return make_response(json.dumps({'code': 1, 'msg': str(e)}), 500)
Example #2
0
def get_article(article_id):
    """
    根据文章id获取文章信息
    :return:
    """
    try:
        # params = request.args
        # article_id = params['article_id']
        inst_article = DAO_utils.mongo_get_article(article_id)
        json_article = inst_article.get_json_object()
        resp = make_response(json.dumps({'code': 0, 'article': json_article}), 200)
    except KeyError, ke:
        print ke
        resp = make_response(
            json.dumps({'code': 103,
                        'msg': 'request key error, details=%s' % str(ke)}), 500)