예제 #1
0
def sendpush():
    uid = "4acc457cc41a45c8a413b208017c6db3"
    token = redis_db.get(uid)
    print 'token:' + token
    # data = json.loads(request.data)
    data = request.form
    groupname = data.get('groupname')
    info = data.get('info')
    print groupname + '   ' + info
    url = ''
    # res = requests.post(url, json={}, headers={'content-type': 'application/json','X-ACCESS-TOKEN': token})
    return json.dumps({'result': "true"})
예제 #2
0
def get_group():
    global DBSESSION
    check_dbsession(DBSESSION)
    res = []
    sql = 'SELECT uid, nickname FROM profile ORDER BY update_time DESC'
    users = DBSESSION.execute(sql)
    for u in users:
        uid = u.uid
        nickname = u.nickname
        # access redis get user token
        token = redis_db.get(u.uid)
        if not token:
            current_app.logger.error('can not get token for uid: %s' % uid)
            continue

        # access dse-service API get user groups by uid: /v1/app/{uid}/group
        url = DSE_SERVICE_GROUP_URL.format(uid=uid)
        headers = {
            'content-type': 'application/json',
            'X-ACCESS-TOKEN': token,
        }

        req = requests.get(url, headers=headers)
        if req.status_code != 200:
            err_msg = 'get <%s, %s> groups error: %s' % (uid, nickname, req.content)
            groups = err_msg
            current_app.logger.error(err_msg)
        else:
            groups = ', '.join([x['gname'] for x in req.json()['data']])

        res.append({
            'uid': uid,
            'nickname': nickname,
            'groups': groups,
        })

    return res