parameters: (user_id, bot_id, storage_dir, is_compile=False)
docstring: Download and store a bot's zip file locally
  
      Checks the file's checksum to make sure the file was downloaded properly
docstring_summary: Download and store a bot's zip file locally
docstring_tokens: Download and store a bot s zip file locally
function: def storeBotLocally(user_id, bot_id, storage_dir, is_compile=False):
      """
      Download and store a bot's zip file locally
  
      Checks the file's checksum to make sure the file was downloaded properly
      """
  
      iterations = 0
      while iterations < 100:
          url = MANAGER_URL + "botFile?user_id={}&bot_id={}".format(user_id, bot_id)
          if is_compile:
              url += "&compile=1"
  
          print("Bot file url %s\n" % url)
  
          remote_zip = urllib.request.urlopen(url)
          zip_filename = remote_zip.headers.get('Content-disposition').split("filename")[1]
          zip_path = os.path.join(storage_dir, zip_filename)
          if os.path.exists(zip_path):
              os.remove(zip_path)
  
          remote_zip_contents = remote_zip.read()
          remote_zip.close()
  
          local_zip = open(zip_path, "wb")
          local_zip.write(remote_zip_contents)
          local_zip.close()
  
          content_hash = md5(remote_zip_contents).hexdigest()
          remote_hash = getBotHash(user_id, bot_id, is_compile)
          if content_hash != remote_hash:
              iterations += 1
              continue
  
          return zip_path
  
      raise RuntimeError("Could not download bot with valid hash, aborting")
function_tokens: def storeBotLocally ( user_id , bot_id , storage_dir , is_compile = False ) : iterations = 0 while iterations < 100 : url = MANAGER_URL + "botFile?user_id={}&bot_id={}" . format ( user_id , bot_id ) if is_compile : url += "&compile=1" print ( "Bot file url %s\n" % url ) remote_zip = urllib . request . urlopen ( url ) zip_filename = remote_zip . headers . get ( 'Content-disposition' ) . split ( "filename" ) [ 1 ] zip_path = os . path . join ( storage_dir , zip_filename ) if os . path . exists ( zip_path ) : os . remove ( zip_path ) remote_zip_contents = remote_zip . read ( ) remote_zip . close ( ) local_zip = open ( zip_path , "wb" ) local_zip . write ( remote_zip_contents ) local_zip . close ( ) content_hash = md5 ( remote_zip_contents ) . hexdigest ( ) remote_hash = getBotHash ( user_id , bot_id , is_compile ) if content_hash != remote_hash : iterations += 1 continue return zip_path raise RuntimeError ( "Could not download bot with valid hash, aborting" )