def teardown_request(self):
    db = getattr(g, '_database', None)
    logger = Logger()
    logger.registerNewAction("Connection to database closed.")
    logger.log()
    if db is not None:
        db.close()
def get_user_attendedEvents(faceId):
    cur = get_database().cursor()
    args = (faceId, )
    logger = Logger()
    logger.registerNewAction("GET User attended events id: " + faceId)
    cur.execute("""
                SELECT
            			Event.IDEvent AS 'EventID',
            			Event.Name AS 'EventName',
            			Place.Name AS 'PlaceName',
            			Event.DateTime AS 'EventDateTime'
            	FROM
            			MA_User
            			JOIN MA_User_Event ON(MA_User.IDUser = MA_User_Event.IDUser)
            			JOIN Event ON (MA_User_Event.IDEvent = Event.IDEvent)
            			JOIN Place ON (Place.IDPlace = Event.IDPlace)
            	WHERE
            			Attendance = 1
            		AND MA_User.FacebookID = ?
            	ORDER BY
            			Event.DateTime DESC
                """, args)
    logger.log()
    query = cur.fetchall()
    return jsonify({'Events': query})
 def test_action_registry(self):
     loggerInstance = Logger()
     action1 = "Test Action 1"
     loggerInstance.registerNewAction("Test Action 1")
     actionRead = loggerInstance.getLatestAction()
     containsAction = action1 in actionRead
     self.assertTrue(containsAction)
     pass
def connect_to_database():
    logger = Logger()
    logger.registerNewAction("New database connection request")
    logger.log()
    con = None
    try:
        con = sqlite3.connect(DATABASE)
    except sqlite3.Error, e:
        print "f*****g Error %s:" % e.args[0]
def get_user_Info(faceId):
    cur = get_database().cursor()
    args = (faceId, )
    logger = Logger()
    logger.registerNewAction("GET USER request id: " + faceId)
    cur.execute("""
                SELECT
                    MA_USER.Name,
                    MA_User.LastName,
                    MA_User.Birthdate,
                    MA_User.Gender,
                    Location.Latitude,
                    Location.Longitude
                FROM
                    MA_User,
                    Location
                WHERE
                    MA_User.IDLocation = Location.IDLocation AND
                    MA_User.FacebookID = ?
                """, args)
    query = cur.fetchall()
    print query
    user = User(query[0][0], query[0][1], query[0][2], query[0][3], faceId)
    logger.registerNewAction("GET User built for return")
    logger.log()
    return json.dumps(user.__dict__)
def get_place_profile(placeId):
    cur = get_database().cursor()
    args = (placeId, )
    logger = Logger()
    logger.registerNewAction("GET Place profile id: " + placeId)
    cur.execute("""
                SELECT
            		Place.Name AS 'PlaceName',
            		Category.Name AS 'Category',
            		Place.Description AS 'PlaceDescription',
            		Location.Latitude,
            		Location.Longitude
                FROM
                		Place
                		JOIN Category ON (Category.IDCategory = Place.IDCategory)
                		JOIN Location ON (Location.IDLocation = PLACE.IDLocation)
                WHERE
                		Place.IDPlace = ?
                """, args)
    logger.log()
    query = cur.fetchall()
    return jsonify({'Place': query})
def get_user_friendList(faceId):
    cur = get_database().cursor()
    args = (faceId, )
    logger = Logger()
    logger.registerNewAction("GET User friends id:" + faceId)
    cur.execute("""
                SELECT
            			USER2.FacebookID,
            			USER2.Name,
            			USER2.LastName
            	FROM
            			MA_User AS USER1,
            			MA_User AS USER2,
            			MA_Users_Relation
            	WHERE
            			USER1.IDUser = MA_Users_Relation.IDUser_1
            		AND	USER2.IDUser = MA_Users_Relation.IDUser_2
            		AND	USER1.FacebookID = ?
            	ORDER BY
            			USER2.Name
                """, args)
    logger.log()
    query = cur.fetchall()
    return jsonify({'Friends': query})
 def test_empty_on_log(self):
 	logger = Logger()
 	logger.log()
 	latestAction = logger.getLatestAction()
 	self.assertEquals(latestAction, "")
 def test_action_registry_different_objects(self):
 	loggerInstance2 = Logger()
 	actionRead = loggerInstance2.getLatestAction()
 	action1 = "Test Action 1"
 	containsAction = action1 in actionRead
 	self.assertTrue(containsAction)
Beispiel #10
0
def index():
    logger = Logger()
    logger.registerNewAction("INDEX served")
    logger.log()
    return "<html><h1><a href='#'>Server running!</a></h1></html>"
Beispiel #11
0
def not_found(error):
    """Return a 404 json instead of 404 html"""
    logger = Logger()
    logger.registerNewAction("REQUEST made, 404 reached")
    logger.log()
    return make_response(jsonify({'error': 'Not found'}), 404)
Beispiel #12
0
def getEvents(faceId, orderByRecommend):
    cur = get_database().cursor()
    args = (faceId, )
    logger = Logger()
    logger.registerNewAction("GET Events id:" + faceId + "Ordered true:" + orderByRecommend)
    if(orderByRecommend):
        cur.execute("""
                    SELECT	EventList.EventName,
            				EventList.EventDescription,
            				EventList.EventDateTime,
            				EventList.PlaceName,
            				MA_User.Name as 'CreatorFirstName',
            				MA_User.LastName as 'CreatorLastName'
            		FROM
            			(SELECT	Event.Name AS 'EventName',
            					Event.Description AS 'EventDescription',
            					Event.DateTime AS 'EventDateTime',
            					Place.Name AS 'PlaceName',
            					Event.IDUser AS 'IDCreatorUser',
            					Recommendation.Weight
            			FROM	MA_User,
            					Recommendation,
            					Event,
            					Place
            			WHERE	MA_User.IDUser = Recommendation.IDUser
            				AND	Event.IDEvent = Recommendation.IDEvent
            				AND MA_User.FacebookID = ?
            				AND Event.DateTime >= DATE('now', '-1 day') --CamNote: date function had to be mod for sqlite
            				AND	Place.IDPlace = Event.IDPlace) AS EventList,
            			MA_User
            		WHERE
            				MA_User.IDUser = EventList.IDCreatorUser
            		ORDER BY
            				EventList.Weight DESC
                    """, args)
    else:
        cur.execute("""
                    SELECT	EventList.EventName,
            				EventList.EventDescription,
            				EventList.EventDateTime,
            				EventList.PlaceName,
            				MA_User.Name AS 'CreatorFirstName',
            				MA_User.LastName AS 'CreatorLastName'
            		FROM
            			(SELECT	Event.Name AS 'EventName',
            					Event.Description AS 'EventDescription',
            					Event.DateTime AS 'EventDateTime',
            					Place.Name AS 'PlaceName',
            					Event.IDUser AS 'IDCreatorUser',
            					Recommendation.Weight
            			FROM	MA_User,
            					Recommendation,
            					Event,
            					Place
            			WHERE	MA_User.IDUser = Recommendation.IDUser
            				AND	Event.IDEvent = Recommendation.IDEvent
            				AND MA_User.FacebookID = ?
            				AND Event.DateTime >= DATE('now', '-1 day') --CamNote: date function had to be mod for sqlite
            				AND	Place.IDPlace = Event.IDPlace) AS EventList,
            			MA_User
            		WHERE
            				MA_User.IDUser = EventList.IDCreatorUser
            		ORDER BY
            				EventList.EventDateTime
                    """, args)
    logger.log()
    query = cur.fetchall()
    return jsonify({'Events': query})