Created
March 29, 2015 06:06
-
-
Save jmkelly/4f793252203e7cc806b6 to your computer and use it in GitHub Desktop.
http post from from queue
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pika | |
import requests | |
import json | |
def send_request(data, url): | |
headers = {'content-type': 'application/json'} | |
requests.post(url, data=data, headers=headers) | |
print "successfully: " + data | |
def on_message(channel, method_frame, header_frame, body): | |
send_request(body, "http://howhotismyshed.com.au/reading") | |
channel.basic_ack(delivery_tag=method_frame.delivery_tag) | |
connection = pika.BlockingConnection() | |
channel = connection.channel() | |
channel.basic_consume(on_message, 'temperatures') | |
try: | |
channel.start_consuming() | |
except KeyboardInterrupt: | |
channel.stop_consuming() | |
connection.close() | |
except: | |
exc_type, exc_value, exc_traceback = sys.exc_info() | |
print traceback.format_exc() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment