# print "try to request again!" # response = requests.put(url, data=json.dumps({'command': command,'devicename':devicename}),headers={'content-type': 'application/json'}) print "request res: %s" % res #if is_json(res): return res.json()['Result'] #else: # return "ERROR: Json result from emulator is not valid, result:%s" % str(res) try: # Loop forever. MAX_DEL_DICT = 7 while 1: #processing the queue messages and asking device emulator to do the task queue.set_message_class(RawMessage) results = queue.get_messages(num_messages=10, visibility_timeout=30,wait_time_seconds=10) dict_deleted ={} del_history = [] print "received queue result : %d" % len(results) for msg in results: body = msg.get_body() jbody = json.loads(body) requestdate =jbody["requestdate"] if jbody["requestdate"] == None else jbody["requestdate"].strip() executedate =jbody["executedate"] if jbody["executedate"] == None else jbody["executedate"].strip() userid = jbody["userid"].strip() command = jbody["command"].strip() devicename = jbody["devicename"] if jbody["devicename"] == None else jbody["devicename"].strip() key = "%s:%s:%s:%s" %(requestdate,executedate,userid,command) print "userid:%s\n command:%s \n devicename:%s \n execute date:%s \n" % ( userid,command,devicename,executedate) if key not in dict_deleted:
print "request res: %s" % res #if is_json(res): return res.json()['Result'] #else: # return "ERROR: Json result from emulator is not valid, result:%s" % str(res) try: # Loop forever. MAX_DEL_DICT = 7 while 1: #processing the queue messages and asking device emulator to do the task queue.set_message_class(RawMessage) results = queue.get_messages(num_messages=10, visibility_timeout=30, wait_time_seconds=10) dict_deleted = {} del_history = [] print "received queue result : %d" % len(results) for msg in results: body = msg.get_body() jbody = json.loads(body) requestdate = jbody["requestdate"] if jbody[ "requestdate"] == None else jbody["requestdate"].strip() executedate = jbody["executedate"] if jbody[ "executedate"] == None else jbody["executedate"].strip() userid = jbody["userid"].strip() command = jbody["command"].strip() devicename = jbody["devicename"] if jbody[ "devicename"] == None else jbody["devicename"].strip()
key.set_contents_from_string(buf.getvalue()) buf.close() try: # Loop forever. while 1: # Read a message from the queue containing the key of # the image to be resized, use read() to read the image. # For every size of image to generated, call thumbnail() # to generate the image and then write() to store the # generated thumbnail back into S3. Good luck, have fun. messages = queue.get_messages(visibility_timeout=5) for m in messages: messageDict = json.loads(m.get_body()) key = messageDict["key"] + "-original" image = read(key) key = messageDict["key"] for size in messageDict["sizes"]: width = messageDict["sizes"][size]["width"] height = messageDict["sizes"][size]["height"] thumb = thumbnail(image, int(width), int(height)) fileName = key + "-" + size write(fileName, thumb, image.format.lower()) queue.delete_message(m) time.sleep(1) # When someone tries to break the program just quit gracefully