def solve_challenge(df: 'dataframe', index: int) -> bool: """Opens challenge url & file for user to complete. Args: df (dataframe): dataframe containing information index (int): Row to read Returns: bool: if challenge was solved. """ logging.info(f"Chall info for: {index}") chall_info = df.iloc[index] logging.info(f"INFO: {chall_info}") ## Open url url = chall_info.loc[CHALLENGE_INFO_CSV_HEADERS[-4]] + FULLSCREEN_URL logging.debug(f"url: {url}") print(f"Webpage: {url}") WebPageInfo(url, scrape= False) ## Solution file solution_url = url = chall_info[CHALLENGE_INFO_CSV_HEADERS[-3]] sol_filename = solution_url[ solution_url.rfind('/') + 1:] logging.info(f"sol filename {sol_filename}") print(f"File: {sol_filename}") os.system(sol_filename) return
def get_subdomain_dirname(subdomain_num: int, total_subdomains: int, subdomain: str) -> str: """Returns directory name for subdirectory. Args: subdomain_num (int): Subdomain number total_subdomains (int): Total number of subdomains subdomain (str): Subdomain name. Returns: str: directory name """ logging.debug( f"Subdir info: {subdomain_num}, {total_subdomains}, {subdomain}") subdomain_num, total_subdomains = str(subdomain_num), str(total_subdomains) if total_subdomains == '1': # specific challenges, e.g., 10 days of stats subdomain_num = '' else: while len(subdomain_num) < len(total_subdomains): subdomain_num = '0' + subdomain_num subdomain_num += '_' subdir_name = subdomain_num + subdomain.strip().lower().replace(' ', '_') logging.debug(f"subdir - {subdir_name}") return subdir_name
def get_subdomain_dirs(domain_dir) -> list: """Returns list of subdomain dirs. Args: domain_dir ([type]): Domain directory. Returns: list: Returns list of subdomain directories. """ not_subdirs = ('.ipynb_checkpoints') p = Path(domain_dir) subdirs = [] for f in p.glob('**/*'): if f.is_dir(): dir_name = get_dirname(f) logging.debug(f"Check dir - {dir_name}") if dir_name not in not_subdirs: subdirs.append(f) logging.debug("DIR - Subdomain dirs:" + '\n-'.join([str(d) for d in subdirs])) return subdirs
def make_file(filename: str, name: str, url: str) -> None: """Checks if file exists. If it doesn't exist, creates file.""" exists = os.path.exists(filename) logging.debug(f"{filename} - {exists}") if os.path.exists(filename): return logging.debug(f"FILE - Creating {filename}") with open(filename, 'w') as outfile: outfile.write(f"Solution to [{name}]({url})") return
def get_dirname(dir_path: Path) -> str: """returns directory name from windows filepath Args: dir_path (Path): path oject Returns: str: directory name """ dirname = str(dir_path.resolve()) dirname = dirname[dirname.rfind('\\') + 1:] logging.debug(f"Dirname {dirname} from {dir_path}") return dirname
def update_github(home_dir: object, commit_msg: str) -> None: """Updates github directory. Args: home_dir (object): home dir pathlib commit_msg (str): Commit message """ repo = Repo(home_dir) repo.git.add(update=True) repo.index.commit(commit_msg) logging.debug(f"Committing: {commit_msg}") origin = repo.remote(name='origin') origin.push() logging.debug("Pushed to repo.")
def get_domain_dirs(home_dir: object) -> list: """Returns list of domain directories. Args: home_dir (object): Home directory Returns: list: List of domain directories """ domain_dirs = [] for d in problem_domains: domain_dir = home_dir / d.name domain_dirs.append(domain_dir) logging.debug("DIR - Domain dirs:" + '\n-'.join([str(d) for d in domain_dirs])) return domain_dirs
def locate_challenge(df: 'dataframe', last_chall_index: int, flag_review: bool) -> Tuple[bool, int]: """Returns boolean indicating if challenge located & index of challenge information Args: df (dataframe): dataframe of challenge inforamtion Returns: Tuple[bool, int]: Challenge located, index of challenge information """ if flag_review: df = df.sample(frac=1).reset_index(drop=True) for index, row in df.iterrows(): logging.debug(f"CHECK - Index {index}") if ( row[CHALLENGE_INFO_CSV_HEADERS[-1]] and ## TODO row[CHALLENGE_INFO_CSV_HEADERS[-2]] == flag_review and ## Completed = flag_review index != last_chall_index ): logging.info(f"FOUND - challenge at {index}") return_index = row[CHALLENGE_INFO_CSV_HEADERS[0]] if flag_review else index return (True, return_index) return (False, None)
def get_chall_name(df: 'dataframe', index: int) -> str: """Returns challenge name.""" chall_info = df.iloc[index] name = ' '.join([str(index + 1), '-', chall_info.loc[CHALLENGE_INFO_CSV_HEADERS[1]]]) logging.debug(f"Chall name {name}") return name