예제 #1
0
def upload_news(data):
    req_data = {
        'appid': consts.appid,
        'title': '[每日天文一圖] ' + data['title'],
        'content':
            '<p><strong>%s</strong></p>'
            '<p><strong>%s</strong></p>'
            '<p><br/></p>'
            '<p>%s</p>'
            '<p><br/></p>'
            '<p><strong>资料来自:</strong></p>'
            '<p>%s</p><p>%s</p><p><br/></p>'
            '<p style="color: rgb(37, 79, 130);"><strong>---------------</strong></p>'
            '<p style="color: rgb(54, 96, 146);"><strong>欢迎关注邻家天文馆, 这里有什么好玩的呢?</strong></p>'
            '<p style="color: rgb(71, 113, 162);"><strong>1.从晴天钟获取天气预报</strong></p>'
            '<p style="color: rgb(89, 129, 178);"><strong>2.查询全天88星座</strong></p>'
            '<p style="color: rgb(106, 145, 194);"><strong>3.查询超过3万个深空天体</strong></p>'
            '<p style="color: rgb(124, 162, 210);"><strong>4.解析星空照片</strong></p>'
            '<p style="color: rgb(141, 179, 226);"><strong>如需详细帮助, 请回复对应数字.</strong></p>' % (
                data['author'], data['translate'], data['article'], data['en_url'], data['cn_url']),
        'picurl': data['picurl'], 'source_url': data['cn_url'],
        'digest': data['article'][:100] + '...'}
    security.add_sign(req_data, consts.sitekey)
    resp = httputils.post_dict_sync(url=consts.wechat_news_url, data=req_data)
    if resp.code != 200:
        logging.error('fail to upload material')
        return False
    else:
        resp_data = json.loads(resp.body.decode('utf8'))
        if resp_data['err_code'] != 0:
            logging.error('fail to upload material: %s: %s', resp_data['err_code'], resp_data['err_msg'])
            return False
        else:
            logging.info('finish to upload material')
            return True
예제 #2
0
def send_message(appmsgid):
    data = {'appid': consts.appid, 'appmsgid': appmsgid}
    security.add_sign(data, consts.sitekey)
    resp = httputils.post_dict_sync(url=consts.wechat_multimsgs_url, data=data)
    if resp.code != 200:
        logging.error('fail to send msg')
        return False
    else:
        resp_data = json.loads(resp.body.decode('utf8'))
        if resp_data['err_code'] != 0:
            logging.error('fail to send msg: %s: %s', resp_data['err_code'],
                          resp_data['err_msg'])
            return False
        else:
            logging.info('finish to send msg')
            return True
예제 #3
0
def send_message(appmsgid):
    data = {
        'appid': consts.appid,
        'appmsgid': appmsgid
    }
    security.add_sign(data, consts.sitekey)
    resp = httputils.post_dict_sync(url=consts.wechat_multimsgs_url, data=data)
    if resp.code != 200:
        logging.error('fail to send msg')
        return False
    else:
        resp_data = json.loads(resp.body.decode('utf8'))
        if resp_data['err_code'] != 0:
            logging.error('fail to send msg: %s: %s', resp_data['err_code'], resp_data['err_msg'])
            return False
        else:
            logging.info('finish to send msg')
            return True
예제 #4
0
def upload_news(data):
    req_data = {
        'appid':
        consts.appid,
        'title':
        '[每日天文一圖] ' + data['title'],
        'content':
        '<p><strong>%s</strong></p>'
        '<p><strong>%s</strong></p>'
        '<p><br/></p>'
        '<p>%s</p>'
        '<p><br/></p>'
        '<p><strong>资料来自:</strong></p>'
        '<p>%s</p><p>%s</p><p><br/></p>'
        '<p style="color: rgb(37, 79, 130);"><strong>---------------</strong></p>'
        '<p style="color: rgb(54, 96, 146);"><strong>欢迎关注邻家天文馆, 这里有什么好玩的呢?</strong></p>'
        '<p style="color: rgb(71, 113, 162);"><strong>1.从晴天钟获取天气预报</strong></p>'
        '<p style="color: rgb(89, 129, 178);"><strong>2.查询全天88星座</strong></p>'
        '<p style="color: rgb(106, 145, 194);"><strong>3.查询超过3万个深空天体</strong></p>'
        '<p style="color: rgb(124, 162, 210);"><strong>4.解析星空照片</strong></p>'
        '<p style="color: rgb(141, 179, 226);"><strong>如需详细帮助, 请回复对应数字.</strong></p>'
        % (data['author'], data['translate'], data['article'], data['en_url'],
           data['cn_url']),
        'picurl':
        data['picurl'],
        'source_url':
        data['cn_url'],
        'digest':
        data['article'][:100] + '...'
    }
    security.add_sign(req_data, consts.sitekey)
    resp = httputils.post_dict_sync(url=consts.wechat_news_url, data=req_data)
    if resp.code != 200:
        logging.error('fail to upload material')
        return False
    else:
        resp_data = json.loads(resp.body.decode('utf8'))
        if resp_data['err_code'] != 0:
            logging.error('fail to upload material: %s: %s',
                          resp_data['err_code'], resp_data['err_msg'])
            return False
        else:
            logging.info('finish to upload material')
            return True