def producer_call(self, product_info): logger.info( 'product info {0} is being sent to the kafka que from the producer' .format(product_info['asin'])) if product_info: ack = self.producer.send('product_to_scrape', {'product_info': product_info}) logger.debug( 'The kafka acknowledgment after sending the message to que {0}' .format(ack)) try: record_metadata = ack.get(timeout=10) logger.info('Record_meta data for kafka que {0}'.format( record_metadata)) except KafkaError: # Decide what to do if produce request failed... logger.error('kafka connection error {0}'.format(KafkaError)) pass else: logger.debug( 'The product info is none so could not send it kafka que')
def update(self, user_payload): ''' This method is to update the user info ''' session = Session() user_payload['update_dt'] = datetime.utcnow() # calling method to remove transient variables user = user_from_dict(user_payload) if 'alert_preference' in user_payload: user_payload['alert_preference'] = json.dumps( user_payload['alert_preference']) session.query(User).filter( User.user_id == user.user_id).filter( User.tenant_id == user.tenant_id).update(user_payload) session.commit() updated_user = self.get(user.user_id, user.tenant_id) if updated_user[0] == 'error': logger.error('User info cant be updated as user with user_id {0} and tenant_id {1} doesnot exist '.format( user_payload['user_id'], user_payload['tenant_id'])) return ('error', 'User doesnt exist', None) return ('success', 'User Info Updated Sucessfully', updated_user[2])
def get(self, user_id, tenant_id): ''' This method retrieves the user info ''' session = Session() user = session.query(User).filter( User.user_id == user_id).filter( User.tenant_id == tenant_id).one_or_none() if user is None: logger.error('User with user_id {0} and tenant_id {1} doesnot exist'.format( user_id, tenant_id)) return ('error', 'User doesnt exist', None) logger.info('User info is retreived for the user_id {0} and tenant_id {1} with the user info {2}'.format( user_id, tenant_id, user.email_id)) return ('success', 'User Info Retrieved', user)
def get_subscription_plans(self, user_id): # def get(self,user_id,tenant_id): ''' This method retrieves the user info ''' payload = {} session = Session() # subscription = session.query(Subscription).filter(Subscription.tenant_id == tenant_id) plans = session.query(Subscription).all() session.commit() payload['plans'] = plans if plans is None: logger.error("no plans to show") return ('error', 'There are no Plans to', None) else: logger.info('Card info is retreived for the user_id {0} '.format( plans)) return ('success', 'plans Info Retrieved', payload)
def tenant_get(self, tenant_id): ''' This method is to retrieve the tenant info ''' session = Session() tenant = session.query(Tenant).filter(Tenant.tenant_id == tenant_id).one_or_none() session.commit() if tenant is None: logger.error( 'Tenant with the id {0} couldnt be found'.format(tenant_id)) return('error', 'Tenant could not be found', None) else: logger.info( 'Tenant info sucessfully retrived for the tenant {0}'.format(tenant_id)) return('success', 'Tenant Info Retrieved Successfully', tenant)
def default(self, obj): print('In the encoder func {0}'.format(obj)) logger.error('In the encoder func {0}'.format(obj)) if isinstance(obj.__class__, DeclarativeMeta): # an SQLAlchemy class fields = {} for field in [x for x in dir(obj) if not x.startswith('_') and x != 'metadata']: print('In the for loop of encoder {0}'.format(field)) data = obj.__getattribute__(field) try: if isinstance(data, datetime): print( 'Converting to dict from object in encoder {0}'.format(data)) data = str(data) fields[field] = data except TypeError: logger.info('Failed in encoder exception {0}'.format( fields[field])) fields[field] = None return fields return json.JSONEncoder.default(self, obj)
def get(self, user_id): # def get(self,user_id,tenant_id): ''' This method retrieves the user info ''' payload = {} session = Session() card = session.query(Payment).filter( Payment.user_id == user_id).one_or_none() # subscription = session.query(Subscription).filter(Subscription.tenant_id == tenant_id) session.commit() payload['cardDetails'] = card if card is None: logger.error('Card with user_id {0} doesnot exist'.format( user_id)) return ('error', 'Card doesnt exist', None) else: logger.info('Card info is retreived for the user_id {0} '.format( card)) return ('success', 'Card Info Retrieved', payload)
def get(self, productId, tenant_id): ''' This method is to retrieve the product info for the given tenant ''' session = Session() logger.info( 'The product with product_id {0} and tenant_id {1} is being retrieved' .format(productId, tenant_id)) product = session.query(Product).filter( Product.id == productId).filter(Product.archive != True).filter( Product.tenant_id == int(tenant_id)).one_or_none() session.commit() if product == None: logger.error( 'The product with product_id {0} and tenant_id {1} doesnt exist' .format(productId, tenant_id)) return "Product Doesn't Exist" else: return product