<jupyter_start><jupyter_text>Advanced Modules Exercise SolutionsIt's time to test your new skills, this project will combine multiple skills sets, including unzipping files with Python, using os module to automatically search through lots of files. Your GoalThere is a .zip file called  Unzipping the FileWe can easily use the shutil library to extract and unzip the contents of the .zip file<jupyter_code>import shutil
shutil.unpack_archive('Mission_Orange_Files/unzip_me_for_instructions.zip','Mission_Orange_Files/extracted_content','zip')<jupyter_output><empty_output><jupyter_text>Regular Expression to Find the LinkThere are many approaches to take here, but since we know we are looking for a website, there should be a www. somewhere in the string. So let's search for strings where the www. is somewhere there. Other approaches could have included searching for .coms, .orgs, or other endings, or trying to search for http or https. [More info on other possible regex patterns for domains](https://stackoverflow.com/questions/2490310/regular-expression-for-checking-website-url).<jupyter_code>import re
# Any word that starts with https:// and for the rest of the word one or more, \w dots, slashes, ? , =, _ or -
pattern = r'https://[-?_=./\w]+'
test = "here is a website https://drive.google.com/open?id=1tWJBFrSQL06qTZgkohs4t_a5Cu84AheLo and https://docs.google.com/document/d/Q-DcxM17nJm_El0aGsNnY7FajaogRviwja/edit let's see if we can find it."
re.findall(pattern,test)
def search(file,pattern= r'https://[-?_=./\w]+'):
    f = open(file,'r')
    text = f.read()
    
    if re.search(pattern,text):
        return re.search(pattern,text)
    else:
        return ''<jupyter_output><empty_output><jupyter_text>OS Walk through the Files to Get the LinkNow that we have a basic function to search through the text of the files, let's perform an os.walk through the unzipped directory to find the links hidden somewhere in one of the text files.<jupyter_code>import os
results = []
for folder , sub_folders , files in os.walk(os.getcwd()+"\\Mission_Orange_Files\\extracted_content"):
    
    for f in files:
        full_path = folder+'\\'+f
         
        results.append(search(full_path)) 
for r in results:
    if r != '':
        print(r.group())<jupyter_output>https://drive.google.com/open?id=1tWJBFrSQL06qTZgkohs4t_a5Cu84AheLo
https://docs.google.com/document/d/1tWJBFrSQL06qTZgkohs4t_a5Cu84AheLocWTXQ-DcxM/edit?usp=sharing
https://drive.google.com/file/d/17nJm_El0aGsNvaMZtnY7FajaogRviwja/view?usp=sharing
{'fraction_non_alphanumeric': 0.09849683544303797, 'fraction_numerical': 0.014240506329113924, 'mean_word_length': 4.657718120805369, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 9, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '306270', 'license': 'MIT', 'n_tokens_mistral': 860, 'n_tokens_neox': 820, 'n_words': 249, 'path': '4-assets/BOOKS/Jupyter-Notebooks/Overflow/09-Advanced-Modules-Exercise-Solutions-checkpoint.ipynb', 'repo_name': 'impastasyndrome/Lambda-Resource-Static-Assets', 'size': '2528'}