def post(self): #get uploaded image upload = self.get_uploads()[0] # upload = self.request.get('img') # upload = blobstore.Blob(upload) blob_key= upload.key() img_key = blob_key logging.info(upload) # ethan = pat = alonso = ninja = False # new customer ethan = levr.Customer.all(keys_only=True).filter('email','*****@*****.**').get() levr_token = 'tlvXNw9F5Qgnqm_uKxYUx9xeyJHSRDnfBbVmUwvDWzQ' if not ethan: ethan = levr.Customer(levr_token = levr_token) ethan.email = '*****@*****.**' ethan.pw = enc.encrypt_password('ethan') ethan.alias = 'ethan owns the deals' ethan.favorites = [] ethan.tester = True ethan.levr_token = 'tlvXNw9F5Qgnqm_uKxYUx9xeyJHSRDnfBbVmUwvDWzQ' # ethan.foursquare_id = 37756769 ethan.foursquare_token = 'IDMTODCAKR34GOI5MSLEQ1IWDJA5SYU0PGHT4F5CAIMPR4CR' # ethan.twitter_token = '819972614-2HoAwfJcHCOePogonjPbNNxuQQsvHeYeJ3U2KasI' ethan.twitter_screen_name = 'LevrDevr' ethan.twitter_id = 819972614 ethan = ethan.put() 'AAACEdEose0cBANvf0FVOdH0NpoqLDZCnt8ZAlVfiYqe90CH1S7rOAEZC7ZChI340ElsX0bYXXOZC1Ks1kWU4JmsGMpUWzp7fm6CfIHKdXwN4ZAvVCFfGMa' pat = levr.Customer.all(keys_only=True).filter('email','*****@*****.**').get() if not pat: pat = levr.Customer(levr_token = levr_token) pat.email = '*****@*****.**' pat.pw = enc.encrypt_password('patrick') pat.alias = 'patrick' pat.favorites = [] pat.tester = True pat.levr_token = 'tlvXNw9F5Qgnqm_uKxYUx9xeyJHSRDnfBbVmUwvDWzQ' # pat.foursquare_id = 22161113 pat.foursquare_token = 'ML4L1LW3SO0SKUXLKWMMBTSOWIUZ34NOTWTWRW41D0ANDBAX' # pat.twitter_friends_by_sn = ['LevrDevr'] pat = pat.put() alonso = levr.Customer.all(keys_only=True).filter('email','*****@*****.**').get() if not alonso: alonso = levr.Customer(levr_token = levr_token) alonso.email = '*****@*****.**' alonso.pw = enc.encrypt_password('alonso') alonso.alias = 'alonso' alonso.favorites = [] # alonso.foursquare_token = '4PNJWJM0CAJ4XISEYR4PWS1DUVGD0MKFDMC4ODL3XGU115G0' alonso.tester = True alonso.levr_token = 'tlvXNw9F5Qgnqm_uKxYUx9xeyJHSRDnfBbVmUwvDWzQ' # alonso.foursquare_id = 32773785 alonso.foursquare_token = 'RGTMFLSGVHNMZMYKSMW4HYFNEE0ZRA5PTD4NJE34RHUOQ5LZ' alonso = alonso.put() ninja = levr.Customer.all(keys_only=True).filter('email','*****@*****.**').get() if not ninja: ninja = levr.Customer(levr_token = levr_token) ninja.email = '*****@*****.**' ninja.pw = enc.encrypt_password('santa') ninja.alias = 'Followed' ninja.favorites = [] ninja.tester = True ninja.levr_token = 'tlvXNw9F5Qgnqm_uKxYUx9xeyJHSRDnfBbVmUwvDWzQ' ninja = ninja.put() params = { 'uid' : ethan, 'business_name' : 'Als Sweatshop', 'geo_point' : levr.geo_converter('42.343880,-71.059570'), 'vicinity' : '10 Buick St', 'types' : 'Establishment,Food', 'deal_description' : 'This is a description gut guts who why when you buy a shoe with feet', 'deal_line1' : 'I am a deal', 'distance' : '10', #is -1 if unknown = double 'development' : True, 'img_key' : img_key } levr.dealCreate(params,'phone_new_business') params = { 'uid' : ethan, 'business_name' : 'Als Sweatshop 2', 'geo_point' : levr.geo_converter('42.343879999999999, -71.059569999999994'), 'vicinity' : '10 Buick St', 'types' : 'Establishment,Food', 'deal_description' : 'This is a description gut guts who why when you buy a shoe with feet', 'deal_line1' : 'I am a deal', 'distance' : '10', #is -1 if unknown = double 'development' : True, 'img_key' : img_key } deal = levr.dealCreate(params,'phone_new_business') p = db.get(pat) p.upvotes.append(deal.key()) p.put() params = { 'uid' : ethan, 'business_name' : 'Als Sweatshop', 'geo_point' : levr.geo_converter('42.343880,-71.059575'), 'vicinity' : '10 Buick St', 'types' : 'Establishment,Food', 'deal_description' : 'This is a description gut guts who why when you buy a shoe with feet', 'deal_line1' : 'I am a deal', 'distance' : '10', #is -1 if unknown = double 'development' : True, 'img_key' : img_key } deal = levr.dealCreate(params,'phone_new_business') bus = levr.Business.gql('WHERE business_name=:1','Als Sweatshop').get() ant = levr.Customer.get(ethan) ant.owner_of = str(bus.key()) ant.put() a = db.get(alonso) a.upvotes.append(deal.key()) a.put() self.redirect('/new/test')
def post(self): logging.debug(self.get_uploads()) if self.get_uploads(): #will this work? upload = self.get_uploads()[0] logging.info(upload) blob_key= upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError('Image was not uploaded') uid = enc.decrypt_key(self.request.get('uid')) businessID = enc.decrypt_key(self.request.get('businessID')) deal_text = self.request.get('deal_text') description = self.request.get('description') contentID = self.request.get('contentID') logging.info(uid) logging.info(businessID) logging.info(deal_text) logging.info(description) business = levr.Business.get(businessID) user = levr.Customer.get(uid) params = { 'uid' : user, 'business_name' : business.business_name, 'geo_point' : business.geo_point, 'vicinity' : business.vicinity, 'types' : ','.join(map(str, business.types)), #phone sends in a comma separated string, types is stored as a list 'deal_description' : description, 'deal_line1' : deal_text, 'distance' : -1, #is -1 if unknown = double 'development' : False, 'img_key' : img_key } dealID = levr.dealCreate(params,'phone_new_business') #fire off a task to do the image rotation stuff task_params = { 'blob_key' : str(img_key) } taskqueue.add(url='/tasks/checkImageRotationTask',payload=json.dumps(task_params)) #track event via mixpanel (asynchronous) # try: # properties = { # 'time' : time.time(), # 'distinct_id' : enc.encrypt_key(user.key()), # 'mp_name_tag' : user.display_name # } # mp_track.track('Deal uploaded','ab1137787f393161bd481e2756b77850',properties) # # to_increment = { # "Deals uploaded" : 1 # } # # mp_track.increment(enc.encrypt_key(user.key()),'ab1137787f393161bd481e2756b77850',to_increment) # # except: # levr.log_error() logging.info('/mobile/upload/complete/?uid='+urllib.quote(enc.encrypt_key(uid))) self.redirect('/mobile/upload/complete/?uid='+urllib.quote(enc.encrypt_key(uid)))
def post(self): logging.debug(self.get_uploads()) if self.get_uploads(): #will this work? upload = self.get_uploads()[0] logging.info(upload) blob_key = upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError('Image was not uploaded') uid = enc.decrypt_key(self.request.get('uid')) businessID = enc.decrypt_key(self.request.get('businessID')) deal_text = self.request.get('deal_text') description = self.request.get('description') contentID = self.request.get('contentID') logging.info(uid) logging.info(businessID) logging.info(deal_text) logging.info(description) business = levr.Business.get(businessID) user = levr.Customer.get(uid) params = { 'uid': user, 'business_name': business.business_name, 'geo_point': business.geo_point, 'vicinity': business.vicinity, 'types': ','.join( map(str, business.types) ), #phone sends in a comma separated string, types is stored as a list 'deal_description': description, 'deal_line1': deal_text, 'distance': -1, #is -1 if unknown = double 'development': False, 'img_key': img_key } dealID = levr.dealCreate(params, 'phone_new_business') #fire off a task to do the image rotation stuff task_params = {'blob_key': str(img_key)} taskqueue.add(url='/tasks/checkImageRotationTask', payload=json.dumps(task_params)) #track event via mixpanel (asynchronous) # try: # properties = { # 'time' : time.time(), # 'distinct_id' : enc.encrypt_key(user.key()), # 'mp_name_tag' : user.display_name # } # mp_track.track('Deal uploaded','ab1137787f393161bd481e2756b77850',properties) # # to_increment = { # "Deals uploaded" : 1 # } # # mp_track.increment(enc.encrypt_key(user.key()),'ab1137787f393161bd481e2756b77850',to_increment) # # except: # levr.log_error() logging.info('/mobile/upload/complete/?uid=' + urllib.quote(enc.encrypt_key(uid))) self.redirect('/mobile/upload/complete/?uid=' + urllib.quote(enc.encrypt_key(uid)))
def post(self,*args,**kwargs): #@UnusedVariable ''' @keyword actor: required @keyword business: required @keyword description: required @keyword deal_text: required @keyword development: required @requires: an image is uploaded - need the blob_key @return: the newly created deal object @rtype: dict ''' user = kwargs.get('actor') business = kwargs.get('business') description = kwargs.get('description') deal_text = kwargs.get('dealText') development = kwargs.get('development') img_key = '' try: #=================================================================== # Assure that an image was uploaded #=================================================================== if self.get_uploads(): upload = self.get_uploads()[0] blob_key= upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError('Image was not uploaded') #=================================================================== # Assemble the deal parameters! And create the deal!! #=================================================================== params = { 'user' : user, 'uid' : user.key(), 'business' : business, 'deal_description' : description, 'deal_line1' : deal_text, 'development' : development, 'img_key' : img_key } # TODO: add pin_color = 'green' to the deal # TODO: add origin = 'merchant' deal_entity = levr.dealCreate(params, 'phone_merchant', upload_flag) # if an image was uploaded, rotate it. if upload_flag == True: try: # Synchronously rotate the image api_utils.rotate_image(blob_key,deal_entity) except: levr.log_error('An image could not be rotated. It was sent to the task que: '+str(blob_key)) # Send the image to the img rotation task que task_params = { 'blob_key' : str(blob_key) } logging.info('Sending this to the img rotation task: '+str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL,payload=json.dumps(task_params)) #=================================================================== # Aw hell.. why not give them some karma too. #=================================================================== user.karma += 5 # no need to level_check on them though... user.put() #=================================================================== # Create some nifty notifications #=================================================================== try: levr.create_notification('followedUpload',user.followers,user.key(),deal_entity) except: levr.log_error() #=================================================================== # Respond with all of the users deals #=================================================================== private = True deals = api_utils.fetch_all_users_deals(user) packaged_deals = api_utils.package_deal_multi(deals, private) response = { 'deals' : packaged_deals } api_utils.send_response(self,response, user) except Exception,e: levr.log_error(e) api_utils.send_error(self,'Server Error')
def post(self, *args, **kwargs): #@UnusedVariable ''' @keyword actor: required @keyword business: required @keyword description: required @keyword deal_text: required @keyword development: required @requires: an image is uploaded - need the blob_key @return: the newly created deal object @rtype: dict ''' user = kwargs.get('actor') business = kwargs.get('business') description = kwargs.get('description') deal_text = kwargs.get('dealText') development = kwargs.get('development') img_key = '' try: #=================================================================== # Assure that an image was uploaded #=================================================================== if self.get_uploads(): upload = self.get_uploads()[0] blob_key = upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError('Image was not uploaded') #=================================================================== # Assemble the deal parameters! And create the deal!! #=================================================================== params = { 'user': user, 'uid': user.key(), 'business': business, 'deal_description': description, 'deal_line1': deal_text, 'development': development, 'img_key': img_key } # TODO: add pin_color = 'green' to the deal # TODO: add origin = 'merchant' deal_entity = levr.dealCreate(params, 'phone_merchant', upload_flag) # if an image was uploaded, rotate it. if upload_flag == True: try: # Synchronously rotate the image api_utils.rotate_image(blob_key, deal_entity) except: levr.log_error( 'An image could not be rotated. It was sent to the task que: ' + str(blob_key)) # Send the image to the img rotation task que task_params = {'blob_key': str(blob_key)} logging.info('Sending this to the img rotation task: ' + str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL, payload=json.dumps(task_params)) #=================================================================== # Aw hell.. why not give them some karma too. #=================================================================== user.karma += 5 # no need to level_check on them though... user.put() #=================================================================== # Create some nifty notifications #=================================================================== try: levr.create_notification('followedUpload', user.followers, user.key(), deal_entity) except: levr.log_error() #=================================================================== # Respond with all of the users deals #=================================================================== private = True deals = api_utils.fetch_all_users_deals(user) packaged_deals = api_utils.package_deal_multi(deals, private) response = {'deals': packaged_deals} api_utils.send_response(self, response, user) except Exception, e: levr.log_error(e) api_utils.send_error(self, 'Server Error')
def post(self, *args, **kwargs): try: logging.info("uploadDeal\n\n\n") logging.info(kwargs) user = kwargs.get("actor") uid = user.key() # make sure than an image is uploaded logging.debug(self.get_uploads()) if self.get_uploads(): # will this work? upload = self.get_uploads()[0] blob_key = upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError("Image was not uploaded") params = { "uid": uid, "business_name": kwargs.get("businessName"), "geo_point": kwargs.get("geoPoint"), "vicinity": kwargs.get("vicinity"), "types": kwargs.get("types"), "deal_description": kwargs.get("description"), "deal_line1": kwargs.get("dealText"), "distance": kwargs.get("distance"), # is -1 if unknown = double "shareURL": kwargs.get("shareURL"), "development": kwargs.get("development"), "img_key": img_key, } # create the deal using the origin specified deal_entity = levr.dealCreate(params, "phone_new_business", upload_flag) # fire off a task to rotate the image task_params = {"blob_key": str(deal_entity.img.key())} logging.info("Sending this to the task: " + str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL, payload=json.dumps(task_params)) # give the user some karma user.karma += 5 # level check! user = api_utils.level_check(user) user.put() # go notify everyone that should be informed try: levr.create_notification("followedUpload", user.followers, user.key(), deal_entity) except: levr.log_error() # grab deal information for sending back to phone deal = api_utils.package_deal(deal_entity, True) response = {"deal": deal} # =================================================================== # Send notification to founders # =================================================================== try: # approve_link = 'http://www.levr.com/admin/deal/{}/approve'.format(enc.encrypt_key(deal_entity.key())) base_url = "http://www.levr.com/admin/deal/{}/expiration?daysToExpire=".format( enc.encrypt_key(deal_entity.key()) ) today_only_link = base_url + "0" one_week_link = base_url + "7" one_month_link = base_url + "30" three_month_link = base_url + "90" six_month_link = base_url + "180" one_year_link = base_url + "360" never_link = base_url + "-1" reject_link = "http://www.levr.com/admin/deal/{}/reject".format(enc.encrypt_key(deal_entity.key())) message = mail.AdminEmailMessage() message.sender = "*****@*****.**" message.subject = "New Upload" message.html = '<img src="{}"><br>'.format(deal.get("smallImg")) message.html += "<h2>{}</h2>".format(deal_entity.deal_text) message.html += "<h3>{}</h3>".format(deal_entity.description) message.html += "<h4>Uploaded by: {}</h4>".format(user.display_name) message.html += "<h5>deal_status: {}</h5>".format(deal_entity.deal_status) message.html += "<br/><p>Set deal expiration.</p>" message.html += '<br><a href="{}">Reject</a><br><br>'.format(reject_link) message.html += '<br><a href="{}">Today Only</a><br><br>'.format(today_only_link) message.html += '<br><a href="{}">One Week</a><br><br>'.format(one_week_link) message.html += '<br><a href="{}">One Month</a><br><br>'.format(one_month_link) message.html += '<br><a href="{}">Three Month</a><br><br>'.format(three_month_link) message.html += '<br><a href="{}">Six Month</a><br><br>'.format(six_month_link) message.html += '<br><a href="{}">One Year</a><br><br>'.format(one_year_link) message.html += '<br><a href="{}">Forever!!!</a><br><br>'.format(never_link) message.html += levr.log_dict(deal, None, "<br>") # message.body += '\n\n\n\n\n\nApprove: {}'.format(approve_link) message.check_initialized() message.send() except: levr.log_error() api_utils.send_response(self, response) except KeyError, e: logging.info("Key Error") logging.info(str(e)) levr.log_error() api_utils.send_error(self, str(e))
def post(self, *args, **kwargs): try: logging.info('uploadDeal\n\n\n') logging.info(kwargs) user = kwargs.get('actor') uid = user.key() #make sure than an image is uploaded logging.debug(self.get_uploads()) if self.get_uploads(): #will this work? upload = self.get_uploads()[0] blob_key = upload.key() img_key = blob_key upload_flag = True else: upload_flag = False raise KeyError('Image was not uploaded') params = { 'uid': uid, 'business_name': kwargs.get('businessName'), 'geo_point': kwargs.get('geoPoint'), 'vicinity': kwargs.get('vicinity'), 'types': kwargs.get('types'), 'deal_description': kwargs.get('description'), 'deal_line1': kwargs.get('dealText'), 'distance': kwargs.get('distance'), #is -1 if unknown = double 'shareURL': kwargs.get('shareURL'), 'development': kwargs.get('development'), 'img_key': img_key } #create the deal using the origin specified deal_entity = levr.dealCreate(params, 'phone_new_business', upload_flag) #fire off a task to rotate the image task_params = {'blob_key': str(deal_entity.img.key())} logging.info('Sending this to the task: ' + str(task_params)) taskqueue.add(url=IMAGE_ROTATION_TASK_URL, payload=json.dumps(task_params)) #give the user some karma user.karma += 5 #level check! user = api_utils.level_check(user) user.put() #go notify everyone that should be informed try: levr.create_notification('followedUpload', user.followers, user.key(), deal_entity) except: levr.log_error() #grab deal information for sending back to phone deal = api_utils.package_deal(deal_entity, True) response = {'deal': deal} #=================================================================== # Send notification to founders #=================================================================== try: # approve_link = 'http://www.levr.com/admin/deal/{}/approve'.format(enc.encrypt_key(deal_entity.key())) base_url = 'http://www.levr.com/admin/deal/{}/expiration?daysToExpire='.format( enc.encrypt_key(deal_entity.key())) today_only_link = base_url + '0' one_week_link = base_url + '7' one_month_link = base_url + '30' three_month_link = base_url + '90' six_month_link = base_url + '180' one_year_link = base_url + '360' never_link = base_url + '-1' reject_link = 'http://www.levr.com/admin/deal/{}/reject'.format( enc.encrypt_key(deal_entity.key())) message = mail.AdminEmailMessage() message.sender = '*****@*****.**' message.subject = 'New Upload' message.html = '<img src="{}"><br>'.format( deal.get('smallImg')) message.html += '<h2>{}</h2>'.format(deal_entity.deal_text) message.html += '<h3>{}</h3>'.format(deal_entity.description) message.html += '<h4>Uploaded by: {}</h4>'.format( user.display_name) message.html += '<h5>deal_status: {}</h5>'.format( deal_entity.deal_status) message.html += '<br/><p>Set deal expiration.</p>' message.html += '<br><a href="{}">Reject</a><br><br>'.format( reject_link) message.html += '<br><a href="{}">Today Only</a><br><br>'.format( today_only_link) message.html += '<br><a href="{}">One Week</a><br><br>'.format( one_week_link) message.html += '<br><a href="{}">One Month</a><br><br>'.format( one_month_link) message.html += '<br><a href="{}">Three Month</a><br><br>'.format( three_month_link) message.html += '<br><a href="{}">Six Month</a><br><br>'.format( six_month_link) message.html += '<br><a href="{}">One Year</a><br><br>'.format( one_year_link) message.html += '<br><a href="{}">Forever!!!</a><br><br>'.format( never_link) message.html += levr.log_dict(deal, None, '<br>') # message.body += '\n\n\n\n\n\nApprove: {}'.format(approve_link) message.check_initialized() message.send() except: levr.log_error() api_utils.send_response(self, response) except KeyError, e: logging.info('Key Error') logging.info(str(e)) levr.log_error() api_utils.send_error(self, str(e))