def __getMatchsByGameActivityId(gameactivity__c): sqlRequest = """select match__c.sfid matchid , match__c.date__c Date, match__c.question__c Question, participant__c_home.name as Participant_Home, participant__c_visitor.name Participant_Visitor from salesforce.match__c match__c, salesforce.participant__c participant__c_home , salesforce.participant__c participant__c_visitor where match__c.gameactivity__c = %(gameactivity__c)s and (participant__c_home.sfid = match__c.participant_home__c) and (participant__c_visitor.sfid = match__c.participant_visitor__c) order by match__c.date__c DESC""" key = { "sqlRequest": "__getMatchsByGameActivityById", "activityId": gameactivity__c } tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache : heroku log data not known") data = __execRequest(sqlRequest, {'gameactivity__c': gameactivity__c}) rediscache.__setCache(key, utils.jsonencode(data), 60) else: logger.info("Data found in redis, using it directly") data = ujson.loads(tmp_dict) return data
def badgeById(badge_id): # get the badge if (badge_id != None and badge_id != ""): cookie, cookie_exists = utils.getCookie() badge_content = postgres.__execRequest( "Select * from badge where id=%(badge_id)s and badge_status='ACTIVE' ", {'badge_id': badge_id}) if (len(badge_content['data']) > 0): logger.info(badge_content) if ('output' in request.args): if (request.args['output'] == 'json'): return utils.returnResponse( utils.jsonencode(badge_content), 200, cookie, cookie_exists) QRCODE_COMPLETE_URL = QRCODE_URL + "'" + APPURL + badge_content[ 'data'][0]['id'] + "?output=json'" logger.info(QRCODE_COMPLETE_URL) data = render_template( BADGE_DATA, GuestFirstname=badge_content['data'][0]['guest_firstname'], GuestLastname=badge_content['data'][0]['guest_lastname'], GuestCompany=badge_content['data'][0]['guest_company'], HostFirstname=badge_content['data'][0]['host_firstname'], HostLastname=badge_content['data'][0]['host_lastname'], ProfilePicture=badge_content['data'][0]['picture_url'], QRCode=QRCODE_COMPLETE_URL) return utils.returnResponse(data, 200, cookie, cookie_exists) return utils.returnResponse( ujson.dumps({'Error': 'Unknown or incorrect badge id'}), 404, cookie, cookie_exists)
def __getMatchById(match_id): sqlRequest = """select date__c , match__c.participant_home__c participant_home_id, match__c.participant_visitor__c participant_visitor_id, match__c.sfid match_id, match__c.gameactivity__c gameactivity__c, match__c.question__c question__c, participant__home.name participant_home_name, participant__home.image__c participant_home_image, participant__home.description__c participant_home_description, participant__visitor.name participant_visitor_name, participant__visitor.image__c participant_visitor_image, participant__visitor.description__c participant_visitor_description from salesforce.match__c, salesforce.participant__c participant__home, salesforce.participant__c participant__visitor where match__c.sfid= %(match_id)s and (participant__home.sfid = match__c.participant_home__c) and (participant__visitor.sfid = match__c.participant_visitor__c)""" key = {"sqlRequest": "__getMatchById", "match_id": match_id} tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache : heroku log data not known") data = __execRequest(sqlRequest, {'match_id': match_id}) rediscache.__setCache(key, utils.jsonencode(data), 60) else: logger.info("Data found in redis, using it directly") data = ujson.loads(tmp_dict) return data
def __getImageAnalysis(tableName, objectName): key = {"sqlRequest": "__getImageAnalysis", "objectName": objectName} tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache : heroku log data not known") concat = SALESFORCE_SCHEMA + "." + tableName data = __execRequest( "select * from {} where name='{}' ".format(concat, objectName), {}) rediscache.__setCache(key, utils.jsonencode(data), 120) else: logger.info("Data found in redis, using it directly") data = ujson.loads(tmp_dict) return data
def __getTables(): key = {"sqlRequest": "__getTables"} tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache : heroku log data not known") sqlRequest = "SELECT table_schema, table_name FROM information_schema.tables where table_schema like '%%alesforce' ORDER BY table_schema,table_name" data = __execRequest(sqlRequest, {}) rediscache.__setCache(key, utils.jsonencode(data), 30) else: logger.info("Data found in redis, using it directly") data = ujson.loads(tmp_dict) return data
def __getObjects(tableName): key = {"sqlRequest": "__getObjects", "tableName": tableName} tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache : data not known") concat = SALESFORCE_SCHEMA + "." + tableName data = __execRequest("select * from {}".format(concat), {}) logger.info("Data Returned") logger.info(data) rediscache.__setCache(key, utils.jsonencode(data), 30) else: logger.info("Data found in redis, using it directly") data = ujson.loads(tmp_dict) return data
def __getSFUsers(): key = {"sqlRequest": "getSFUsers"} tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache : heroku log data not known") sql = "select name, sfid from salesforce.user where CanAcceptGuest__c = 'True' order by name ASC" data = __execRequest(sql, {}) rediscache.__setCache(key, utils.jsonencode(data), 60) else: logger.info("Data found in redis, using it directly") data = ujson.loads(tmp_dict) logger.debug(data) return data
def __getMatchs(): sqlRequest = """ select salesforce.gameactivity__c.name , salesforce.gameactivity__c.sfid, (select count(*) from salesforce.match__c where salesforce.match__c.gameactivity__c = salesforce.gameactivity__c.sfid) as nbMatchs from salesforce.gameactivity__c where salesforce.gameactivity__c.active__c = True """ key = {"sqlRequest": "__getMatchs"} tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache : heroku log data not known") data = __execRequest(sqlRequest, None) rediscache.__setCache(key, utils.jsonencode(data), 60) else: logger.info("Data found in redis, using it directly") data = ujson.loads(tmp_dict) return data
def __getGameActivityById(gameactivity__c): key = { "sqlRequest": "__getGameActivityById", "activityId": gameactivity__c } tmp_dict = rediscache.__getCache(key) if ((tmp_dict == None) or (tmp_dict == '')): logger.info("Data not found in cache : heroku log data not known") sqlRequestActivityName = """ select gameactivity__c.name ActivityName from salesforce.gameactivity__c where gameactivity__c.sfid = %(gameactivity__c)s """ data = __execRequest(sqlRequestActivityName, {'gameactivity__c': gameactivity__c}) rediscache.__setCache(key, utils.jsonencode(data), 60) else: logger.info("Data found in redis, using it directly") data = ujson.loads(tmp_dict) return data