def test_basic(): """ test_basic""" client = CloudAMQPClient(CLOUDAMQP_URL, TEST_QUEUE_NAME) sent_msg = {'test': 'test'} client.send_message(sent_msg) received_msg = client.get_message() assert sent_msg == received_msg print 'test_basic passed.'
def test_basic(): """ test basic cases """ client = CloudAMQPClient(CLOUDAMQP_URL, TEST_QUEUE_NAME) send = {"test": "test"} client.send_message(send) rev = client.get_message() assert send == rev print "test_basic passed."
cloudAMQP_client = CloudAMQPClient(SCRAPE_NEWS_TASK_QUEUE_URL, SCRAPE_NEWS_TASK_QUEUE_NAME) while True: news_list = news_api_client.getNewsFromSource(NEWS_SOURCES) num_of_news_news = 0 for news in news_list: news_digest = hashlib.md5( news['title'].encode('utf-8')).digest().encode('base64') if redis_client.get(news_digest) is None: num_of_news_news = num_of_news_news + 1 news['digest'] = news_digest if news['publishedAt'] is None: news['publishedAt'] = datetime.datetime.utcnow().strftime( "%Y-%m-%dT%H:%M:%SZ") redis_client.set(news_digest, "True") redis_client.expire(news_digest, NEWS_TIME_OUT_IN_SECONDS) cloudAMQP_client.send_message(news) LOGGING_NEWS_MONITOR.info('[x] Sent message to %s' % (news['title'])) print "Fetched %d news." % num_of_news_news cloudAMQP_client.sleep(SLEEP_TIME_IN_SECONDS)