@ -20,10 +20,20 @@ db_engine = {}
db_metadata = { }
db_metadata = { }
meals = { }
meals = { }
def connect ( user , password , db , host = ' localhost ' , port = 5432 ) :
url = ' postgresql:// {} : {} @ {} : {} / {} '
url = url . format ( user , password , host , port , db )
con = sqlalchemy . create_engine ( url , client_encoding = ' utf8 ' )
meta = sqlalchemy . MetaData ( bind = con , reflect = True )
return con , meta
def getLeaderboard ( ) :
def getLeaderboard ( ) :
leaders = [ ]
s = ' select u.username as name, u.score as score, max(m.meal_date) as last_meal from users as u inner join meals as m on u.id = m.kuk where m.kuk>0 and m.status>0 group by u.id order by u.score, last_meal; '
leaders . append ( { ' name ' : ' marek ' , ' score ' : 34 } )
r = db_engine . execute ( text ( s ) )
leaders . append ( { ' name ' : ' sven ' , ' score ' : 16 } )
leaders = [ ]
for row in r :
leaders . append ( dict ( row ) )
r . close ( )
return leaders
return leaders
def getUpcomingMeals ( ) :
def getUpcomingMeals ( ) :