<s> import os <EOL> import os . path <EOL> import shutil <EOL> import json <EOL> import api <EOL> import api . common <EOL> import api . config <EOL> db = api . common . db_conn ( ) <EOL> db . problems . remove ( { } ) <EOL> problem_dir = "<STR_LIT>" <EOL> load_dir = api . config . basedir + "<STR_LIT>" <EOL> categories = os . listdir ( load_dir ) <EOL> if os . path . exists ( problem_dir ) : <EOL> shutil . rmtree ( problem_dir ) <EOL> os . makedirs ( problem_dir ) <EOL> for category in categories : <EOL> category_count = <NUM_LIT:0> <EOL> problem_dirs = os . listdir ( load_dir + os . sep + category ) <EOL> for problem in problem_dirs : <EOL> path = load_dir + os . sep + category + os . sep + problem + os . sep <EOL> try : <EOL> data = json . loads ( open ( path + problem + "<STR_LIT>" ) . read ( ) ) <EOL> data [ "<STR_LIT>" ] = <NUM_LIT:0> <EOL> db . problems . insert ( data ) <EOL> category_count += <NUM_LIT:1> <EOL> if os . path . exists ( path + "<STR_LIT>" ) and os . path . isdir ( path + "<STR_LIT>" ) : <EOL> target = problem_dir + os . sep + problem <EOL> shutil . copytree ( path + "<STR_LIT>" , target ) <EOL> except Exception as e : <EOL> print ( "<STR_LIT>" + problem + "<STR_LIT>" + str ( e ) + "<STR_LIT:)>" ) <EOL> print ( "<STR_LIT>" % ( category , category_count ) ) <EOL> submissions = db . submissions . find ( { "<STR_LIT>" : True } ) <EOL> problems = db . problems . find ( { } ) <EOL> solved = { } <EOL> for submission in submissions : <EOL> for problem in problems : <EOL> if problem [ "<STR_LIT>" ] == submission [ "<STR_LIT>" ] : <EOL> if problem [ "<STR_LIT>" ] in solved : <EOL> solved [ problem [ "<STR_LIT>" ] ] += <NUM_LIT:1> <EOL> else : <EOL> solved [ problem [ "<STR_LIT>" ] ] = <NUM_LIT:1> <EOL> break <EOL> for pid in solved : <EOL> db . problems . update_one ( { "<STR_LIT>" : pid } , { "<STR_LIT>" : { "<STR_LIT>" : solved [ pid ] } } ) <EOL> db . e_problems . remove ( { } ) <EOL> eastereggs = json . loads ( open ( api . config . basedir + "<STR_LIT>" ) . read ( ) ) <EOL> db . e_problems . insert_many ( eastereggs ) <EOL> print ( "<STR_LIT>" ) </s>
