Example #1
0
def refreshTop20():
    """
    Refresh the first 20 users
    :return:
    """
    results = session.query(UserInfo.url_token).order_by(desc('follower_count')).limit(20).all()
    for result in results:
        app.send_task('tasks.zhihu.getUserInfo', args=[result[0], True], queue='q_userInfo', routing_key='rk_userInfo')
        time.sleep(TIME_DELAY)
Example #2
0
 def post(self, request, *args, **kwargs):
     """
     Verifiy form and send email.
     """
     form = EmailForm(request.POST)
     if form.is_valid():
         try:
             ip = request.META.get('REMOTE_ADDR', '')
             ua = request.META.get('HTTP_USER_AGENT', '')
             email = form.save()
             email.ip = ip
             email.ua = ua
             email.save()
             app.send_task('tasks.send_email', (email.id,), queue='email')
         except Exception, e:
             logger.error('[%s] Send email except, err: %s' % (request.view_name, str(e)))
             return self.response([{'status': 2, 'msg': 'System Error'}])
         else:
             return self.response([{'status': 0, 'msg': 'Success'}])
Example #3
0
def getUserInfo(url_token, refresh=None, relation=None):
    """
    Get the user info
    :param url_token: user's url_token
    :param refresh: refresh or not, default False
    :param Relation: Relation or not, default False
    :return:
    """
    try:
        r = requests.get(
            USER_INFO_URL.format(url_token),
            headers=HEADERS,
            timeout=TIMEOUT
        )
    except Exception as e:
        print(e)
    else:
        content = json.loads(r.content.decode('utf-8'))
        update_user_info(content)
        if refresh:
            insert_update_table(content)
        if relation:
            app.send_task('tasks.zhihu.followeeUser', args=[content, ], queue='q_followee', routing_key='rk_followee')
Example #4
0
from tasks import app

if __name__ == '__main__':
    app.send_task("tasks.task1.do_task1",
                  args=(
                      5,
                      9,
                  ),
                  queue='task1_queue',
                  routing_key='route1')
    print("send done")