def add_user_to_league_by_token(user_info, token): db = InteractWithUsersDb() id = db.get_user_info(user_info["name"])[0][0] info = Scripts.token_load(token) movie_db = InteractWithMovieDb() users = movie_db.get_league_users_ids(info) for i in users: if id in i: return False movie_db.add_user_to_league_user(info, id) return True
def my_movies_league_totals_info(user_info): my_movies = OrderedDict() db = InteractWithUsersDb() movie_db = InteractWithMovieDb() print user_info id = db.get_user_info(user_info["name"])[0][0] leagues = movie_db.get_users_leagues(str(id)) for league in leagues: league_info = movie_db.get_league_totals_for_all_users(league) my_movies[league] = league_info return my_movies
def my_movies(user_info): my_movies = OrderedDict() db = InteractWithUsersDb() movie_db = InteractWithMovieDb() id = db.get_user_info(user_info["name"])[0][0] leagues = movie_db.get_users_leagues(str(id)) for league in leagues: movie_data = movie_db.get_users_movie_info_from_league(league, id) totals = GetMyMovies(league, id) totals.get_my_movie_gross() movie_data.append(totals.get_all_my_totals()) my_movies[league] = movie_data return my_movies
def create_league(league_name, league_owner, start_date, end_date, end_record): print 'hi' db = InteractWithMovieDb() udb = InteractWithUsersDb() uid = udb.get_user_info(league_owner)[0][0] print 'hi1' league_name = league_name.replace(" ", "_") print 'hi2' print league_name, uid, str(start_date), str(end_date), str(end_record) db.add_league_to_leagues(league_name, uid, str(start_date), str(end_date), str(end_record)) print 'hi3' db.create_league_movie_table(league_name) print 'hi4' db.create_league_table(league_name) print 'hi5' db.create_league_user_table(league_name) print 'hi6' db.add_user_to_league_user(league_name, int(uid)) print 'hi7' # populate league_movies #gml = GetMovieList(league_name) #gml.get_date_range() tasks.get_date_range(league_name) print 'hi'
def my_leagues_rankings(user_info): my_movies = OrderedDict() db = InteractWithUsersDb() movie_db = InteractWithMovieDb() id = db.get_user_info(user_info["name"])[0][0] leagues = movie_db.get_users_leagues(str(id)) for league in leagues: winner = ['No Winner', 0] me = [user_info["name"], 0] league_info = movie_db.get_league_totals_for_all_users(league) for i in league_info: entry = Scripts.convert_dollar_to_int(league_info[i]) if entry > winner[1]: winner = [i, entry] if i == user_info["name"]: me = [i, entry] if me == winner: me[1] = Scripts.convert_int_to_dollar(me[1]) my_movies[league] = [me] elif me != winner: winner[1] = Scripts.convert_int_to_dollar(winner[1]) me[1] = Scripts.convert_int_to_dollar(me[1]) my_movies[league] = [winner, me] return my_movies
def google_signup(): db = InteractWithUsersDb() access_token = session.get('access_token') if access_token is None: return redirect(url_for('login')) access_token = access_token[0] from urllib2 import Request, urlopen, URLError headers = {'Authorization': 'OAuth ' + access_token} req = Request('https://www.googleapis.com/oauth2/v1/userinfo', None, headers) try: res = urlopen(req) except URLError, e: if e.code == 401: # Unauthorized - bad token session.pop('access_token', None) return redirect(url_for('login')) return res.read()
def get_leagues(user): db = InteractWithMovieDb() udb = InteractWithUsersDb() uid = udb.get_user_info(user)[0][0] return db.get_users_leagues(uid)