def main():
logging.basicConfig(filename='logs/games.log',level=logging.ERROR, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p')
config=json.loads(open('config.json').read())
command_line_args = sys.argv
dates = utils.validate_dates(command_line_args)
start_date = dates[0]
end_date = dates[1]
username = config['username']
password = config['password']
host = config['host']
database = config['database']
engine = create_engine('mysql://'+username+':'+password+'@'+host+'/'+database)
DBSession = scoped_session(sessionmaker(autoflush=True,autocommit=False,bind=engine))
game_ids = []
for dt in rrule(DAILY, dtstart=start_date, until=end_date):
date_response = utils.get_scoreboard_response_for_date(dt.strftime("%m/%d/%Y"))
date_data = utils.get_array_of_dicts_from_response(date_response, constants.SCOREBOARD_DATA_INDEX)
for game_data in date_data:
game_ids.append(game_data['GAME_ID'])
if len(game_ids) > 0:
game_data_queue = Queue()
# Create worker threads
for x in range(8):
game_worker = game.GameWorker(game_data_queue, DBSession)
# Setting daemon to True will let the main thread exit even though the workers are blocking
game_worker.daemon = True
game_worker.start()
# Put the tasks into the queue as a tuple
for game_id in game_ids:
season = utils.get_season_from_game_id(game_id)
season_type = utils.get_season_type_from_game_id(game_id)
if season_type != None:
game_data_queue.put((game_id, season, season_type))
# Causes the main thread to wait for the queue to finish processing all the tasks
game_data_queue.join()
DBSession.remove()
get_all_game_stats_for_date_range.py 文件源码
python
阅读 23
收藏 0
点赞 0
评论 0
评论列表
文章目录