def rabbitmqsend(): from libs import rabbitmq dataStr = { 'id': '876327f6-35a1-43e6-8d46-3dcadab623f7', 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1', 'url': 'https://yourdemo.herokuapp.com/', 'image_width': 2320, 'image_height': 3088, 'cookie': 'f482e8e3-9b64-46b7-9cab-e4fc33ca5f17', 'UPLOAD_IN_REDIS': False, 'remote_url': 'https://bucketeer-ad74aded-29ae-4300-ac4a-2ed34f120de3.s3.eu-west-1.amazonaws.com/public/876327f6-35a1-43e6-8d46-3dcadab623f7.jpg' } dataJson = ujson.dumps(dataStr) rabbitmq.sendMessage(dataJson, "wtf") return "ok"
def image(): try: logger.debug(utils.get_debug_all(request)) i = request.files['fileToUpload'] # get the image imageid = uuid.uuid4().__str__() f = ('%s.jpeg' % (imageid)) i.save('%s/%s' % (PATH_TO_TEST_IMAGES_DIR, f)) completeFilename = '%s/%s' % (PATH_TO_TEST_IMAGES_DIR, f) try: filepath = completeFilename image = Image.open(filepath) img_width = image.size[0] img_height = image.size[1] for orientation in ExifTags.TAGS.keys(): if ExifTags.TAGS[orientation] == 'Orientation': break exif = dict(image._getexif().items()) logger.debug(exif[orientation]) if exif[orientation] == 3: image = image.rotate(180, expand=True) image.save( filepath, quality=50, subsampling=0, ) elif exif[orientation] == 6: image = image.rotate(270, expand=True) image.save( filepath, quality=50, subsampling=0, ) elif exif[orientation] == 8: image = image.rotate(90, expand=True) image.save( filepath, quality=50, subsampling=0, ) img_width = image.size[0] img_height = image.size[1] image.close() except Exception as e: import traceback traceback.print_exc() # ok the entry is correct let's add it in our db cookie, cookie_exists = utils.getCookie() if (postgres.__checkHerokuLogsTable()): postgres.__saveLogEntry(request, cookie) # now upload logger.debug(completeFilename) #prepare rabbitmq data rabbitdata = { 'id': imageid, 'user-agent': request.headers['User-Agent'], 'url': request.url, 'image_width': img_width, "image_height": img_height, 'cookie': cookie } if (UPLOAD_IN_REDIS == True): # Save the image into redis file = open(completeFilename, "rb") data = file.read() file.close() rediscache.__setCache(imageid, data, 3600) os.remove(completeFilename) logger.info("File saved in Redis") rabbitdata['UPLOAD_IN_REDIS'] = True else: # saves into AWS rabbitdata['UPLOAD_IN_REDIS'] = False remotefilename = imageid + ".jpg" awsFilename = aws.uploadData(completeFilename, remotefilename) os.remove(completeFilename) logger.info("File saved in AWS") rabbitdata['remote_url'] = awsFilename # Sends data to RabbitMQ logger.debug(rabbitdata) rabbitmq.sendMessage(ujson.dumps(rabbitdata), rabbitmq.CLOUDAMQP_QUEUE) #awsFilename = aws.uploadData(completeFilename, f) key = { 'url': request.url, 'status_upload': 'Thanks for participating', 'error_upload': None } tmp_dict = None #data_dict = None tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache") data = render_template(RENDER_ROOT_PHOTO, status_upload="Thanks for participating", error_upload=None, FA_APIKEY=utils.FOLLOWANALYTICS_API_KEY, userid=cookie, PUSHER_KEY=notification.PUSHER_KEY) #rediscache.__setCache(key, data, 60) else: logger.info("Data found in redis, using it directly") data = tmp_dict return utils.returnResponse(data, 200, cookie, cookie_exists) except Exception as e: import traceback cookie, cookie_exists = utils.getCookie() data = render_template( RENDER_ROOT_PHOTO, status_upload=None, error_upload= "An error occured while saving your file, please try again", FA_APIKEY=utils.FOLLOWANALYTICS_API_KEY, userid=cookie, PUSHER_KEY=notification.PUSHER_KEY) return utils.returnResponse(data, 200, cookie, cookie_exists)
from libs import rabbitmq import datetime, ujson for i in range(30): currentDate = datetime.datetime.now() dataStr = {"Data": "Content " + currentDate.__str__() + " - " + str(i)} dataJson = ujson.dumps(dataStr) rabbitmq.sendMessage(dataJson, rabbitmq.CLOUDAMQP_QUEUE)
def guest(): try: cookie, cookie_exists = utils.getCookie() if (postgres.__checkHerokuLogsTable()): postgres.__saveLogEntry(request, cookie) logger.debug(utils.get_debug_all(request)) form = ReusableForm(request.form) hosts = postgres.__getSFUsers() key = {'url' : MAIN_URL, 'cookie' : cookie} tmp_dict = rediscache.__getCache(key) data = "" if request.method == 'GET': if ((tmp_dict != None) and (tmp_dict != '')): #means user has already registered, forwarding him to the guest thanks data = render_template(GUESTTHANKS, registered=True, userid=cookie, PUSHER_KEY=notification.PUSHER_KEY, PUSHER_CLUSTER=notification.CLUSTER) return utils.returnResponse(data, 200, cookie, cookie_exists) else: # needs to register data = render_template(GUESTFILE, form=form, hosts=hosts['data'],userid=cookie,PUSHER_KEY=notification.PUSHER_KEY, PUSHER_CLUSTER=notification.CLUSTER) return utils.returnResponse(data, 200, cookie, cookie_exists) elif request.method == 'POST': if ((tmp_dict != None) and (tmp_dict != '')): #user has gone through the registration process already, need to redirect him to the guest thanks page data = render_template(GUESTTHANKS, registered=True, userid=cookie, PUSHER_KEY=notification.PUSHER_KEY, PUSHER_CLUSTER=notification.CLUSTER) return utils.returnResponse(data, 200, cookie, cookie_exists) else: #user has not registerd yet, it's the case now Firstname=request.form['Firstname'] Lastname=request.form['Lastname'] Email=request.form['Email'] Company=request.form['Company'] PhoneNumber=request.form['PhoneNumber'] Host=request.form['Host'] Picture="https://3.bp.blogspot.com/-KIngJEZr94Q/Wsxoh-8kwuI/AAAAAAAAQyM/YlDJM1eBvzoDAUV79-0v_Us-amsjlFpkgCLcBGAs/s1600/aaa.jpg" if ("fileToUpload" in request.files): Picture, rabbitData =aws.AWS_upload(request.files['fileToUpload'], request) rabbitData['cookie'] = cookie rabbitData['UPLOAD_IN_REDIS'] = False rabbitData['remote_url'] = Picture logger.info(rabbitData) rabbitmq.sendMessage(ujson.dumps(rabbitData), rabbitmq.CLOUDAMQP_QUEUE) postgres.__saveGuestEntry(Firstname, Lastname, Email, Company, PhoneNumber, Host, cookie, Picture) data = render_template(GUESTTHANKS, registered=False, userid=cookie, PUSHER_KEY=notification.PUSHER_KEY, PUSHER_CLUSTER=notification.CLUSTER) rediscache.__setCache(key, ujson.dumps({"Status":"Logged In"}), 3600) return utils.returnResponse(data, 200, cookie, cookie_exists) else: #redirecting the user return redirect("/",code=302) if form.validate(): # Save the comment here. flash('Hello ' + Firstname) else: flash('All the form fields are required. ') data = render_template(GUESTFILE, form=form, hosts=hosts['data'],userid=cookie,PUSHER_KEY=notification.PUSHER_KEY, PUSHER_CLUSTER=notification.CLUSTER) return utils.returnResponse(data, 200, cookie, cookie_exists) except Exception as e: import traceback traceback.print_exc() cookie, cookie_exists = utils.getCookie() return utils.returnResponse("An error occured, check logDNA for more information", 200, cookie, cookie_exists)
for i in range(1): currentDate = datetime.datetime.now() dataStr = { "id": uuid.uuid4().__str__(), "Data": "Content " + currentDate.__str__() + " - " + str(i), "UPLOAD_IN_REDIS": False } #dataStr = {'id': '876327f6-35a1-43e6-8d46-3dcadab623f7', #'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1', #url': 'https://yourdemo.herokuapp.com/', 'image_width': 2320, 'image_height': 3088, 'cookie': 'f482e8e3-9b64-46b7-9cab-e4fc33ca5f17', 'UPLOAD_IN_REDIS': False, 'remote_url': 'https://bucketeer-ad74aded-29ae-4300-ac4a-2ed34f120de3.s3.eu-west-1.amazonaws.com/public/876327f6-35a1-43e6-8d46-3dcadab623f7.jpg'} dataStr = { 'id': '29218951-51c1-4342-a433-bd42503b3f7d', 'user-agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/73.0.3683.68 Mobile/15E148 Safari/605.1', 'url': 'http://yourdemo.herokuapp.com/', 'image_width': 1932, 'image_height': 2576, 'cookie': '602c7e17-d3cc-4249-8956-04d90607cc6a', 'UPLOAD_IN_REDIS': False, 'remote_url': 'https://bucketeer-ad74aded-29ae-4300-ac4a-2ed34f120de3.s3.eu-west-1.amazonaws.com/public/29218951-51c1-4342-a433-bd42503b3f7d.jpg' } dataJson = ujson.dumps(dataStr) rabbitmq.sendMessage(dataJson, "web-to-workers")