def __init__(self, league): self.league = league self.db = InteractWithMovieDb() self.baseURL = 'http://www.boxofficemojo.com/schedule/?view=&release=&date=%s-%s' \ '&showweeks=5&p=.htm' self.start_date = None self.end_date = None
def get_all_league_movies(self, league, json=False): db = InteractWithMovieDb() list_ = db.get_league_movie_list(league) if json: return list_, self.jsonify(list_) else: return list_
def __init__(self, league_name, league_owner, start_date, end_date, end_record): self.league_name = league_name self.league_owner = league_owner self.start_date = start_date self.end_date = end_date self.end_record = end_record self.db = InteractWithMovieDb()
def __init__(self, league, user): self.league = league self.user = user self.db = InteractWithMovieDb() self.args = self.get_my_movies() self.foreign_gross = [] self.domestic_gross = [] self.worldwide_gross = []
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 add_user_movie_to_league_list(league, values): data = [] print values values = values.split(',') values = [values[idx:idx+2] for idx in range(0, len(values), 2)] for l in values: data.append("("+','.join(l)+")") data = ', '.join(data) print data db = InteractWithMovieDb() db.add_user_movie_to_league_list(league, data)
def get_movie_by_month(league, start_date, end_date, year, month): db = InteractWithMovieDb() start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d').date() end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d').date() #todo add baseurl to app config baseURL = 'http://www.boxofficemojo.com/schedule/?view=&release=&date=%s-%s' \ '&showweeks=5&p=.htm' url = baseURL % (year, month) html = urllib2.urlopen(url) soup = BeautifulSoup(html, "html.parser") for a in soup.find_all('a', href=True)[3:]: if 'movies' in a['href']: movie_id = a['href'].split('=')[1] movie_id = urllib.urlencode({'': movie_id})[1:-4] try: movie = GetMovieData(str(movie_id)) movie.find_movie_info() movie.find_movie_gross() movie_title, foreign_gross, domestic_gross, worldwide_gross, release_date = movie.get_movie_data_strings( ) movie_title = Scripts.fix_unicode(movie_title) movie_title = Scripts.fix_acii(movie_title) if foreign_gross == 'n/a': foreign_gross = None if domestic_gross == 'n/a': domestic_gross = None if worldwide_gross == 'n/a': worldwide_gross = None if worldwide_gross is None: s = Scripts() _foreign = s.convert_dollar_to_int(foreign_gross) _domestic = s.convert_dollar_to_int(domestic_gross) worldwide_gross = sum([_foreign, _domestic]) worldwide_gross = s.convert_int_to_dollar(worldwide_gross) date = release_date.split("-") if start_date < datetime.date(int(date[0]), int(date[1]), int(date[2])) < end_date: if db.check_movie_exists(league, movie_id) == 0: print 'Adding %s to db' % movie_title db.add_movie_to_db(league, movie_title, movie_id, foreign_gross, domestic_gross, worldwide_gross, release_date) else: print 'Updating %s in db' % movie_title db.update_movie_gross(league, foreign_gross, domestic_gross, worldwide_gross, movie_id) else: print "Not in range, %s" % release_date except Exception, e: print e print movie_id
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(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 get_full_league_stats(league): movie_db = InteractWithMovieDb() rtn_list = {} for i in movie_db.get_league_users_and_movies(league): lst = list(i) for a in lst: if isinstance(a, datetime.date): lst[lst.index(a)] = a.strftime('%Y-%m-%d') if lst[0] not in rtn_list: rtn_list[lst[0]] = [] rtn_list[lst[0]].append(lst[1:]) else: rtn_list[lst[0]].append(lst[1:]) return rtn_list
def get_date_range(league): db = InteractWithMovieDb() dates = db.get_league_info(league) start_date = dates[0][0] start_date_serial = start_date.isoformat() end_date = dates[0][1] end_date_serial = end_date.isoformat() dates_list = OrderedDict( ((start_date + timedelta(_)).strftime(r"%Y-%m"), None) for _ in xrange((end_date - start_date).days)).keys() if start_date.month != end_date.month and start_date.year != end_date.year: dates_list.append(end_date.strftime(r"%Y-%m")) for date in dates_list: year, month = date.split('-') get_movie_by_month(league, start_date_serial, end_date_serial, year, month)
def main_sub(league, movie): db = InteractWithMovieDb() movie_id = movie movie = GetMovieData(movie_id) movie_title, foreign_gross, domestic_gross, worldwide_gross, release_date = movie.get_update_info( ) if foreign_gross == 'n/a': foreign_gross = None if domestic_gross == 'n/a': domestic_gross = None if worldwide_gross == 'n/a': worldwide_gross = None if worldwide_gross is None: s = Scripts() _foreign = s.convert_dollar_to_int(foreign_gross) _domestic = s.convert_dollar_to_int(domestic_gross) worldwide_gross = sum([_foreign, _domestic]) worldwide_gross = s.convert_int_to_dollar(worldwide_gross) print 'Updating %s in %s' % (movie_title, league[0]) db.update_movie_gross(league[0], foreign_gross, domestic_gross, worldwide_gross, movie_id)
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 get_all_movies_for_league(self, league): movie_db = InteractWithMovieDb() movies = movie_db.get_all_movies_for_league(league) print movies return movies
def main(): db = InteractWithMovieDb() leagues = db.get_leagues_to_update() for league in leagues: for movie in db.get_movies_to_update(league[0]): main_sub(league, movie[0])
def get_leagues(user): db = InteractWithMovieDb() udb = InteractWithUsersDb() uid = udb.get_user_info(user)[0][0] return db.get_users_leagues(uid)
def __init__(self, user): self.user = user # users json self.db = InteractWithMovieDb()