├── Module 1 ├── Assignments │ ├── Working with Python Scripts-LAB.pdf │ ├── Working with Python Scripts-LAB.png │ ├── coursera.org-Qwiklabs Assessment Working with Python Scripts.pdf │ ├── coursera.org-Qwiklabs Assessment Working with Python Scripts.png │ └── solution │ │ ├── health_checks.py │ │ └── network.py ├── Quiz │ ├── Automation │ │ ├── quiz_module_1.pdf │ │ ├── quiz_module_1.png │ │ └── quiz_module_1_afterSubmit.pdf │ ├── Getting Ready for Python │ │ ├── quiz_module_1.pdf │ │ ├── quiz_module_1.png │ │ └── quiz_module_1_afterSubmit.pdf │ └── Running Python Locally │ │ ├── quiz_module_1.pdf │ │ ├── quiz_module_1.png │ │ └── quiz_module_1_afterSubmit.pdf ├── Reading │ ├── Automating Tasks Through Programming │ │ ├── coursera.org-Is it worth the time.pdf │ │ └── xkcd_com_1205_.pdf │ ├── Course Introduction │ │ ├── automatetheboringstuff_com_.pdf │ │ └── coursera.org-Welcome to the Course.pdf │ ├── Getting Ready for Python │ │ ├── coursera.org-Pointers for Getting Your Environment Setup.pdf │ │ ├── devblogs_microsoft_com_python_python-in-the-windows-10-may-2019-update_.pdf │ │ ├── en_wikipedia_org_wiki_History_of_Unix.pdf │ │ ├── packaging_python_org_guides_installing-using-pip-and-virtual-environments_.pdf │ │ ├── realpython_com_installing-python_.pdf │ │ ├── www_digitalocean_com_community_tutorials_how-to-install-python-3-and-set-up-a-local-programming-environment-on-windows-10.pdf │ │ └── www_digitalocean_com_community_tutorials_package-management-basics-apt-yum-dnf-pkg.pdf │ ├── Running Python Locally │ │ ├── coursera.org-Setting up Your Environment.pdf │ │ ├── coursera.org-Setting up Your Environment.png │ │ ├── realpython_com_python-ides-code-editors-guide_#pycharm.pdf │ │ ├── www_datacamp_com_community_tutorials_data-science-python-ide.pdf │ │ └── www_softwaretestinghelp_com_python-ide-code-editors_.pdf │ └── coursera.org-How to Log in to Qwiklabs.pdf ├── notesImages │ ├── areas_py_content_cat_image15.png │ ├── atom_code_completion_image19.png │ ├── atom_code_completion_ret_image20.png │ ├── bit_rot_example_image23.png │ ├── c_compile_diag_image10.png │ ├── compiler_diag_image8.png │ ├── execute_w_shebang_image14.png │ ├── health_check_script_output_image27.png │ ├── import_areas_py_module_image16.png │ ├── interpreter_diag_image9.png │ ├── kernel_example_diag_image1.png │ ├── manual_onboarding_sample_img_image21.png │ ├── psutil_cpupercent_example_image26.png │ ├── python_interactive_interpreter_image12.png │ ├── python_interpreter_diag_image11.png │ ├── python_version_sample1_image3.png │ ├── python_version_sample2_image4.png │ ├── python_version_sample3_image5.png │ ├── python_version_sample4_image6.png │ ├── python_version_sample5_image7.png │ ├── request_module_submodule_image17.png │ ├── shebang_sample_image13.png │ ├── shutil_diskusage_example_image24.png │ ├── shutil_diskusage_freedisk_image25.png │ ├── task_automation_formula_image22.png │ ├── user_space_example_diag_image2.png │ ├── vim_syntax_highlight_image18.png │ └── vm_network_diagram_image28.png └── notes_module_1.md ├── Module 2 ├── Assignments │ ├── Model Review │ │ ├── Handling Files.pdf │ │ ├── Handling Files.png │ │ ├── Solution │ │ │ ├── data │ │ │ │ ├── employees.csv │ │ │ │ ├── report.txt │ │ │ │ └── test_report.txt │ │ │ └── scripts │ │ │ │ └── generate_report.py │ │ └── coursera.org-Qwiklabs Assessment Handling Files.pdf │ └── Reading and Writing Files │ │ ├── C2M2L1_Reading_And_Writing_Files.ipynb │ │ ├── C2M2L1_Reading_And_Writing_Files.md │ │ ├── C2M2L1_Reading_And_Writing_Files.py │ │ ├── C2M2L1_Reading_And_Writing_Files.tex │ │ └── guests.txt ├── Quiz │ ├── Managing Files & Directories │ │ ├── quiz_module_2.pdf │ │ ├── quiz_module_2.png │ │ └── quiz_module_2_afterSubmit.pdf │ └── Reading & Writing CSV Files │ │ ├── quiz_module_2.pdf │ │ ├── quiz_module_2.png │ │ └── quiz_module_2_afterSubmit.pdf ├── Reading │ ├── Managing Files and Directories │ │ ├── coursera.org-Files and Directories Cheat-Sheet.pdf │ │ ├── docs_python_org_3_library_os_html.pdf │ │ ├── docs_python_org_3_library_os_path_html.pdf │ │ └── en_wikipedia_org_wiki_Unix_time.pdf │ ├── Reading and Writing CSV Files │ │ ├── CSV Files Cheat Sheet.pdf │ │ ├── CSV Files Cheat Sheet.png │ │ ├── docs_python_org_3_library_csv_html.pdf │ │ └── realpython_com_python-csv_.pdf │ └── Reading and Writing Files │ │ ├── coursera.org-Reading and Writing Files Cheat-Sheet.pdf │ │ └── docs_python_org_3_library_functions_html#open.pdf ├── notesImages │ ├── csv_example_image9.png │ ├── csv_reader_example_image10.png │ ├── csv_reader_file_gen_cat_image11.png │ ├── dict_reader_example_image13.png │ ├── file_modes_example_image7.png │ ├── file_open_list_sort_example_image6.png │ ├── file_open_read_example_image2.png │ ├── file_open_readline_example_image1.png │ ├── file_open_strip_upper_example_image5.png │ ├── file_open_upper_example_image4.png │ ├── file_open_with_block_image3.png │ ├── file_os_remove_image8.png │ ├── sample_csv_file_image12.png │ └── write_file_csv_mod_image14.png └── notes_module_2.md ├── Module 3 ├── Assignments │ └── Model Review │ │ ├── Qwiklabs Assessment: Working with Regular Expressions.pdf │ │ ├── Qwiklabs Assessment: Working with Regular Expressions.png │ │ ├── Solution │ │ ├── data │ │ │ ├── updated_user_emails.csv │ │ │ └── user_emails.csv │ │ └── scripts │ │ │ └── script.py │ │ ├── coursera.org-Qwiklabs Assessment Working with Regular Expressions.pdf │ │ └── googlecoursera.qwiklabs.com-Working with Regular Expressions.pdf ├── Quiz │ ├── Advanced Regular Expressions │ │ ├── quiz_module_3.pdf │ │ ├── quiz_module_3.png │ │ └── quiz_module_3_afterSubmit.pdf │ ├── Basic Regular Expressions │ │ ├── quiz_module_3.pdf │ │ ├── quiz_module_3.png │ │ └── quiz_module_3_afterSubmit.pdf │ └── Regular Expressions │ │ ├── quiz_module_3.pdf │ │ ├── quiz_module_3.png │ │ └── quiz_module_3_afterSubmit.pdf ├── Reading │ ├── Advanced Regular Expressions │ │ ├── coursera.org-Advanced Regular Expressions Cheat-Sheet.pdf │ │ └── regexcrossword_com_.pdf │ └── Basic Regular Expressions │ │ ├── Regular Expressions Cheat-Sheet.pdf │ │ ├── Regular Expressions Cheat-Sheet.png │ │ ├── docs_python_org_3_howto_regex_html#greedy-versus-non-greedy.pdf │ │ ├── docs_python_org_3_howto_regex_html.pdf │ │ └── docs_python_org_3_library_re_html.pdf ├── notesImages │ ├── error_result_1_image12.png │ ├── grep_pattern_caret_image5.png │ ├── grep_pattern_dollar_image6.png │ ├── grep_pattern_dot_image4.png │ ├── grep_python_i_dict_words_image3.png │ ├── grep_thon_dict_words_image2.png │ ├── log_entry_example_image1.png │ ├── output_search_re_image7.png │ ├── output_search_re_image8.png │ ├── output_search_re_image9.png │ ├── rearrange_name_example_image10.png │ └── repetition_qualifiers_example_image11.png └── notes_module_3.md ├── Module 4 ├── Assignments │ └── Module Review │ │ ├── Qwiklabs Assessment: Working with Log Files.pdf │ │ ├── Qwiklabs Assessment: Working with Log Files.png │ │ ├── Solution │ │ ├── data │ │ │ ├── errors_found.log │ │ │ └── fishy.log │ │ └── scripts │ │ │ └── find_error.py │ │ ├── coursera.org-Qwiklabs Assessment Working with Log Files.pdf │ │ ├── coursera.org-Qwiklabs Assessment Working with Log Files.png │ │ └── googlecoursera.qwiklabs.com-Working with Log Files.pdf ├── Quiz │ ├── Data Streams │ │ ├── quiz_module_4.pdf │ │ ├── quiz_module_4.png │ │ └── quiz_module_4_afterSubmit.pdf │ ├── Processing Log Files │ │ ├── quiz_module_4.pdf │ │ ├── quiz_module_4.png │ │ └── quiz_module_4_afterSubmit.pdf │ └── Python Subprocesses │ │ ├── quiz_module_4.pdf │ │ ├── quiz_module_4.png │ │ └── quiz_module_4_afterSubmit.pdf ├── Reading │ ├── Data Streams │ │ ├── More About Input Functions.pdf │ │ ├── More About Input Functions.png │ │ ├── docs_python_org_2_library_functions_html#input.pdf │ │ ├── docs_python_org_3_library_functions_html#input.pdf │ │ └── useful_links.md │ └── Python Subprocesses │ │ ├── Python Subprocesses Cheat Sheet.png │ │ ├── coursera.org-Python Subprocesses Cheat Sheet.pdf │ │ └── docs_python_org_3_library_subprocess_html.pdf ├── Scipts │ ├── check_cron.py │ ├── check_cron_upd.py │ ├── create_file.py │ ├── hello.py │ ├── myapp.py │ ├── parameters.py │ ├── seconds.py │ └── variables.py ├── notesImages │ ├── PATH_var_output_image7.png │ ├── advance_subprocess_management_image18.png │ ├── check_cron_upd_output_image25.png │ ├── check_program_status_failed_image13.png │ ├── check_program_status_success_image12.png │ ├── count_data_using_dict_image24.png │ ├── cron_check_output_image23.png │ ├── env_cmd_output_image6.png │ ├── env_var_using_python_image8.png │ ├── env_var_using_python_image9.png │ ├── input_method_example_image1.png │ ├── input_method_example_output_time_converter_image3.png │ ├── input_method_example_time_converter_image2.png │ ├── io_stream_diagram_image4.png │ ├── io_stream_example_image5.png │ ├── log_diag_image20.png │ ├── log_files_diag_image19.png │ ├── parent_child_subprocess_image17.png │ ├── python_sample_script_file_image15.png │ ├── python_sample_script_file_image16.png │ ├── python_sample_script_status_image14.png │ ├── sample_data_image21.png │ ├── sys_argv_list_example_noparam_image10.png │ ├── sys_argv_list_example_withparam_image11.png │ └── user_extract_regex_image22.png └── notes_module_4.md ├── Module 5 ├── Assignments │ ├── Errors and Exceptions │ │ ├── C2M5L4_Errors_and_Exceptions-V2.html │ │ ├── C2M5L4_Errors_and_Exceptions-V2.ipynb │ │ ├── C2M5L4_Errors_and_Exceptions-V2.md │ │ └── C2M5L4_Errors_and_Exceptions-V2.py │ ├── Module Review │ │ ├── Implementing Unit Testing.pdf │ │ ├── Implementing Unit Testing.png │ │ ├── Solution │ │ │ ├── data │ │ │ │ └── user_emails.csv │ │ │ └── scripts │ │ │ │ ├── emails.py │ │ │ │ └── emails_test.py │ │ └── googlecoursera.qwiklabs.com-Implementing Unit Testing.pdf │ └── Unit Tests │ │ ├── C2M5L2_Unit_Tests_and_Edge_Cases-V3.html │ │ ├── C2M5L2_Unit_Tests_and_Edge_Cases-V3.ipynb │ │ ├── C2M5L2_Unit_Tests_and_Edge_Cases-V3.md │ │ └── C2M5L2_Unit_Tests_and_Edge_Cases-V3.py ├── Quiz │ ├── Other Test Concepts │ │ ├── quiz_module_5.pdf │ │ ├── quiz_module_5.png │ │ └── quiz_module_5_afterSubmit.pdf │ └── Simple Tests │ │ ├── quiz_module_5.pdf │ │ ├── quiz_module_5.png │ │ └── quiz_module_5_afterSubmit.pdf ├── Reading │ ├── Errors and Exceptions │ │ ├── Handling Errors Cheat-Sheet.pdf │ │ ├── Handling Errors Cheat-Sheet.png │ │ ├── docs_python_org_2_reference_simple_stmts_html#the-assert-statement.pdf │ │ ├── docs_python_org_2_tutorial_errors_html#handling-exceptions.pdf │ │ ├── docs_python_org_3_library_exceptions_html#bltin-exceptions.pdf │ │ ├── docs_python_org_3_tutorial_errors_html#raising-exceptions.pdf │ │ ├── docs_python_org_3_tutorial_errors_html.pdf │ │ ├── doughellmann_com_blog_2009_06_19_python-exception-handling-techniques_.pdf │ │ └── stackoverflow_com_questions_5142418_what_is_the_use_of_asser.pdf │ ├── Other Test Concepts │ │ ├── coursera.org-More About Tests.pdf │ │ ├── landing_google_com_sre_sre-book_chapters_monitoring-distributed-systems_.pdf │ │ ├── landing_google_com_sre_sre-book_chapters_testing-reliability_.pdf │ │ ├── testing_googleblog_com_2007_10_performance-testing_html.pdf │ │ ├── testing_googleblog_com_2008_09_test-first-is-fun_08_html.pdf │ │ ├── www_guru99_com_exploratory-testing_html.pdf │ │ └── www_guru99_com_smoke-testing_html.pdf │ └── Unit Tests │ │ ├── coursera.org-Help with Jupyter Notebooks.pdf │ │ ├── coursera.org-Unit Test Cheat-Sheet.pdf │ │ └── docs_python_org_3_library_unittest_html#basic-example.pdf ├── Scipts │ ├── charfreq.py │ ├── rearrange.py │ ├── rearrange_test.py │ ├── validations.py │ └── validations_test.py ├── notesImages │ ├── code_bug_image12.png │ ├── code_bug_squash_image13.png │ ├── code_load_image15.png │ ├── code_smoke_image14.png │ ├── double_name_testcase_output_image7.png │ ├── empty_string_testcase_output_image5.png │ ├── empty_string_testcase_output_image6.png │ ├── integration_test_diag_image11.png │ ├── manual_testing_example_image2.png │ ├── one_name_testcase_output_image8.png │ ├── one_name_testcase_output_image9.png │ ├── output_unittest_example_image4.png │ ├── rearrange_unit_test_example_image3.png │ ├── sample_image_image1.png │ ├── test_driven_approach_image16.png │ ├── validations_after_assert_image22.png │ ├── validations_script_input_empty_list_image20.png │ ├── validations_script_input_len_1_list_image21.png │ ├── validations_script_input_number_image19.png │ ├── validations_script_other_params_image18.png │ ├── validations_script_raise_output_image17.png │ ├── validations_test_output_image23.png │ └── white_box_black_box_animation_image10.png └── notes_module_5.md ├── Module 6 ├── Assignments │ ├── Editing Files using Substrings.pdf │ ├── Editing Files using Substrings.png │ ├── Solution │ │ ├── data │ │ │ ├── janez_profile_11042019.doc │ │ │ ├── jdoe_contact_07292018.csv │ │ │ ├── jdoe_profile_07272018.doc │ │ │ ├── kwood_pic_04032017.jpg │ │ │ ├── kwood_profile_04022017.doc │ │ │ ├── list.txt │ │ │ └── pchow_pic_05162019.jpg │ │ └── scripts │ │ │ ├── changeJane.py │ │ │ ├── findJane.sh │ │ │ └── oldFiles.txt │ └── googlecoursera.qwiklabs.com-Editing Files using Substrings.pdf ├── Quiz │ ├── Advanced Bash Concepts │ │ ├── quiz_module_6.pdf │ │ ├── quiz_module_6.png │ │ └── quiz_module_6_afterSubmit.pdf │ ├── Bash Scripting │ │ ├── quiz_module_6.pdf │ │ ├── quiz_module_6.png │ │ └── quiz_module_6_afterSubmit.pdf │ └── Interacting with the Command Line Shell │ │ ├── quiz_module_6.pdf │ │ ├── quiz_module_6.png │ │ └── quiz_module_6_afterSubmit.pdf ├── Reading │ ├── Bash Scripting │ │ ├── coursera.org-Bash Scripting Resources.pdf │ │ ├── linuxconfig_org_bash-scripting-tutorial-for-beginners.pdf │ │ ├── ryanstutorials_net_bash-scripting-tutorial_.pdf │ │ └── www_shellscript_sh_.pdf │ └── Interacting with the Command Line Shell │ │ ├── coursera.org-Basic Linux Commands Cheat-Sheet.pdf │ │ └── coursera.org-Redirections Pipes and Signals.pdf ├── Scripts │ ├── capitalize.py │ ├── check-localhost.sh │ ├── fruits.sh │ ├── gather-information.sh │ ├── old_website │ │ ├── about.HTM │ │ ├── contact.HTM │ │ ├── footer.HTM │ │ ├── index.HTM │ │ └── rename.sh │ ├── random-exit.py │ ├── retry.sh │ ├── stdout_example.py │ ├── streams_err.py │ ├── toploglines.sh │ └── while.sh ├── notesImages │ ├── bash_python_os_diag_image42.png │ ├── check_localhost_script_output_image31.png │ ├── cmd_complex_pipes_image16.png │ ├── cmd_ls_less_pipes_image15.png │ ├── cmd_redirection_STDERR_example_image12.png │ ├── cmd_redirection_STDERR_output_example_image13.png │ ├── cmd_redirection_STDIN_example_image11.png │ ├── cmd_redirection_echo_STDOUT_example_image14.png │ ├── cmd_redirection_example_image8.png │ ├── cmd_redirection_output_append_example_image10.png │ ├── cmd_redirection_output_example_image9.png │ ├── cut_cmd_varlog_syslogs_example_image41.png │ ├── cut_command_example_image39.png │ ├── cut_command_example_image40.png │ ├── for_loop_example_image35.png │ ├── for_loop_rename_example_image36.png │ ├── for_loop_rename_example_image37.png │ ├── for_loop_rename_example_image38.png │ ├── gather_information_script_output_image24.png │ ├── gather_information_script_output_image26.png │ ├── glob_questionmark_example_image30.png │ ├── globs_star_example_image27.png │ ├── globs_star_example_image29.png │ ├── globs_star_prefix_example_image28.png │ ├── linux_cmd_cp_example_image2.png │ ├── linux_cmd_ls_la_example_image4.png │ ├── linux_cmd_mv_cp_example_image5.png │ ├── linux_cmd_output_image1.png │ ├── linux_cmd_rm_example_image6.png │ ├── linux_cmd_rmdir_example_image7.png │ ├── linux_cmd_touch_example_image3.png │ ├── ping_cmd_example_image19.png │ ├── ping_cmd_kill_example_image23.png │ ├── ping_cmd_rerun_fg_example_image22.png │ ├── ping_cmd_terminate_ctrlZ_example_image21.png │ ├── ping_cmd_terminate_example_image20.png │ ├── python_capitalize_example_image17.png │ ├── python_capitalize_example_image18.png │ ├── test_cmd_example_image32.png │ ├── test_cmd_example_image33.png │ ├── variable_assignment_error_image25.png │ └── while_loop_example_image34.png └── notes_module_6.md ├── Module 7 ├── Assignments │ ├── Final Project : Problem Statement Video │ │ ├── Help with Research and Planning │ │ │ ├── Help with Research and Planning.mp4 │ │ │ ├── subtitle.txt │ │ │ └── subtitles-en.vtt │ │ └── Project Problem Statement │ │ │ ├── Project Problem Statement.mp4 │ │ │ ├── subtitle.txt │ │ │ └── subtitles-en.vtt │ ├── Log Analysis Using Regular Expressions.pdf │ ├── Log Analysis Using Regular Expressions.png │ ├── Solution │ │ ├── data │ │ │ ├── error_message.csv │ │ │ ├── syslog.log │ │ │ ├── user_emails.csv │ │ │ └── user_statistics.csv │ │ ├── html │ │ │ ├── error_message.html │ │ │ ├── final_assignment.html │ │ │ └── user_statistics.html │ │ └── scripts │ │ │ ├── csv_to_html.py │ │ │ └── ticky_check.py │ └── googlecoursera.qwiklabs.com-Log Analysis Using Regular Expressions.pdf ├── Scripts │ ├── README.md │ ├── ticky_check_1.py │ ├── ticky_check_2.py │ └── ticky_check_3.py └── notes_module_7.md ├── README.md └── google_logo-preview.jpg /Module 1/Assignments/Working with Python Scripts-LAB.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Assignments/Working with Python Scripts-LAB.pdf -------------------------------------------------------------------------------- /Module 1/Assignments/Working with Python Scripts-LAB.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Assignments/Working with Python Scripts-LAB.png -------------------------------------------------------------------------------- /Module 1/Assignments/coursera.org-Qwiklabs Assessment Working with Python Scripts.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Assignments/coursera.org-Qwiklabs Assessment Working with Python Scripts.pdf -------------------------------------------------------------------------------- /Module 1/Assignments/coursera.org-Qwiklabs Assessment Working with Python Scripts.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Assignments/coursera.org-Qwiklabs Assessment Working with Python Scripts.png -------------------------------------------------------------------------------- /Module 1/Assignments/solution/health_checks.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import shutil 3 | import psutil 4 | from network import * 5 | 6 | def check_disk_usage(disk): 7 | """Verifies that there's enough free space on disk""" 8 | du = shutil.disk_usage(disk) 9 | free = du.free / du.total * 100 10 | return free > 20 11 | def check_cpu_usage(): 12 | """Verifies that there's enough unused CPU""" 13 | usage = psutil.cpu_percent(1) 14 | return usage < 75 15 | # If there's not enough disk, or not enough CPU, print an error 16 | if not check_disk_usage('/') or not check_cpu_usage(): 17 | print("ERROR!") 18 | elif check_localhost() and check_connectivity(): 19 | print("Everything ok") 20 | else: 21 | print("Network checks failed") 22 | -------------------------------------------------------------------------------- /Module 1/Assignments/solution/network.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import requests 4 | import socket 5 | 6 | def check_localhost(): 7 | localhost = socket.gethostbyname('localhost') 8 | return localhost == '127.0.0.1' 9 | 10 | def check_connectivity(): 11 | request = requests.get("http://www.google.com") 12 | return request.status_code == 200 13 | 14 | 15 | -------------------------------------------------------------------------------- /Module 1/Quiz/Automation/quiz_module_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Automation/quiz_module_1.pdf -------------------------------------------------------------------------------- /Module 1/Quiz/Automation/quiz_module_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Automation/quiz_module_1.png -------------------------------------------------------------------------------- /Module 1/Quiz/Automation/quiz_module_1_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Automation/quiz_module_1_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 1/Quiz/Getting Ready for Python/quiz_module_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Getting Ready for Python/quiz_module_1.pdf -------------------------------------------------------------------------------- /Module 1/Quiz/Getting Ready for Python/quiz_module_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Getting Ready for Python/quiz_module_1.png -------------------------------------------------------------------------------- /Module 1/Quiz/Getting Ready for Python/quiz_module_1_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Getting Ready for Python/quiz_module_1_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 1/Quiz/Running Python Locally/quiz_module_1.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Running Python Locally/quiz_module_1.pdf -------------------------------------------------------------------------------- /Module 1/Quiz/Running Python Locally/quiz_module_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Running Python Locally/quiz_module_1.png -------------------------------------------------------------------------------- /Module 1/Quiz/Running Python Locally/quiz_module_1_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Quiz/Running Python Locally/quiz_module_1_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Automating Tasks Through Programming/coursera.org-Is it worth the time.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Automating Tasks Through Programming/coursera.org-Is it worth the time.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Automating Tasks Through Programming/xkcd_com_1205_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Automating Tasks Through Programming/xkcd_com_1205_.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Course Introduction/automatetheboringstuff_com_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Course Introduction/automatetheboringstuff_com_.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Course Introduction/coursera.org-Welcome to the Course.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Course Introduction/coursera.org-Welcome to the Course.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Getting Ready for Python/coursera.org-Pointers for Getting Your Environment Setup.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Getting Ready for Python/coursera.org-Pointers for Getting Your Environment Setup.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Getting Ready for Python/devblogs_microsoft_com_python_python-in-the-windows-10-may-2019-update_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Getting Ready for Python/devblogs_microsoft_com_python_python-in-the-windows-10-may-2019-update_.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Getting Ready for Python/en_wikipedia_org_wiki_History_of_Unix.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Getting Ready for Python/en_wikipedia_org_wiki_History_of_Unix.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Getting Ready for Python/packaging_python_org_guides_installing-using-pip-and-virtual-environments_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Getting Ready for Python/packaging_python_org_guides_installing-using-pip-and-virtual-environments_.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Getting Ready for Python/realpython_com_installing-python_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Getting Ready for Python/realpython_com_installing-python_.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Getting Ready for Python/www_digitalocean_com_community_tutorials_how-to-install-python-3-and-set-up-a-local-programming-environment-on-windows-10.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Getting Ready for Python/www_digitalocean_com_community_tutorials_how-to-install-python-3-and-set-up-a-local-programming-environment-on-windows-10.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Getting Ready for Python/www_digitalocean_com_community_tutorials_package-management-basics-apt-yum-dnf-pkg.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Getting Ready for Python/www_digitalocean_com_community_tutorials_package-management-basics-apt-yum-dnf-pkg.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Running Python Locally/coursera.org-Setting up Your Environment.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Running Python Locally/coursera.org-Setting up Your Environment.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Running Python Locally/coursera.org-Setting up Your Environment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Running Python Locally/coursera.org-Setting up Your Environment.png -------------------------------------------------------------------------------- /Module 1/Reading/Running Python Locally/realpython_com_python-ides-code-editors-guide_#pycharm.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Running Python Locally/realpython_com_python-ides-code-editors-guide_#pycharm.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Running Python Locally/www_datacamp_com_community_tutorials_data-science-python-ide.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Running Python Locally/www_datacamp_com_community_tutorials_data-science-python-ide.pdf -------------------------------------------------------------------------------- /Module 1/Reading/Running Python Locally/www_softwaretestinghelp_com_python-ide-code-editors_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/Running Python Locally/www_softwaretestinghelp_com_python-ide-code-editors_.pdf -------------------------------------------------------------------------------- /Module 1/Reading/coursera.org-How to Log in to Qwiklabs.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/Reading/coursera.org-How to Log in to Qwiklabs.pdf -------------------------------------------------------------------------------- /Module 1/notesImages/areas_py_content_cat_image15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/areas_py_content_cat_image15.png -------------------------------------------------------------------------------- /Module 1/notesImages/atom_code_completion_image19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/atom_code_completion_image19.png -------------------------------------------------------------------------------- /Module 1/notesImages/atom_code_completion_ret_image20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/atom_code_completion_ret_image20.png -------------------------------------------------------------------------------- /Module 1/notesImages/bit_rot_example_image23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/bit_rot_example_image23.png -------------------------------------------------------------------------------- /Module 1/notesImages/c_compile_diag_image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/c_compile_diag_image10.png -------------------------------------------------------------------------------- /Module 1/notesImages/compiler_diag_image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/compiler_diag_image8.png -------------------------------------------------------------------------------- /Module 1/notesImages/execute_w_shebang_image14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/execute_w_shebang_image14.png -------------------------------------------------------------------------------- /Module 1/notesImages/health_check_script_output_image27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/health_check_script_output_image27.png -------------------------------------------------------------------------------- /Module 1/notesImages/import_areas_py_module_image16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/import_areas_py_module_image16.png -------------------------------------------------------------------------------- /Module 1/notesImages/interpreter_diag_image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/interpreter_diag_image9.png -------------------------------------------------------------------------------- /Module 1/notesImages/kernel_example_diag_image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/kernel_example_diag_image1.png -------------------------------------------------------------------------------- /Module 1/notesImages/manual_onboarding_sample_img_image21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/manual_onboarding_sample_img_image21.png -------------------------------------------------------------------------------- /Module 1/notesImages/psutil_cpupercent_example_image26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/psutil_cpupercent_example_image26.png -------------------------------------------------------------------------------- /Module 1/notesImages/python_interactive_interpreter_image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/python_interactive_interpreter_image12.png -------------------------------------------------------------------------------- /Module 1/notesImages/python_interpreter_diag_image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/python_interpreter_diag_image11.png -------------------------------------------------------------------------------- /Module 1/notesImages/python_version_sample1_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/python_version_sample1_image3.png -------------------------------------------------------------------------------- /Module 1/notesImages/python_version_sample2_image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/python_version_sample2_image4.png -------------------------------------------------------------------------------- /Module 1/notesImages/python_version_sample3_image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/python_version_sample3_image5.png -------------------------------------------------------------------------------- /Module 1/notesImages/python_version_sample4_image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/python_version_sample4_image6.png -------------------------------------------------------------------------------- /Module 1/notesImages/python_version_sample5_image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/python_version_sample5_image7.png -------------------------------------------------------------------------------- /Module 1/notesImages/request_module_submodule_image17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/request_module_submodule_image17.png -------------------------------------------------------------------------------- /Module 1/notesImages/shebang_sample_image13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/shebang_sample_image13.png -------------------------------------------------------------------------------- /Module 1/notesImages/shutil_diskusage_example_image24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/shutil_diskusage_example_image24.png -------------------------------------------------------------------------------- /Module 1/notesImages/shutil_diskusage_freedisk_image25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/shutil_diskusage_freedisk_image25.png -------------------------------------------------------------------------------- /Module 1/notesImages/task_automation_formula_image22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/task_automation_formula_image22.png -------------------------------------------------------------------------------- /Module 1/notesImages/user_space_example_diag_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/user_space_example_diag_image2.png -------------------------------------------------------------------------------- /Module 1/notesImages/vim_syntax_highlight_image18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/vim_syntax_highlight_image18.png -------------------------------------------------------------------------------- /Module 1/notesImages/vm_network_diagram_image28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 1/notesImages/vm_network_diagram_image28.png -------------------------------------------------------------------------------- /Module 2/Assignments/Model Review/Handling Files.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Assignments/Model Review/Handling Files.pdf -------------------------------------------------------------------------------- /Module 2/Assignments/Model Review/Handling Files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Assignments/Model Review/Handling Files.png -------------------------------------------------------------------------------- /Module 2/Assignments/Model Review/Solution/data/employees.csv: -------------------------------------------------------------------------------- 1 | Full Name, Username, Department 2 | Audrey Miller, audrey, Development 3 | Arden Garcia, ardeng, Sales 4 | Bailey Thomas, baileyt, Human Resources 5 | Blake Sousa, sousa, IT infrastructure 6 | Cameron Nguyen, nguyen, Marketing 7 | Charlie Grey, greyc, Development 8 | Chris Black, chrisb, User Experience Research 9 | Courtney Silva, silva, IT infrastructure 10 | Darcy Johnsonn, darcy, IT infrastructure 11 | Elliot Lamb, elliotl, Development 12 | Emery Halls, halls, Sales 13 | Flynn McMillan, flynn, Marketing 14 | Harley Klose, harley, Human Resources 15 | Jean May Coy, jeanm, Vendor operations 16 | Kay Stevens, kstev, Sales 17 | Lio Nelson, lion, User Experience Research 18 | Logan Tillas, tillas, Vendor operations 19 | Micah Lopes, micah, Development 20 | Sol Mansi, solm, IT infrastructure 21 | -------------------------------------------------------------------------------- /Module 2/Assignments/Model Review/Solution/data/report.txt: -------------------------------------------------------------------------------- 1 | Development:4 2 | Human Resources:2 3 | IT infrastructure:4 4 | Marketing:2 5 | Sales:3 6 | User Experience Research:2 7 | Vendor operations:2 8 | -------------------------------------------------------------------------------- /Module 2/Assignments/Model Review/Solution/data/test_report.txt: -------------------------------------------------------------------------------- 1 | Development:4 2 | Human Resources:2 3 | IT infrastructure:4 4 | Marketing:2 5 | Sales:3 6 | User Experience Research:2 7 | Vendor operations:2 8 | -------------------------------------------------------------------------------- /Module 2/Assignments/Model Review/Solution/scripts/generate_report.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import csv 4 | 5 | def read_employees(csv_file_location): 6 | csv.register_dialect('empDialect', skipinitialspace=True, strict=True) 7 | employee_file = csv.DictReader(open(csv_file_location), dialect = 'empDialect') 8 | employee_list = [] 9 | for data in employee_file: 10 | employee_list.append(data) 11 | return employee_list 12 | 13 | employee_list = read_employees('/home/student-02-087c8b510c92/data/employees.csv') 14 | #print(employee_list) 15 | 16 | 17 | def process_data(employee_list): 18 | department_list = [] 19 | for employee_data in employee_list: 20 | department_list.append(employee_data['Department']) 21 | 22 | department_data = {} 23 | for department_name in set(department_list): 24 | department_data[department_name] = department_list.count(department_name) 25 | return department_data 26 | 27 | dictionary = process_data(employee_list) 28 | print(dictionary) 29 | 30 | def write_report(dictionary, report_file): 31 | with open(report_file, "w+") as f: 32 | for k in sorted(dictionary): 33 | f.write(str(k)+':'+str(dictionary[k])+'\n') 34 | #f.close() 35 | 36 | write_report(dictionary, '/home/student-02-087c8b510c92/test_report.txt') 37 | -------------------------------------------------------------------------------- /Module 2/Assignments/Model Review/coursera.org-Qwiklabs Assessment Handling Files.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Assignments/Model Review/coursera.org-Qwiklabs Assessment Handling Files.pdf -------------------------------------------------------------------------------- /Module 2/Assignments/Reading and Writing Files/C2M2L1_Reading_And_Writing_Files.md: -------------------------------------------------------------------------------- 1 | 2 | # Practice Notebook: Reading and Writing Files 3 | 4 | In this exercise, we will test your knowledge of reading and writing files by playing around with some text files. 5 |

6 | Let's say we have a text file containing current visitors at a hotel. We'll call it, *guests.txt*. Run the following code to create the file. The file will automatically populate with each initial guest's first name on its own line. 7 | 8 | 9 | ```python 10 | guests = open("guests.txt", "w") 11 | initial_guests = ["Bob", "Andrea", "Manuel", "Polly", "Khalid"] 12 | 13 | for i in initial_guests: 14 | guests.write(i + "\n") 15 | 16 | guests.close() 17 | ``` 18 | 19 | No output is generated for the above code cell. To check the contents of the newly created *guests.txt* file, run the following code. 20 | 21 | 22 | ```python 23 | with open("guests.txt") as guests: 24 | for line in guests: 25 | print(line) 26 | ``` 27 | 28 | Bob 29 | 30 | Andrea 31 | 32 | Manuel 33 | 34 | Polly 35 | 36 | Khalid 37 | 38 | 39 | 40 | The output shows that our *guests.txt* file is correctly populated with each initial guest's first name on its own line. Cool! 41 |

42 | Now suppose we want to update our file as guests check in and out. Fill in the missing code in the following cell to add guests to the *guests.txt* file as they check in. 43 | 44 | 45 | ```python 46 | new_guests = ["Sam", "Danielle", "Jacob"] 47 | 48 | with open("guests.txt", 'a') as guests: 49 | for i in new_guests: 50 | guests.write(i + "\n") 51 | 52 | guests.close() 53 | ``` 54 | 55 | To check whether your code correctly added the new guests to the *guests.txt* file, run the following cell. 56 | 57 | 58 | ```python 59 | with open("guests.txt") as guests: 60 | for line in guests: 61 | print(line) 62 | ``` 63 | 64 | Bob 65 | 66 | Andrea 67 | 68 | Manuel 69 | 70 | Polly 71 | 72 | Khalid 73 | 74 | Sam 75 | 76 | Danielle 77 | 78 | Jacob 79 | 80 | 81 | 82 | The current names in the *guests.txt* file should be: Bob, Andrea, Manuel, Polly, Khalid, Sam, Danielle and Jacob. 83 |

84 | Was the *guests.txt* file correctly appended with the new guests? If not, go back and edit your code making sure to fill in the gaps appropriately so that the new guests are correctly added to the *guests.txt* file. Once the new guests are successfully added, you have filled in the missing code correctly. Great! 85 |

86 | Now let's remove the guests that have checked out already. There are several ways to do this, however, the method we will choose for this exercise is outlined as follows: 87 | 1. Open the file in "read" mode. 88 | 2. Iterate over each line in the file and put each guest's name into a Python list. 89 | 3. Open the file once again in "write" mode. 90 | 4. Add each guest's name in the Python list to the file one by one. 91 | 92 |
93 | Ready? Fill in the missing code in the following cell to remove the guests that have checked out already. 94 | 95 | 96 | ```python 97 | checked_out=["Andrea", "Manuel", "Khalid"] 98 | temp_list=[] 99 | 100 | with open("guests.txt", 'r') as guests: 101 | for g in guests: 102 | temp_list.append(g.strip()) 103 | 104 | with open("guests.txt", 'w') as guests: 105 | for name in temp_list: 106 | if name not in checked_out: 107 | guests.write(name + "\n") 108 | ``` 109 | 110 | To check whether your code correctly removed the checked out guests from the *guests.txt* file, run the following cell. 111 | 112 | 113 | ```python 114 | with open("guests.txt") as guests: 115 | for line in guests: 116 | print(line) 117 | ``` 118 | 119 | Bob 120 | 121 | Polly 122 | 123 | Sam 124 | 125 | Danielle 126 | 127 | Jacob 128 | 129 | 130 | 131 | The current names in the *guests.txt* file should be: Bob, Polly, Sam, Danielle and Jacob. 132 |

133 | Were the names of the checked out guests correctly removed from the *guests.txt* file? If not, go back and edit your code making sure to fill in the gaps appropriately so that the checked out guests are correctly removed from the *guests.txt* file. Once the checked out guests are successfully removed, you have filled in the missing code correctly. Awesome! 134 |

135 | Now let's check whether Bob and Andrea are still checked in. How could we do this? We'll just read through each line in the file to see if their name is in there. Run the following code to check whether Bob and Andrea are still checked in. 136 | 137 | 138 | ```python 139 | guests_to_check = ['Bob', 'Andrea'] 140 | checked_in = [] 141 | 142 | with open("guests.txt","r") as guests: 143 | for g in guests: 144 | checked_in.append(g.strip()) 145 | for check in guests_to_check: 146 | if check in checked_in: 147 | print("{} is checked in".format(check)) 148 | else: 149 | print("{} is not checked in".format(check)) 150 | ``` 151 | 152 | Bob is checked in 153 | Andrea is not checked in 154 | 155 | 156 | We can see that Bob is checked in while Andrea is not. Nice work! You've learned the basics of reading and writing files in Python! 157 | -------------------------------------------------------------------------------- /Module 2/Assignments/Reading and Writing Files/C2M2L1_Reading_And_Writing_Files.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # # Practice Notebook: Reading and Writing Files 5 | 6 | # In this exercise, we will test your knowledge of reading and writing files by playing around with some text files. 7 | #

8 | # Let's say we have a text file containing current visitors at a hotel. We'll call it, *guests.txt*. Run the following code to create the file. The file will automatically populate with each initial guest's first name on its own line. 9 | 10 | # In[22]: 11 | 12 | 13 | guests = open("guests.txt", "w") 14 | initial_guests = ["Bob", "Andrea", "Manuel", "Polly", "Khalid"] 15 | 16 | for i in initial_guests: 17 | guests.write(i + "\n") 18 | 19 | guests.close() 20 | 21 | 22 | # No output is generated for the above code cell. To check the contents of the newly created *guests.txt* file, run the following code. 23 | 24 | # In[23]: 25 | 26 | 27 | with open("guests.txt") as guests: 28 | for line in guests: 29 | print(line) 30 | 31 | 32 | # The output shows that our *guests.txt* file is correctly populated with each initial guest's first name on its own line. Cool! 33 | #

34 | # Now suppose we want to update our file as guests check in and out. Fill in the missing code in the following cell to add guests to the *guests.txt* file as they check in. 35 | 36 | # In[24]: 37 | 38 | 39 | new_guests = ["Sam", "Danielle", "Jacob"] 40 | 41 | with open("guests.txt", 'a') as guests: 42 | for i in new_guests: 43 | guests.write(i + "\n") 44 | 45 | guests.close() 46 | 47 | 48 | # To check whether your code correctly added the new guests to the *guests.txt* file, run the following cell. 49 | 50 | # In[25]: 51 | 52 | 53 | with open("guests.txt") as guests: 54 | for line in guests: 55 | print(line) 56 | 57 | 58 | # The current names in the *guests.txt* file should be: Bob, Andrea, Manuel, Polly, Khalid, Sam, Danielle and Jacob. 59 | #

60 | # Was the *guests.txt* file correctly appended with the new guests? If not, go back and edit your code making sure to fill in the gaps appropriately so that the new guests are correctly added to the *guests.txt* file. Once the new guests are successfully added, you have filled in the missing code correctly. Great! 61 | #

62 | # Now let's remove the guests that have checked out already. There are several ways to do this, however, the method we will choose for this exercise is outlined as follows: 63 | # 1. Open the file in "read" mode. 64 | # 2. Iterate over each line in the file and put each guest's name into a Python list. 65 | # 3. Open the file once again in "write" mode. 66 | # 4. Add each guest's name in the Python list to the file one by one. 67 | # 68 | #
69 | # Ready? Fill in the missing code in the following cell to remove the guests that have checked out already. 70 | 71 | # In[26]: 72 | 73 | 74 | checked_out=["Andrea", "Manuel", "Khalid"] 75 | temp_list=[] 76 | 77 | with open("guests.txt", 'r') as guests: 78 | for g in guests: 79 | temp_list.append(g.strip()) 80 | 81 | with open("guests.txt", 'w') as guests: 82 | for name in temp_list: 83 | if name not in checked_out: 84 | guests.write(name + "\n") 85 | 86 | 87 | # To check whether your code correctly removed the checked out guests from the *guests.txt* file, run the following cell. 88 | 89 | # In[27]: 90 | 91 | 92 | with open("guests.txt") as guests: 93 | for line in guests: 94 | print(line) 95 | 96 | 97 | # The current names in the *guests.txt* file should be: Bob, Polly, Sam, Danielle and Jacob. 98 | #

99 | # Were the names of the checked out guests correctly removed from the *guests.txt* file? If not, go back and edit your code making sure to fill in the gaps appropriately so that the checked out guests are correctly removed from the *guests.txt* file. Once the checked out guests are successfully removed, you have filled in the missing code correctly. Awesome! 100 | #

101 | # Now let's check whether Bob and Andrea are still checked in. How could we do this? We'll just read through each line in the file to see if their name is in there. Run the following code to check whether Bob and Andrea are still checked in. 102 | 103 | # In[28]: 104 | 105 | 106 | guests_to_check = ['Bob', 'Andrea'] 107 | checked_in = [] 108 | 109 | with open("guests.txt","r") as guests: 110 | for g in guests: 111 | checked_in.append(g.strip()) 112 | for check in guests_to_check: 113 | if check in checked_in: 114 | print("{} is checked in".format(check)) 115 | else: 116 | print("{} is not checked in".format(check)) 117 | 118 | 119 | # We can see that Bob is checked in while Andrea is not. Nice work! You've learned the basics of reading and writing files in Python! 120 | -------------------------------------------------------------------------------- /Module 2/Assignments/Reading and Writing Files/guests.txt: -------------------------------------------------------------------------------- 1 | Bob 2 | Polly 3 | Sam 4 | Danielle 5 | Jacob 6 | -------------------------------------------------------------------------------- /Module 2/Quiz/Managing Files & Directories/quiz_module_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Quiz/Managing Files & Directories/quiz_module_2.pdf -------------------------------------------------------------------------------- /Module 2/Quiz/Managing Files & Directories/quiz_module_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Quiz/Managing Files & Directories/quiz_module_2.png -------------------------------------------------------------------------------- /Module 2/Quiz/Managing Files & Directories/quiz_module_2_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Quiz/Managing Files & Directories/quiz_module_2_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 2/Quiz/Reading & Writing CSV Files/quiz_module_2.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Quiz/Reading & Writing CSV Files/quiz_module_2.pdf -------------------------------------------------------------------------------- /Module 2/Quiz/Reading & Writing CSV Files/quiz_module_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Quiz/Reading & Writing CSV Files/quiz_module_2.png -------------------------------------------------------------------------------- /Module 2/Quiz/Reading & Writing CSV Files/quiz_module_2_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Quiz/Reading & Writing CSV Files/quiz_module_2_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Managing Files and Directories/coursera.org-Files and Directories Cheat-Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Managing Files and Directories/coursera.org-Files and Directories Cheat-Sheet.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Managing Files and Directories/docs_python_org_3_library_os_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Managing Files and Directories/docs_python_org_3_library_os_html.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Managing Files and Directories/docs_python_org_3_library_os_path_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Managing Files and Directories/docs_python_org_3_library_os_path_html.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Managing Files and Directories/en_wikipedia_org_wiki_Unix_time.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Managing Files and Directories/en_wikipedia_org_wiki_Unix_time.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Reading and Writing CSV Files/CSV Files Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Reading and Writing CSV Files/CSV Files Cheat Sheet.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Reading and Writing CSV Files/CSV Files Cheat Sheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Reading and Writing CSV Files/CSV Files Cheat Sheet.png -------------------------------------------------------------------------------- /Module 2/Reading/Reading and Writing CSV Files/docs_python_org_3_library_csv_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Reading and Writing CSV Files/docs_python_org_3_library_csv_html.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Reading and Writing CSV Files/realpython_com_python-csv_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Reading and Writing CSV Files/realpython_com_python-csv_.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Reading and Writing Files/coursera.org-Reading and Writing Files Cheat-Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Reading and Writing Files/coursera.org-Reading and Writing Files Cheat-Sheet.pdf -------------------------------------------------------------------------------- /Module 2/Reading/Reading and Writing Files/docs_python_org_3_library_functions_html#open.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/Reading/Reading and Writing Files/docs_python_org_3_library_functions_html#open.pdf -------------------------------------------------------------------------------- /Module 2/notesImages/csv_example_image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/csv_example_image9.png -------------------------------------------------------------------------------- /Module 2/notesImages/csv_reader_example_image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/csv_reader_example_image10.png -------------------------------------------------------------------------------- /Module 2/notesImages/csv_reader_file_gen_cat_image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/csv_reader_file_gen_cat_image11.png -------------------------------------------------------------------------------- /Module 2/notesImages/dict_reader_example_image13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/dict_reader_example_image13.png -------------------------------------------------------------------------------- /Module 2/notesImages/file_modes_example_image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/file_modes_example_image7.png -------------------------------------------------------------------------------- /Module 2/notesImages/file_open_list_sort_example_image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/file_open_list_sort_example_image6.png -------------------------------------------------------------------------------- /Module 2/notesImages/file_open_read_example_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/file_open_read_example_image2.png -------------------------------------------------------------------------------- /Module 2/notesImages/file_open_readline_example_image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/file_open_readline_example_image1.png -------------------------------------------------------------------------------- /Module 2/notesImages/file_open_strip_upper_example_image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/file_open_strip_upper_example_image5.png -------------------------------------------------------------------------------- /Module 2/notesImages/file_open_upper_example_image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/file_open_upper_example_image4.png -------------------------------------------------------------------------------- /Module 2/notesImages/file_open_with_block_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/file_open_with_block_image3.png -------------------------------------------------------------------------------- /Module 2/notesImages/file_os_remove_image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/file_os_remove_image8.png -------------------------------------------------------------------------------- /Module 2/notesImages/sample_csv_file_image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/sample_csv_file_image12.png -------------------------------------------------------------------------------- /Module 2/notesImages/write_file_csv_mod_image14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 2/notesImages/write_file_csv_mod_image14.png -------------------------------------------------------------------------------- /Module 3/Assignments/Model Review/Qwiklabs Assessment: Working with Regular Expressions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Assignments/Model Review/Qwiklabs Assessment: Working with Regular Expressions.pdf -------------------------------------------------------------------------------- /Module 3/Assignments/Model Review/Qwiklabs Assessment: Working with Regular Expressions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Assignments/Model Review/Qwiklabs Assessment: Working with Regular Expressions.png -------------------------------------------------------------------------------- /Module 3/Assignments/Model Review/Solution/data/updated_user_emails.csv: -------------------------------------------------------------------------------- 1 | Full Name, Email Address 2 | Blossom Gill, blossom@xyz.edu 3 | Hayes Delgado, nonummy@utnisia.com 4 | Petra Jones, ac@xyz.edu 5 | Oleg Noel, noel@liberomauris.ca 6 | Ahmed Miller, ahmed.miller@nequenonquam.co.uk 7 | Macaulay Douglas, mdouglas@xyz.edu 8 | Aurora Grant, enim.non@xyz.edu 9 | Madison Mcintosh, mcintosh@nisiaenean.net 10 | Montana Powell, montanap@semmagna.org 11 | Rogan Robinson, rr.robinson@xyz.edu 12 | Simon Rivera, sri@xyz.edu 13 | Benedict Pacheco, bpacheco@xyz.edu 14 | Maisie Hendrix, mai.hendrix@xyz.edu 15 | Xaviera Gould, xlg@utnisia.net 16 | Oren Rollins, oren@semmagna.com 17 | Flavia Santiago, flavia@utnisia.net 18 | Jackson Owens, jackowens@xyz.edu 19 | Britanni Humphrey, britanni@ut.net 20 | Kirk Nixon, kirknixon@xyz.edu 21 | Bree Campbell, breee@utnisia.net 22 | -------------------------------------------------------------------------------- /Module 3/Assignments/Model Review/Solution/data/user_emails.csv: -------------------------------------------------------------------------------- 1 | Full Name, Email Address 2 | Blossom Gill, blossom@abc.edu 3 | Hayes Delgado, nonummy@utnisia.com 4 | Petra Jones, ac@abc.edu 5 | Oleg Noel, noel@liberomauris.ca 6 | Ahmed Miller, ahmed.miller@nequenonquam.co.uk 7 | Macaulay Douglas, mdouglas@abc.edu 8 | Aurora Grant, enim.non@abc.edu 9 | Madison Mcintosh, mcintosh@nisiaenean.net 10 | Montana Powell, montanap@semmagna.org 11 | Rogan Robinson, rr.robinson@abc.edu 12 | Simon Rivera, sri@abc.edu 13 | Benedict Pacheco, bpacheco@abc.edu 14 | Maisie Hendrix, mai.hendrix@abc.edu 15 | Xaviera Gould, xlg@utnisia.net 16 | Oren Rollins, oren@semmagna.com 17 | Flavia Santiago, flavia@utnisia.net 18 | Jackson Owens, jackowens@abc.edu 19 | Britanni Humphrey, britanni@ut.net 20 | Kirk Nixon, kirknixon@abc.edu 21 | Bree Campbell, breee@utnisia.net 22 | -------------------------------------------------------------------------------- /Module 3/Assignments/Model Review/Solution/scripts/script.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | #Import libraries 4 | import re 5 | import csv 6 | 7 | def contains_domain(address, domain): 8 | """Returns True if the email address contains the given,domain,in the domain position, false if not.""" 9 | domain = r'[\w\.-]+@'+domain+'$' 10 | if re.match(domain,address): 11 | return True 12 | return False 13 | 14 | 15 | def replace_domain(address, old_domain, new_domain): 16 | """Replaces the old domain with the new domain in the received address.""" 17 | old_domain_pattern = r'' + old_domain + '$' 18 | address = re.sub(old_domain_pattern, new_domain, address) 19 | return address 20 | 21 | def main(): 22 | """Processes the list of emails, replacing any instances of the old domain with the new domain.""" 23 | old_domain, new_domain = 'abc.edu', 'xyz.edu' 24 | csv_file_location = '../data/user_emails.csv' 25 | report_file = '../data' + '/updated_user_emails.csv' 26 | user_email_list = [] 27 | old_domain_email_list = [] 28 | new_domain_email_list = [] 29 | 30 | with open(csv_file_location, 'r') as f: 31 | user_data_list = list(csv.reader(f)) 32 | user_email_list = [data[1].strip() for data in user_data_list[1:]] 33 | 34 | for email_address in user_email_list: 35 | if contains_domain(email_address, old_domain): 36 | old_domain_email_list.append(email_address) 37 | replaced_email = replace_domain(email_address,old_domain,new_domain) 38 | new_domain_email_list.append(replaced_email) 39 | 40 | email_key = ' ' + 'Email Address' 41 | email_index = user_data_list[0].index(email_key) 42 | 43 | for user in user_data_list[1:]: 44 | for old_domain, new_domain in zip(old_domain_email_list, new_domain_email_list): 45 | if user[email_index] == ' ' + old_domain: 46 | user[email_index] = ' ' + new_domain 47 | f.close() 48 | 49 | with open(report_file, 'w+') as output_file: 50 | writer = csv.writer(output_file) 51 | writer.writerows(user_data_list) 52 | output_file.close() 53 | 54 | main() 55 | -------------------------------------------------------------------------------- /Module 3/Assignments/Model Review/coursera.org-Qwiklabs Assessment Working with Regular Expressions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Assignments/Model Review/coursera.org-Qwiklabs Assessment Working with Regular Expressions.pdf -------------------------------------------------------------------------------- /Module 3/Assignments/Model Review/googlecoursera.qwiklabs.com-Working with Regular Expressions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Assignments/Model Review/googlecoursera.qwiklabs.com-Working with Regular Expressions.pdf -------------------------------------------------------------------------------- /Module 3/Quiz/Advanced Regular Expressions/quiz_module_3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Advanced Regular Expressions/quiz_module_3.pdf -------------------------------------------------------------------------------- /Module 3/Quiz/Advanced Regular Expressions/quiz_module_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Advanced Regular Expressions/quiz_module_3.png -------------------------------------------------------------------------------- /Module 3/Quiz/Advanced Regular Expressions/quiz_module_3_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Advanced Regular Expressions/quiz_module_3_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 3/Quiz/Basic Regular Expressions/quiz_module_3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Basic Regular Expressions/quiz_module_3.pdf -------------------------------------------------------------------------------- /Module 3/Quiz/Basic Regular Expressions/quiz_module_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Basic Regular Expressions/quiz_module_3.png -------------------------------------------------------------------------------- /Module 3/Quiz/Basic Regular Expressions/quiz_module_3_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Basic Regular Expressions/quiz_module_3_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 3/Quiz/Regular Expressions/quiz_module_3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Regular Expressions/quiz_module_3.pdf -------------------------------------------------------------------------------- /Module 3/Quiz/Regular Expressions/quiz_module_3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Regular Expressions/quiz_module_3.png -------------------------------------------------------------------------------- /Module 3/Quiz/Regular Expressions/quiz_module_3_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Quiz/Regular Expressions/quiz_module_3_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 3/Reading/Advanced Regular Expressions/coursera.org-Advanced Regular Expressions Cheat-Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Reading/Advanced Regular Expressions/coursera.org-Advanced Regular Expressions Cheat-Sheet.pdf -------------------------------------------------------------------------------- /Module 3/Reading/Advanced Regular Expressions/regexcrossword_com_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Reading/Advanced Regular Expressions/regexcrossword_com_.pdf -------------------------------------------------------------------------------- /Module 3/Reading/Basic Regular Expressions/Regular Expressions Cheat-Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Reading/Basic Regular Expressions/Regular Expressions Cheat-Sheet.pdf -------------------------------------------------------------------------------- /Module 3/Reading/Basic Regular Expressions/Regular Expressions Cheat-Sheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Reading/Basic Regular Expressions/Regular Expressions Cheat-Sheet.png -------------------------------------------------------------------------------- /Module 3/Reading/Basic Regular Expressions/docs_python_org_3_howto_regex_html#greedy-versus-non-greedy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Reading/Basic Regular Expressions/docs_python_org_3_howto_regex_html#greedy-versus-non-greedy.pdf -------------------------------------------------------------------------------- /Module 3/Reading/Basic Regular Expressions/docs_python_org_3_howto_regex_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Reading/Basic Regular Expressions/docs_python_org_3_howto_regex_html.pdf -------------------------------------------------------------------------------- /Module 3/Reading/Basic Regular Expressions/docs_python_org_3_library_re_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/Reading/Basic Regular Expressions/docs_python_org_3_library_re_html.pdf -------------------------------------------------------------------------------- /Module 3/notesImages/error_result_1_image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/error_result_1_image12.png -------------------------------------------------------------------------------- /Module 3/notesImages/grep_pattern_caret_image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/grep_pattern_caret_image5.png -------------------------------------------------------------------------------- /Module 3/notesImages/grep_pattern_dollar_image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/grep_pattern_dollar_image6.png -------------------------------------------------------------------------------- /Module 3/notesImages/grep_pattern_dot_image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/grep_pattern_dot_image4.png -------------------------------------------------------------------------------- /Module 3/notesImages/grep_python_i_dict_words_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/grep_python_i_dict_words_image3.png -------------------------------------------------------------------------------- /Module 3/notesImages/grep_thon_dict_words_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/grep_thon_dict_words_image2.png -------------------------------------------------------------------------------- /Module 3/notesImages/log_entry_example_image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/log_entry_example_image1.png -------------------------------------------------------------------------------- /Module 3/notesImages/output_search_re_image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/output_search_re_image7.png -------------------------------------------------------------------------------- /Module 3/notesImages/output_search_re_image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/output_search_re_image8.png -------------------------------------------------------------------------------- /Module 3/notesImages/output_search_re_image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/output_search_re_image9.png -------------------------------------------------------------------------------- /Module 3/notesImages/rearrange_name_example_image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/rearrange_name_example_image10.png -------------------------------------------------------------------------------- /Module 3/notesImages/repetition_qualifiers_example_image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 3/notesImages/repetition_qualifiers_example_image11.png -------------------------------------------------------------------------------- /Module 4/Assignments/Module Review/Qwiklabs Assessment: Working with Log Files.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Assignments/Module Review/Qwiklabs Assessment: Working with Log Files.pdf -------------------------------------------------------------------------------- /Module 4/Assignments/Module Review/Qwiklabs Assessment: Working with Log Files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Assignments/Module Review/Qwiklabs Assessment: Working with Log Files.png -------------------------------------------------------------------------------- /Module 4/Assignments/Module Review/Solution/data/errors_found.log: -------------------------------------------------------------------------------- 1 | July 31 04:11:32 mycomputername CRON[51253]: ERROR: Failed to start CRON job due to script syntax error. Inform the CRON job owner! 2 | -------------------------------------------------------------------------------- /Module 4/Assignments/Module Review/Solution/scripts/find_error.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import os 5 | import re 6 | 7 | def error_search(log_file): 8 | error = input("What is the error? ") 9 | returned_errors = [] 10 | with open(log_file, mode='r',encoding='UTF-8') as file: 11 | for log in file.readlines(): 12 | error_patterns = ["error"] 13 | for i in range(len(error.split(' '))): 14 | error_patterns.append(r"{}".format(error.split(' ')[i].lower())) 15 | if all(re.search(error_pattern, log.lower()) for error_pattern in error_patterns): 16 | returned_errors.append(log) 17 | file.close() 18 | return returned_errors 19 | 20 | def file_output(returned_errors): 21 | with open(os.path.expanduser('~') + '/data/errors_found.log', 'w') as file: 22 | for error in returned_errors: 23 | file.write(error) 24 | file.close() 25 | 26 | if __name__ == "__main__": 27 | log_file = sys.argv[1] 28 | returned_errors = error_search(log_file) 29 | file_output(returned_errors) 30 | sys.exit(0) 31 | 32 | -------------------------------------------------------------------------------- /Module 4/Assignments/Module Review/coursera.org-Qwiklabs Assessment Working with Log Files.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Assignments/Module Review/coursera.org-Qwiklabs Assessment Working with Log Files.pdf -------------------------------------------------------------------------------- /Module 4/Assignments/Module Review/coursera.org-Qwiklabs Assessment Working with Log Files.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Assignments/Module Review/coursera.org-Qwiklabs Assessment Working with Log Files.png -------------------------------------------------------------------------------- /Module 4/Assignments/Module Review/googlecoursera.qwiklabs.com-Working with Log Files.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Assignments/Module Review/googlecoursera.qwiklabs.com-Working with Log Files.pdf -------------------------------------------------------------------------------- /Module 4/Quiz/Data Streams/quiz_module_4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Data Streams/quiz_module_4.pdf -------------------------------------------------------------------------------- /Module 4/Quiz/Data Streams/quiz_module_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Data Streams/quiz_module_4.png -------------------------------------------------------------------------------- /Module 4/Quiz/Data Streams/quiz_module_4_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Data Streams/quiz_module_4_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 4/Quiz/Processing Log Files/quiz_module_4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Processing Log Files/quiz_module_4.pdf -------------------------------------------------------------------------------- /Module 4/Quiz/Processing Log Files/quiz_module_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Processing Log Files/quiz_module_4.png -------------------------------------------------------------------------------- /Module 4/Quiz/Processing Log Files/quiz_module_4_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Processing Log Files/quiz_module_4_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 4/Quiz/Python Subprocesses/quiz_module_4.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Python Subprocesses/quiz_module_4.pdf -------------------------------------------------------------------------------- /Module 4/Quiz/Python Subprocesses/quiz_module_4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Python Subprocesses/quiz_module_4.png -------------------------------------------------------------------------------- /Module 4/Quiz/Python Subprocesses/quiz_module_4_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Quiz/Python Subprocesses/quiz_module_4_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 4/Reading/Data Streams/More About Input Functions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Reading/Data Streams/More About Input Functions.pdf -------------------------------------------------------------------------------- /Module 4/Reading/Data Streams/More About Input Functions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Reading/Data Streams/More About Input Functions.png -------------------------------------------------------------------------------- /Module 4/Reading/Data Streams/docs_python_org_2_library_functions_html#input.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Reading/Data Streams/docs_python_org_2_library_functions_html#input.pdf -------------------------------------------------------------------------------- /Module 4/Reading/Data Streams/docs_python_org_3_library_functions_html#input.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Reading/Data Streams/docs_python_org_3_library_functions_html#input.pdf -------------------------------------------------------------------------------- /Module 4/Reading/Data Streams/useful_links.md: -------------------------------------------------------------------------------- 1 | # Useful Links : Reading 2 | 3 | ## In Python 2: 4 | 5 | ### Standard Library Docs: 6 | 7 | 1. https://docs.python.org/2/library/functions.html#input 8 | 1. https://docs.python.org/2/library/functions.html#raw_input 9 | 1. https://docs.python.org/2/library/functions.html#eval 10 | 11 | ## In Python 3 12 | 13 | ### Standard Library Docs: 14 | 15 | 1. https://docs.python.org/3/library/functions.html#input 16 | 1. https://docs.python.org/3/library/functions.html#eval 17 | -------------------------------------------------------------------------------- /Module 4/Reading/Python Subprocesses/Python Subprocesses Cheat Sheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Reading/Python Subprocesses/Python Subprocesses Cheat Sheet.png -------------------------------------------------------------------------------- /Module 4/Reading/Python Subprocesses/coursera.org-Python Subprocesses Cheat Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Reading/Python Subprocesses/coursera.org-Python Subprocesses Cheat Sheet.pdf -------------------------------------------------------------------------------- /Module 4/Reading/Python Subprocesses/docs_python_org_3_library_subprocess_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/Reading/Python Subprocesses/docs_python_org_3_library_subprocess_html.pdf -------------------------------------------------------------------------------- /Module 4/Scipts/check_cron.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | logfile = sys.argv[1] 5 | with open(logfile) as f: 6 | for line in f: 7 | if "CRON" not in line: 8 | # continue keyword tells the loop to go to the next element 9 | continue 10 | pattern = r"USER \((\w+)\)$" 11 | result = re.search(pattern, line) 12 | print(result[1]) -------------------------------------------------------------------------------- /Module 4/Scipts/check_cron_upd.py: -------------------------------------------------------------------------------- 1 | import re 2 | import sys 3 | 4 | logfile = sys.argv[1] 5 | usernames = {} 6 | with open(logfile) as f: 7 | for line in f: 8 | if "CRON" not in line: 9 | # continue keyword tells the loop to go to the next element 10 | continue 11 | pattern = r"USER \((\w+)\)$" 12 | result = re.search(pattern, line) 13 | if result is None: 14 | continue 15 | name = result[1] 16 | usernames[name] = usernames.get(name, 0) + 1 17 | print(usernames) -------------------------------------------------------------------------------- /Module 4/Scipts/create_file.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | # Receives a file name as a command line argument 4 | filename=sys.argv[1] 5 | 6 | # Checks whether the file name exist or not 7 | # When the file doesn't exist, it creates it by writing a line to it 8 | if not os.path.exists(filename): 9 | with open(filename, "w") as f: 10 | f.write("New file created\n") 11 | # When the file exist, our script print an error message and exits with an exit value of one 12 | else: 13 | print("Error, the file {} already exists!".format(filename)) 14 | sys.exit(1) 15 | -------------------------------------------------------------------------------- /Module 4/Scipts/hello.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Input function aloows for prompt the user for a cetain value which can be used in scripts 4 | name = input("Please enter your name: ") 5 | print("Hello, " + name) 6 | -------------------------------------------------------------------------------- /Module 4/Scipts/myapp.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | 4 | # The copy method creates a new dictionary that can be changed as needed without modifying the original environment 5 | my_env = os.environ.copy() 6 | 7 | # The path variable indicates where the operating system will look for the executable programs 8 | # Joins /opt/myapp and the old value of the path variable to the path separator 9 | my_env["PATH"] = os.pathsep.join(["/opt/myapp/", my_env["PATH"]]) 10 | 11 | # Calls the myapp command, setting the end parameter to the new environment 12 | result = subprocess.run(["myapp"], env=my_env) -------------------------------------------------------------------------------- /Module 4/Scipts/parameters.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | print(sys.argv) -------------------------------------------------------------------------------- /Module 4/Scipts/seconds.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/enb python3 2 | 3 | def to_seconds(hours, minutes, seconds): 4 | return hours*3600+minutes*60+seconds 5 | 6 | print("Welcome to this time converter") 7 | 8 | cont = "y" 9 | while(cont.lower() == "y"): 10 | hours = int(input("Enter the number of hours: ")) 11 | minutes = int(input("Enter the number of minutes: ")) 12 | seconds = int(input("Enter the number of seconds: ")) 13 | 14 | print("That's {} seconds.".format(to_seconds(hours, minutes, seconds))) 15 | print() 16 | cont = input("Do you want to do another conversion? [y to continue] ") 17 | 18 | print("Good bye!") -------------------------------------------------------------------------------- /Module 4/Scipts/variables.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import os 4 | 5 | print("HOME: " + os.environ.get("HOME", "")) 6 | print("SHELL: " + os.environ.get("SHELL", "")) 7 | # export FRUIT=Pineapple 8 | print("FRUIT: " + os.environ.get("FRUIT", "")) -------------------------------------------------------------------------------- /Module 4/notesImages/PATH_var_output_image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/PATH_var_output_image7.png -------------------------------------------------------------------------------- /Module 4/notesImages/advance_subprocess_management_image18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/advance_subprocess_management_image18.png -------------------------------------------------------------------------------- /Module 4/notesImages/check_cron_upd_output_image25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/check_cron_upd_output_image25.png -------------------------------------------------------------------------------- /Module 4/notesImages/check_program_status_failed_image13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/check_program_status_failed_image13.png -------------------------------------------------------------------------------- /Module 4/notesImages/check_program_status_success_image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/check_program_status_success_image12.png -------------------------------------------------------------------------------- /Module 4/notesImages/count_data_using_dict_image24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/count_data_using_dict_image24.png -------------------------------------------------------------------------------- /Module 4/notesImages/cron_check_output_image23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/cron_check_output_image23.png -------------------------------------------------------------------------------- /Module 4/notesImages/env_cmd_output_image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/env_cmd_output_image6.png -------------------------------------------------------------------------------- /Module 4/notesImages/env_var_using_python_image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/env_var_using_python_image8.png -------------------------------------------------------------------------------- /Module 4/notesImages/env_var_using_python_image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/env_var_using_python_image9.png -------------------------------------------------------------------------------- /Module 4/notesImages/input_method_example_image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/input_method_example_image1.png -------------------------------------------------------------------------------- /Module 4/notesImages/input_method_example_output_time_converter_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/input_method_example_output_time_converter_image3.png -------------------------------------------------------------------------------- /Module 4/notesImages/input_method_example_time_converter_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/input_method_example_time_converter_image2.png -------------------------------------------------------------------------------- /Module 4/notesImages/io_stream_diagram_image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/io_stream_diagram_image4.png -------------------------------------------------------------------------------- /Module 4/notesImages/io_stream_example_image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/io_stream_example_image5.png -------------------------------------------------------------------------------- /Module 4/notesImages/log_diag_image20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/log_diag_image20.png -------------------------------------------------------------------------------- /Module 4/notesImages/log_files_diag_image19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/log_files_diag_image19.png -------------------------------------------------------------------------------- /Module 4/notesImages/parent_child_subprocess_image17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/parent_child_subprocess_image17.png -------------------------------------------------------------------------------- /Module 4/notesImages/python_sample_script_file_image15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/python_sample_script_file_image15.png -------------------------------------------------------------------------------- /Module 4/notesImages/python_sample_script_file_image16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/python_sample_script_file_image16.png -------------------------------------------------------------------------------- /Module 4/notesImages/python_sample_script_status_image14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/python_sample_script_status_image14.png -------------------------------------------------------------------------------- /Module 4/notesImages/sample_data_image21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/sample_data_image21.png -------------------------------------------------------------------------------- /Module 4/notesImages/sys_argv_list_example_noparam_image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/sys_argv_list_example_noparam_image10.png -------------------------------------------------------------------------------- /Module 4/notesImages/sys_argv_list_example_withparam_image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/sys_argv_list_example_withparam_image11.png -------------------------------------------------------------------------------- /Module 4/notesImages/user_extract_regex_image22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 4/notesImages/user_extract_regex_image22.png -------------------------------------------------------------------------------- /Module 5/Assignments/Errors and Exceptions/C2M5L4_Errors_and_Exceptions-V2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # # Practice Notebook - Errors and Exceptions 5 | 6 | # Below we have a function that removes an item from an input list. Run it to see what it does. 7 | 8 | # In[1]: 9 | 10 | 11 | my_list = [27, 5, 9, 6, 8] 12 | 13 | def RemoveValue(myVal): 14 | my_list.remove(myVal) 15 | return my_list 16 | 17 | print(RemoveValue(27)) 18 | 19 | 20 | # We used the `RemoveValue()` function to remove the number, 27 from the given list. Great! The function seems to be working fine. However, there is a problem when we try to call the function on the number 27 again. Run the following cell to see what happens. 21 | 22 | # In[2]: 23 | 24 | 25 | print(RemoveValue(27)) 26 | 27 | 28 | # From the above output we see that our function now raises a **ValueError**. This is because we are trying to remove a number from a list that is not in the list. When we removed 27 from the list the first time, it was no longer available in the list to be removed a second time. Python is letting us know that the number 27 no longer makes sense for our `RemoveValue()` function. 29 | #

30 | # We'd like to take control of the error messaging here and pre-empt this error. Fill in the blanks below to raise a ValueError in the `RemoveValue()` function if a value is not in the list. You can have the error message say something obvious like "Value must be in the given list". 31 | 32 | # In[3]: 33 | 34 | 35 | def RemoveValue(myVal): 36 | if myVal not in my_list: 37 | raise ValueError('Value must be in the given list') 38 | else: 39 | my_list.remove(myVal) 40 | return my_list 41 | 42 | print(RemoveValue(27)) 43 | 44 | 45 | # Did your error message print correctly? Was the output something like: **ValueError: Value must be in the given list**? If not, go back to the previous cell and make sure you filled in the blanks correctly. If your error message did print correctly, great! You are on your way to mastering the basics of handling errors and exceptions. 46 | #

47 | # Now, let's look at a different function. Below we have a function that sorts an input list alphabetically. Run it to see what it does. 48 | 49 | # In[4]: 50 | 51 | 52 | my_word_list = ['east', 'after', 'up', 'over', 'inside'] 53 | 54 | def OrganizeList(myList): 55 | myList.sort() 56 | return myList 57 | 58 | print(OrganizeList(my_word_list)) 59 | 60 | 61 | # We used the `OrganizeList()` function to sort a given list alphabetically. The function seems to be working fine. However, there is a problem when we try to call the function on a list containing number values. Run the following cell to see what happens. 62 | 63 | # In[5]: 64 | 65 | 66 | my_new_list = [6, 3, 8, "12", 42] 67 | print(OrganizeList(my_new_list)) 68 | 69 | 70 | # From the above output we see that our function now raises a **TypeError**. This is because the `OrganizeList()` function makes sense for lists that are filled with only strings. Take control of the error messaging here and pre-empt this error by filling in the blanks below to add an assert type argument that verifies whether the input list is filled with only strings. You can have the error message say something like "Word list must be a list of strings". 71 | 72 | # In[8]: 73 | 74 | 75 | def OrganizeList(myList): 76 | for item in myList: 77 | assert type(item) != str, 'Word list must be a list of strings' 78 | myList.sort() 79 | return myList 80 | 81 | print(OrganizeList(my_new_list)) 82 | 83 | 84 | # Did your error message print correctly? Was the output something like: **AssertionError: Word list must be a list of strings**? If not, go back to the previous cell and make sure you filled in the blanks correctly. If your error message did print correctly, excellent! You are another step closer to mastering the basics of handling errors and exceptions. 85 | #

86 | # Let's look at one last code block. The `Guess()` function below takes a list of participants, assigns each a random number from 1 to 9, and stores this information in a dictionary with the participant name as the key. It then returns *True* if Larry was assigned the number 9 and *False* if this was not the case. Run it to see what it does. 87 | 88 | # In[9]: 89 | 90 | 91 | import random 92 | 93 | participants = ['Jack','Jill','Larry','Tom'] 94 | 95 | def Guess(participants): 96 | my_participant_dict = {} 97 | for participant in participants: 98 | my_participant_dict[participant] = random.randint(1, 9) 99 | if my_participant_dict['Larry'] == 9: 100 | return True 101 | else: 102 | return False 103 | 104 | print(Guess(participants)) 105 | 106 | 107 | # The code seems to be working fine. However, there are some things that could go wrong, so find the part that might throw an exception and wrap it in a try-except block to ensure that you get sensible behavior. Do this in the cell below. Code your function to return *None* if an exception occurs. 108 | 109 | # In[14]: 110 | 111 | 112 | # Revised Guess() function 113 | def Guess(participants): 114 | my_participant_dict = {} 115 | for participant in participants: 116 | my_participant_dict[participant] = random.randint(1, 9) 117 | try: 118 | if my_participant_dict['Larry'] == 9: 119 | return True 120 | else: 121 | return False 122 | except: 123 | return None 124 | 125 | 126 | # Call your revised `Guess()` function with the following participant list. 127 | 128 | # In[15]: 129 | 130 | 131 | participants = ['Cathy','Fred','Jack','Tom'] 132 | print(Guess(participants)) 133 | 134 | 135 | # Was the above output *None*? If not, go back to the code block containing your revised `Guess()` function and make edits so that the output is *None* for the previous code block. If the above output was indeed *None*, congratulations! You've mastered the basics of handling errors and exceptions in Python and you are all done with this notebook! 136 | -------------------------------------------------------------------------------- /Module 5/Assignments/Module Review/Implementing Unit Testing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Assignments/Module Review/Implementing Unit Testing.pdf -------------------------------------------------------------------------------- /Module 5/Assignments/Module Review/Implementing Unit Testing.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Assignments/Module Review/Implementing Unit Testing.png -------------------------------------------------------------------------------- /Module 5/Assignments/Module Review/Solution/data/user_emails.csv: -------------------------------------------------------------------------------- 1 | Blossom Gill,blossom@abc.edu, 2 | Hayes Delgado,nonummy@abc.edu 3 | Petra Jones,ac@abc.edu 4 | Oleg Noel,noel@abc.edu 5 | Ahmed Miller,ahmed.miller@abc.edu 6 | Macaulay Douglas,mdouglas@abc.edu 7 | Aurora Grant,enim.non@abc.edu 8 | Madison Mcintosh,mcintosh@abc.edu 9 | Montana Powell,montanap@abc.edu 10 | Rogan Robinson,rr.robinson@abc.edu 11 | Simon Rivera,sri@abc.edu 12 | Benedict Pacheco,bpacheco@abc.edu 13 | Maisie Hendrix,mai.hendrix@abc.edu 14 | Xaviera Gould,xlg@abc.edu 15 | Oren Rollins,oren@abc.edu 16 | Flavia Santiago,flavia@abc.edu 17 | Jackson Owens,jacksonowens@abc.edu 18 | Britanni Humphrey,britanni@abc.edu 19 | Kirk Nixon,kirknixon@abc.edu 20 | Bree Campbell,breee@abc.edu 21 | -------------------------------------------------------------------------------- /Module 5/Assignments/Module Review/Solution/scripts/emails.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import csv 5 | 6 | def populate_dictionary(filename): 7 | """Populate a dictionary with name/email pairs for easy lookup.""" 8 | email_dict = {} 9 | with open(filename) as csvfile: 10 | lines = csv.reader(csvfile, delimiter = ',') 11 | for row in lines: 12 | name = str(row[0].lower()) 13 | email_dict[name] = row[1] 14 | return email_dict 15 | 16 | def find_email(argv): 17 | """ Return an email address based on the username given.""" 18 | # Create the username based on the command line input. 19 | try: 20 | fullname = str(argv[1] + " " + argv[2]) 21 | # Preprocess the data 22 | email_dict = populate_dictionary('/home/student-00-8deba6524d87/data/user_emails.csv') 23 | # Find and print the email 24 | if email_dict.get(fullname.lower()): 25 | return email_dict.get(fullname.lower()) 26 | else: 27 | return "No email address found" 28 | except IndexError: 29 | return "Missing parameters" 30 | 31 | def main(): 32 | print(find_email(sys.argv)) 33 | 34 | if __name__ == "__main__": 35 | main() 36 | -------------------------------------------------------------------------------- /Module 5/Assignments/Module Review/Solution/scripts/emails_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import unittest 3 | 4 | from emails import find_email 5 | 6 | class EmailsTest(unittest.TestCase): 7 | def test_basic(self): 8 | testcase = [None, "Bree", "Campbell"] 9 | expected = "breee@abc.edu" 10 | self.assertEqual(find_email(testcase), expected) 11 | 12 | def test_one_name(self): 13 | testcase = [None, "John"] 14 | expected = "Missing parameters" 15 | self.assertEqual(find_email(testcase), expected) 16 | 17 | def test_two_name(self): 18 | testcase = [None, "Roy","Cooper"] 19 | expected = "No email address found" 20 | self.assertEqual(find_email(testcase), expected) 21 | 22 | if __name__ == '__main__': 23 | unittest.main() 24 | -------------------------------------------------------------------------------- /Module 5/Assignments/Module Review/googlecoursera.qwiklabs.com-Implementing Unit Testing.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Assignments/Module Review/googlecoursera.qwiklabs.com-Implementing Unit Testing.pdf -------------------------------------------------------------------------------- /Module 5/Assignments/Unit Tests/C2M5L2_Unit_Tests_and_Edge_Cases-V3.md: -------------------------------------------------------------------------------- 1 | 2 | # Practice Notebook - Unit Tests and Edge Cases 3 | 4 | Below we have some code that makes a list of specific letters found in any string. If you run it, you can see what it does. 5 | 6 | 7 | ```python 8 | import re 9 | 10 | my_txt = "An investment in knowledge pays the best interest." 11 | 12 | def LetterCompiler(txt): 13 | result = re.findall(r'([a-c]).', txt) 14 | return result 15 | 16 | print(LetterCompiler(my_txt)) 17 | ``` 18 | 19 | ['a', 'b'] 20 | 21 | 22 | From the output, you can see that the `LetterCompiler( )` function finds all matches for the letters a through c in an input string if followed by another character and returns them as a list of strings, with each string representing one match. Nice. 23 |

24 | But can we be sure that this function will always do what we expect it to do? We need to write code to help us catch mistakes, errors and bugs. This code should automate the process of checking if the returned value of our code matches the expectations by dynamically feeding into it test cases. Since we're dynamically feeding in different strings, it would be prudent to create unit tests for our code. We can use the module **unittest** for this. 25 |

26 | Fill in the blanks below to create an automatic unint test that verifies whether input strings have the correct list of string matches. 27 | 28 | 29 | ```python 30 | import unittest 31 | 32 | class TestCompiler(unittest.TestCase): 33 | 34 | def test_basic(self): 35 | testcase = "The best preparation for tomorrow is doing your best today." 36 | expected = ['b', 'a', 'a', 'b', 'a'] 37 | self.assertEqual(LetterCompiler(testcase), expected) 38 | ``` 39 | 40 | Now that your automatic test is coded, you need to call the `unittest.main( )` function to run the test. It is important to note that the configuration for running unit tests in Jupyter is different than running unit tests from the command line. Running `unittest.main( )` in Jupyter **will result in an error**. You can see this by runnig the following cell to execute your automatic test. 41 | 42 | 43 | ```python 44 | unittest.main() 45 | ``` 46 | 47 | E 48 | ====================================================================== 49 | ERROR: /home/jovyan/ (unittest.loader._FailedTest) 50 | ---------------------------------------------------------------------- 51 | AttributeError: module '__main__' has no attribute '/home/jovyan/' 52 | 53 | ---------------------------------------------------------------------- 54 | Ran 1 test in 0.001s 55 | 56 | FAILED (errors=1) 57 | 58 | 59 | 60 | An exception has occurred, use %tb to see the full traceback. 61 | 62 | 63 | SystemExit: True 64 | 65 | 66 | 67 | Yikes! **SystemExit: True** means an error occurred, as expected. The reason is that `unittest.main( )` looks at *sys.argv*. In Jupyter, by default, the first parameter of *sys.argv* is what started the Jupyter kernel which is not the case when executing it from the command line. This default parameter is passed into `unittest.main( )` as an attribute when you don't explicitly pass it attributes and is therefore what causes the error about the kernel connection file not being a valid attribute. Passing an explicit list to `unittest.main( )` prevents it from looking at *sys.argv*. 68 |

Let's pass it the list ['first-arg-is-ignored'] for example. In addition, we will pass it the parameter *exit = False* to prevent `unittest.main( )` from shutting down the kernel process. Run the following cell with the *argv* and *exit* parameters passed into `unittest.main( )` to rerun your automatic test. 69 | 70 | 71 | ```python 72 | unittest.main(argv = ['first-arg-is-ignored'], exit = False) 73 | ``` 74 | 75 | . 76 | ---------------------------------------------------------------------- 77 | Ran 1 test in 0.047s 78 | 79 | OK 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | Did your automatic test pass? Was **OK** the result? If not, go back to your automatic test code and make sure you filled in the blanks correctly. If your automatic test passed, great! You have successfully filled in the gaps to create an automatic test that verifies whether input strings have the correct list of string matches. 90 | 91 | This is great work so far, but your automatic test includes only one test case. You need to make it grow. You can feed in more strings as test cases to test whether your code works in the general case. But you should also see what happens when you give it some input that you might not expect it to run into under normal operations. 92 |

93 | Edge cases are inputs to code that produce unexpected results, and are found at the extreme ends of the ranges of input we imagine programs will typically work with. Can you use the cell below to write some edge cases? We've already filled in another test case for you! As it is, this test will run fine. Can you come up with at least one test case that you think could result in a wrong return value? No wrong answers! Feel free to play around. 94 | 95 | 96 | ```python 97 | class TestCompiler2(unittest.TestCase): 98 | 99 | def test_two(self): 100 | testcase = "A b c d e f g h i j k l m n o q r s t u v w x y z" 101 | expected = ['b', 'c'] 102 | self.assertEqual(LetterCompiler(testcase), expected) 103 | 104 | # EDGE CASES HERE 105 | def test_three(self): 106 | testcase = "A d e f g h i j k l m n o q r s t u v w x y z" 107 | expected = [] 108 | self.assertEqual(LetterCompiler(testcase), expected) 109 | 110 | def test_four(self): 111 | testcase = "" 112 | expected = [] 113 | self.assertEqual(LetterCompiler(testcase), expected) 114 | 115 | unittest.main(argv = ['first-arg-is-ignored'], exit = False) 116 | ``` 117 | 118 | .... 119 | ---------------------------------------------------------------------- 120 | Ran 4 tests in 0.077s 121 | 122 | OK 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | Did you find any edge cases? If not, continue working on it. Choosing test cases can be an exercise in creativity. Coming up with different ways a code might break can be super fun! When you have found an edge case, think about special handling in your script in order for your code to continue to behave correctly. 133 |
134 | If you are out of ideas: Try removing the spaces and figure out why they were in the example testcase. Does that give you an idea for other tests? 135 |
136 | When you have found at least one edge case, you are all done with this notebook. You should take a moment to reflect on what you've done so far. It's super impressive and it's going to fit nicely in your IT toolkit. 137 | -------------------------------------------------------------------------------- /Module 5/Assignments/Unit Tests/C2M5L2_Unit_Tests_and_Edge_Cases-V3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # coding: utf-8 3 | 4 | # # Practice Notebook - Unit Tests and Edge Cases 5 | 6 | # Below we have some code that makes a list of specific letters found in any string. If you run it, you can see what it does. 7 | 8 | # In[1]: 9 | 10 | 11 | import re 12 | 13 | my_txt = "An investment in knowledge pays the best interest." 14 | 15 | def LetterCompiler(txt): 16 | result = re.findall(r'([a-c]).', txt) 17 | return result 18 | 19 | print(LetterCompiler(my_txt)) 20 | 21 | 22 | # From the output, you can see that the `LetterCompiler( )` function finds all matches for the letters a through c in an input string if followed by another character and returns them as a list of strings, with each string representing one match. Nice. 23 | #

24 | # But can we be sure that this function will always do what we expect it to do? We need to write code to help us catch mistakes, errors and bugs. This code should automate the process of checking if the returned value of our code matches the expectations by dynamically feeding into it test cases. Since we're dynamically feeding in different strings, it would be prudent to create unit tests for our code. We can use the module **unittest** for this. 25 | #

26 | # Fill in the blanks below to create an automatic unint test that verifies whether input strings have the correct list of string matches. 27 | 28 | # In[2]: 29 | 30 | 31 | import unittest 32 | 33 | class TestCompiler(unittest.TestCase): 34 | 35 | def test_basic(self): 36 | testcase = "The best preparation for tomorrow is doing your best today." 37 | expected = ['b', 'a', 'a', 'b', 'a'] 38 | self.assertEqual(LetterCompiler(testcase), expected) 39 | 40 | 41 | # Now that your automatic test is coded, you need to call the `unittest.main( )` function to run the test. It is important to note that the configuration for running unit tests in Jupyter is different than running unit tests from the command line. Running `unittest.main( )` in Jupyter **will result in an error**. You can see this by runnig the following cell to execute your automatic test. 42 | 43 | # In[3]: 44 | 45 | 46 | unittest.main() 47 | 48 | 49 | # Yikes! **SystemExit: True** means an error occurred, as expected. The reason is that `unittest.main( )` looks at *sys.argv*. In Jupyter, by default, the first parameter of *sys.argv* is what started the Jupyter kernel which is not the case when executing it from the command line. This default parameter is passed into `unittest.main( )` as an attribute when you don't explicitly pass it attributes and is therefore what causes the error about the kernel connection file not being a valid attribute. Passing an explicit list to `unittest.main( )` prevents it from looking at *sys.argv*. 50 | #

Let's pass it the list ['first-arg-is-ignored'] for example. In addition, we will pass it the parameter *exit = False* to prevent `unittest.main( )` from shutting down the kernel process. Run the following cell with the *argv* and *exit* parameters passed into `unittest.main( )` to rerun your automatic test. 51 | 52 | # In[4]: 53 | 54 | 55 | unittest.main(argv = ['first-arg-is-ignored'], exit = False) 56 | 57 | 58 | # Did your automatic test pass? Was **OK** the result? If not, go back to your automatic test code and make sure you filled in the blanks correctly. If your automatic test passed, great! You have successfully filled in the gaps to create an automatic test that verifies whether input strings have the correct list of string matches. 59 | 60 | # This is great work so far, but your automatic test includes only one test case. You need to make it grow. You can feed in more strings as test cases to test whether your code works in the general case. But you should also see what happens when you give it some input that you might not expect it to run into under normal operations. 61 | #

62 | # Edge cases are inputs to code that produce unexpected results, and are found at the extreme ends of the ranges of input we imagine programs will typically work with. Can you use the cell below to write some edge cases? We've already filled in another test case for you! As it is, this test will run fine. Can you come up with at least one test case that you think could result in a wrong return value? No wrong answers! Feel free to play around. 63 | 64 | # In[15]: 65 | 66 | 67 | class TestCompiler2(unittest.TestCase): 68 | 69 | def test_two(self): 70 | testcase = "A b c d e f g h i j k l m n o q r s t u v w x y z" 71 | expected = ['b', 'c'] 72 | self.assertEqual(LetterCompiler(testcase), expected) 73 | 74 | # EDGE CASES HERE 75 | def test_three(self): 76 | testcase = "A d e f g h i j k l m n o q r s t u v w x y z" 77 | expected = [] 78 | self.assertEqual(LetterCompiler(testcase), expected) 79 | 80 | def test_four(self): 81 | testcase = "" 82 | expected = [] 83 | self.assertEqual(LetterCompiler(testcase), expected) 84 | 85 | unittest.main(argv = ['first-arg-is-ignored'], exit = False) 86 | 87 | 88 | # Did you find any edge cases? If not, continue working on it. Choosing test cases can be an exercise in creativity. Coming up with different ways a code might break can be super fun! When you have found an edge case, think about special handling in your script in order for your code to continue to behave correctly. 89 | #
90 | # If you are out of ideas: Try removing the spaces and figure out why they were in the example testcase. Does that give you an idea for other tests? 91 | #
92 | # When you have found at least one edge case, you are all done with this notebook. You should take a moment to reflect on what you've done so far. It's super impressive and it's going to fit nicely in your IT toolkit. 93 | -------------------------------------------------------------------------------- /Module 5/Quiz/Other Test Concepts/quiz_module_5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Quiz/Other Test Concepts/quiz_module_5.pdf -------------------------------------------------------------------------------- /Module 5/Quiz/Other Test Concepts/quiz_module_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Quiz/Other Test Concepts/quiz_module_5.png -------------------------------------------------------------------------------- /Module 5/Quiz/Other Test Concepts/quiz_module_5_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Quiz/Other Test Concepts/quiz_module_5_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 5/Quiz/Simple Tests/quiz_module_5.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Quiz/Simple Tests/quiz_module_5.pdf -------------------------------------------------------------------------------- /Module 5/Quiz/Simple Tests/quiz_module_5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Quiz/Simple Tests/quiz_module_5.png -------------------------------------------------------------------------------- /Module 5/Quiz/Simple Tests/quiz_module_5_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Quiz/Simple Tests/quiz_module_5_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/Handling Errors Cheat-Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/Handling Errors Cheat-Sheet.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/Handling Errors Cheat-Sheet.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/Handling Errors Cheat-Sheet.png -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/docs_python_org_2_reference_simple_stmts_html#the-assert-statement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/docs_python_org_2_reference_simple_stmts_html#the-assert-statement.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/docs_python_org_2_tutorial_errors_html#handling-exceptions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/docs_python_org_2_tutorial_errors_html#handling-exceptions.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/docs_python_org_3_library_exceptions_html#bltin-exceptions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/docs_python_org_3_library_exceptions_html#bltin-exceptions.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/docs_python_org_3_tutorial_errors_html#raising-exceptions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/docs_python_org_3_tutorial_errors_html#raising-exceptions.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/docs_python_org_3_tutorial_errors_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/docs_python_org_3_tutorial_errors_html.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/doughellmann_com_blog_2009_06_19_python-exception-handling-techniques_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/doughellmann_com_blog_2009_06_19_python-exception-handling-techniques_.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Errors and Exceptions/stackoverflow_com_questions_5142418_what_is_the_use_of_asser.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Errors and Exceptions/stackoverflow_com_questions_5142418_what_is_the_use_of_asser.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Other Test Concepts/coursera.org-More About Tests.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Other Test Concepts/coursera.org-More About Tests.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Other Test Concepts/landing_google_com_sre_sre-book_chapters_monitoring-distributed-systems_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Other Test Concepts/landing_google_com_sre_sre-book_chapters_monitoring-distributed-systems_.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Other Test Concepts/landing_google_com_sre_sre-book_chapters_testing-reliability_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Other Test Concepts/landing_google_com_sre_sre-book_chapters_testing-reliability_.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Other Test Concepts/testing_googleblog_com_2007_10_performance-testing_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Other Test Concepts/testing_googleblog_com_2007_10_performance-testing_html.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Other Test Concepts/testing_googleblog_com_2008_09_test-first-is-fun_08_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Other Test Concepts/testing_googleblog_com_2008_09_test-first-is-fun_08_html.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Other Test Concepts/www_guru99_com_exploratory-testing_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Other Test Concepts/www_guru99_com_exploratory-testing_html.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Other Test Concepts/www_guru99_com_smoke-testing_html.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Other Test Concepts/www_guru99_com_smoke-testing_html.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Unit Tests/coursera.org-Help with Jupyter Notebooks.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Unit Tests/coursera.org-Help with Jupyter Notebooks.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Unit Tests/coursera.org-Unit Test Cheat-Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Unit Tests/coursera.org-Unit Test Cheat-Sheet.pdf -------------------------------------------------------------------------------- /Module 5/Reading/Unit Tests/docs_python_org_3_library_unittest_html#basic-example.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/Reading/Unit Tests/docs_python_org_3_library_unittest_html#basic-example.pdf -------------------------------------------------------------------------------- /Module 5/Scipts/charfreq.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | def char_frequency(filename): 4 | """ 5 | Counts the frequency of each character in the given file. 6 | """ 7 | # First try to open the file 8 | try: 9 | f = open(filename) 10 | # code in the except block is only executed if one of the instructions in the try block raise an error of the matching type 11 | except OSError: 12 | return None 13 | 14 | # Now process the file 15 | characters = {} 16 | for line in f: 17 | for char in line: 18 | characters[char] = characters.get(char, 0) + 1 19 | f.close() 20 | return characters -------------------------------------------------------------------------------- /Module 5/Scipts/rearrange.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | 5 | def rearrange_name(name): 6 | result = re.search(r"^([\w .]*), ([\w .]*)$", name) 7 | # to account edge cases 8 | if result is None: 9 | return name 10 | return "{} {}".format(result[2], result[1]) 11 | 12 | # from rearrange import rearrange_name 13 | 14 | # from keyword imports a function from a script in the python3 interpreter 15 | # importing it in this way, the function can be called without having to write the module name each time we want to call it 16 | -------------------------------------------------------------------------------- /Module 5/Scipts/rearrange_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Writing Unit Tests in Python 4 | # from keyword imports a function from a script in the python3 interpreter 5 | # the function can be called without having to write the module name each time we want to call it 6 | from rearrange import rearrange_name 7 | # unittest module includes classes and methods for creating unit tests 8 | import unittest 9 | 10 | # Include the class that we want to inherit from in the parentheses 11 | # TestRearrange class inherits from TestCase 12 | class TestRearrange(unittest.TestCase): 13 | def test_basic(self): 14 | testcase = "Lovelace, Ada" 15 | expected = "Ada Lovelace" 16 | self.assertEqual(rearrange_name(testcase), expected) 17 | 18 | # test for an edge case 19 | def test_empty(self): 20 | testcase = "" 21 | expected = "" 22 | self.assertEqual(rearrange_name(testcase), expected) 23 | 24 | def test_double_name(self): 25 | testcase = "Hopper, Grace M." 26 | expected = "Grace M. Hopper" 27 | self.assertEqual(rearrange_name(testcase), expected) 28 | 29 | def test_one_name(self): 30 | testcase = "Voltaire" 31 | expected = "Voltaire" 32 | self.assertEqual(rearrange_name(testcase), expected) 33 | 34 | # Runs the test 35 | unittest.main() -------------------------------------------------------------------------------- /Module 5/Scipts/validations.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | def validate_user(username, minlen): 4 | assert type(username) == str, "username must be a string" 5 | if minlen < 1: 6 | raise ValueError("minlen must be at least 1") 7 | if len(username) < minlen: 8 | return False 9 | if not username.isalnum(): 10 | return False 11 | return True -------------------------------------------------------------------------------- /Module 5/Scipts/validations_test.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import unittest 4 | 5 | from validations import validate_user 6 | 7 | class TestValidateUser(unittest.TestCase): 8 | def test_valid(self): 9 | self.assertEqual(validate_user('validuser', 3), True) 10 | 11 | def test_too_short(self): 12 | self.assertEqual(validate_user('inv', 5), False) 13 | 14 | def test_invalid_characters(self): 15 | self.assertEqual(validate_user('invalid_user', 1), False) 16 | 17 | def test_invalid_minlen(self): 18 | self.assertRaises(ValueError, validate_user, "user", -1) 19 | 20 | # Run the test 21 | unittest.main() -------------------------------------------------------------------------------- /Module 5/notesImages/code_bug_image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/code_bug_image12.png -------------------------------------------------------------------------------- /Module 5/notesImages/code_bug_squash_image13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/code_bug_squash_image13.png -------------------------------------------------------------------------------- /Module 5/notesImages/code_load_image15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/code_load_image15.png -------------------------------------------------------------------------------- /Module 5/notesImages/code_smoke_image14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/code_smoke_image14.png -------------------------------------------------------------------------------- /Module 5/notesImages/double_name_testcase_output_image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/double_name_testcase_output_image7.png -------------------------------------------------------------------------------- /Module 5/notesImages/empty_string_testcase_output_image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/empty_string_testcase_output_image5.png -------------------------------------------------------------------------------- /Module 5/notesImages/empty_string_testcase_output_image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/empty_string_testcase_output_image6.png -------------------------------------------------------------------------------- /Module 5/notesImages/integration_test_diag_image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/integration_test_diag_image11.png -------------------------------------------------------------------------------- /Module 5/notesImages/manual_testing_example_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/manual_testing_example_image2.png -------------------------------------------------------------------------------- /Module 5/notesImages/one_name_testcase_output_image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/one_name_testcase_output_image8.png -------------------------------------------------------------------------------- /Module 5/notesImages/one_name_testcase_output_image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/one_name_testcase_output_image9.png -------------------------------------------------------------------------------- /Module 5/notesImages/output_unittest_example_image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/output_unittest_example_image4.png -------------------------------------------------------------------------------- /Module 5/notesImages/rearrange_unit_test_example_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/rearrange_unit_test_example_image3.png -------------------------------------------------------------------------------- /Module 5/notesImages/sample_image_image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/sample_image_image1.png -------------------------------------------------------------------------------- /Module 5/notesImages/test_driven_approach_image16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/test_driven_approach_image16.png -------------------------------------------------------------------------------- /Module 5/notesImages/validations_after_assert_image22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/validations_after_assert_image22.png -------------------------------------------------------------------------------- /Module 5/notesImages/validations_script_input_empty_list_image20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/validations_script_input_empty_list_image20.png -------------------------------------------------------------------------------- /Module 5/notesImages/validations_script_input_len_1_list_image21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/validations_script_input_len_1_list_image21.png -------------------------------------------------------------------------------- /Module 5/notesImages/validations_script_input_number_image19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/validations_script_input_number_image19.png -------------------------------------------------------------------------------- /Module 5/notesImages/validations_script_other_params_image18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/validations_script_other_params_image18.png -------------------------------------------------------------------------------- /Module 5/notesImages/validations_script_raise_output_image17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/validations_script_raise_output_image17.png -------------------------------------------------------------------------------- /Module 5/notesImages/validations_test_output_image23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/validations_test_output_image23.png -------------------------------------------------------------------------------- /Module 5/notesImages/white_box_black_box_animation_image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 5/notesImages/white_box_black_box_animation_image10.png -------------------------------------------------------------------------------- /Module 6/Assignments/Editing Files using Substrings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/Editing Files using Substrings.pdf -------------------------------------------------------------------------------- /Module 6/Assignments/Editing Files using Substrings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/Editing Files using Substrings.png -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/data/janez_profile_11042019.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/Solution/data/janez_profile_11042019.doc -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/data/jdoe_contact_07292018.csv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/Solution/data/jdoe_contact_07292018.csv -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/data/jdoe_profile_07272018.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/Solution/data/jdoe_profile_07272018.doc -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/data/kwood_pic_04032017.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/Solution/data/kwood_pic_04032017.jpg -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/data/kwood_profile_04022017.doc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/Solution/data/kwood_profile_04022017.doc -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/data/list.txt: -------------------------------------------------------------------------------- 1 | 001 jane /data/jane_profile_07272018.doc 2 | 002 kwood /data/kwood_profile_04022017.doc 3 | 003 pchow /data/pchow_profile_05152019.doc 4 | 004 janez /data/janez_profile_11042019.doc 5 | 005 jane /data/jane_pic_07282018.jpg 6 | 006 kwood /data/kwood_pic_04032017.jpg 7 | 007 pchow /data/pchow_pic_05162019.jpg 8 | 008 jane /data/jane_contact_07292018.csv 9 | 009 kwood /data/kwood_contact_04042017.csv 10 | 010 pchow /data/pchow_contact_05172019.csv 11 | -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/data/pchow_pic_05162019.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/Solution/data/pchow_pic_05162019.jpg -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/scripts/changeJane.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import sys 4 | import subprocess 5 | 6 | f = open(sys.argv[1], "r") 7 | for line in f.readlines(): 8 | old_name = line.strip() 9 | new_name = old_name.replace("jane", "jdoe") 10 | subprocess.run(["mv", old_name, new_name]) 11 | f.close() 12 | -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/scripts/findJane.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | > oldFiles.txt 4 | 5 | files=$(grep " jane " ../data/list.txt | cut -d' ' -f3) 6 | for f in $files; do 7 | if [ -e $HOME$f ]; then 8 | echo $HOME$f >> oldFiles.txt; 9 | fi 10 | done 11 | 12 | -------------------------------------------------------------------------------- /Module 6/Assignments/Solution/scripts/oldFiles.txt: -------------------------------------------------------------------------------- 1 | /home/student-00-46df8174b8f9/data/jane_profile_07272018.doc 2 | /home/student-00-46df8174b8f9/data/jane_contact_07292018.csv 3 | -------------------------------------------------------------------------------- /Module 6/Assignments/googlecoursera.qwiklabs.com-Editing Files using Substrings.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Assignments/googlecoursera.qwiklabs.com-Editing Files using Substrings.pdf -------------------------------------------------------------------------------- /Module 6/Quiz/Advanced Bash Concepts/quiz_module_6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Advanced Bash Concepts/quiz_module_6.pdf -------------------------------------------------------------------------------- /Module 6/Quiz/Advanced Bash Concepts/quiz_module_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Advanced Bash Concepts/quiz_module_6.png -------------------------------------------------------------------------------- /Module 6/Quiz/Advanced Bash Concepts/quiz_module_6_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Advanced Bash Concepts/quiz_module_6_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 6/Quiz/Bash Scripting/quiz_module_6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Bash Scripting/quiz_module_6.pdf -------------------------------------------------------------------------------- /Module 6/Quiz/Bash Scripting/quiz_module_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Bash Scripting/quiz_module_6.png -------------------------------------------------------------------------------- /Module 6/Quiz/Bash Scripting/quiz_module_6_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Bash Scripting/quiz_module_6_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 6/Quiz/Interacting with the Command Line Shell/quiz_module_6.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Interacting with the Command Line Shell/quiz_module_6.pdf -------------------------------------------------------------------------------- /Module 6/Quiz/Interacting with the Command Line Shell/quiz_module_6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Interacting with the Command Line Shell/quiz_module_6.png -------------------------------------------------------------------------------- /Module 6/Quiz/Interacting with the Command Line Shell/quiz_module_6_afterSubmit.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Quiz/Interacting with the Command Line Shell/quiz_module_6_afterSubmit.pdf -------------------------------------------------------------------------------- /Module 6/Reading/Bash Scripting/coursera.org-Bash Scripting Resources.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Reading/Bash Scripting/coursera.org-Bash Scripting Resources.pdf -------------------------------------------------------------------------------- /Module 6/Reading/Bash Scripting/linuxconfig_org_bash-scripting-tutorial-for-beginners.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Reading/Bash Scripting/linuxconfig_org_bash-scripting-tutorial-for-beginners.pdf -------------------------------------------------------------------------------- /Module 6/Reading/Bash Scripting/ryanstutorials_net_bash-scripting-tutorial_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Reading/Bash Scripting/ryanstutorials_net_bash-scripting-tutorial_.pdf -------------------------------------------------------------------------------- /Module 6/Reading/Bash Scripting/www_shellscript_sh_.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Reading/Bash Scripting/www_shellscript_sh_.pdf -------------------------------------------------------------------------------- /Module 6/Reading/Interacting with the Command Line Shell/coursera.org-Basic Linux Commands Cheat-Sheet.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Reading/Interacting with the Command Line Shell/coursera.org-Basic Linux Commands Cheat-Sheet.pdf -------------------------------------------------------------------------------- /Module 6/Reading/Interacting with the Command Line Shell/coursera.org-Redirections Pipes and Signals.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Reading/Interacting with the Command Line Shell/coursera.org-Redirections Pipes and Signals.pdf -------------------------------------------------------------------------------- /Module 6/Scripts/capitalize.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | 5 | for line in sys.stdin: 6 | print(line.strip().capitalize()) 7 | -------------------------------------------------------------------------------- /Module 6/Scripts/check-localhost.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if grep "127.0.0.1" /etc/hosts; then 4 | echo "Everything ok" 5 | else 6 | echo "ERROR! 127.0.0.1 is not in /etc/hosts" 7 | fi -------------------------------------------------------------------------------- /Module 6/Scripts/fruits.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for fruit in peach orange apple; do 4 | echo "I like $fruit!" 5 | done -------------------------------------------------------------------------------- /Module 6/Scripts/gather-information.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | line="-------------------------------------------------------------------" 4 | 5 | echo "Starting time at: $(date)"; echo $line 6 | 7 | echo "UPTIME"; uptime; echo $line 8 | 9 | echo "FREE"; free; echo $line 10 | 11 | echo "WHO"; who; echo $line 12 | 13 | echo "Finshing at: $(date)" -------------------------------------------------------------------------------- /Module 6/Scripts/old_website/about.HTM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Scripts/old_website/about.HTM -------------------------------------------------------------------------------- /Module 6/Scripts/old_website/contact.HTM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Scripts/old_website/contact.HTM -------------------------------------------------------------------------------- /Module 6/Scripts/old_website/footer.HTM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Scripts/old_website/footer.HTM -------------------------------------------------------------------------------- /Module 6/Scripts/old_website/index.HTM: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/Scripts/old_website/index.HTM -------------------------------------------------------------------------------- /Module 6/Scripts/old_website/rename.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for file in *.HTM; do 4 | name=$(basename "$file" .HTM) 5 | echo mv "$file" "$name.html" 6 | done -------------------------------------------------------------------------------- /Module 6/Scripts/random-exit.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | import sys 4 | import random 5 | 6 | # Uses random randint to generate a value between zero and three 7 | value=random.randint(0, 3) 8 | # Prints the selected value and exits with it 9 | print("Returning: " + str(value)) 10 | sys.exit(value) -------------------------------------------------------------------------------- /Module 6/Scripts/retry.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | n=0 4 | command=$1 5 | while ! $command && [ $n -le 5 ]; do 6 | sleep $n 7 | ((n=n+1)) 8 | echo "Retry #$n" 9 | done; -------------------------------------------------------------------------------- /Module 6/Scripts/stdout_example.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | print("Don't mind me, just a bit of text here...") -------------------------------------------------------------------------------- /Module 6/Scripts/streams_err.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | data = input('This will come from STDIN: ') 4 | print('Now we write it to STDOUT: ' + data) 5 | raise ValueError('Now we generate an error to STDERR') 6 | -------------------------------------------------------------------------------- /Module 6/Scripts/toploglines.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | for logfile in /var/log/*log; do 4 | echo "Processing: $logfile" 5 | cut -d' ' -f5- $logfile | sort | uniq -c | sort -nr | head -5 6 | done -------------------------------------------------------------------------------- /Module 6/Scripts/while.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | n=1 4 | while [ $n -le 5 ]; do 5 | echo "Iteration number $n" 6 | ((n+=1)) 7 | done -------------------------------------------------------------------------------- /Module 6/notesImages/bash_python_os_diag_image42.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/bash_python_os_diag_image42.png -------------------------------------------------------------------------------- /Module 6/notesImages/check_localhost_script_output_image31.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/check_localhost_script_output_image31.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_complex_pipes_image16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_complex_pipes_image16.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_ls_less_pipes_image15.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_ls_less_pipes_image15.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_redirection_STDERR_example_image12.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_redirection_STDERR_example_image12.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_redirection_STDERR_output_example_image13.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_redirection_STDERR_output_example_image13.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_redirection_STDIN_example_image11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_redirection_STDIN_example_image11.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_redirection_echo_STDOUT_example_image14.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_redirection_echo_STDOUT_example_image14.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_redirection_example_image8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_redirection_example_image8.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_redirection_output_append_example_image10.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_redirection_output_append_example_image10.png -------------------------------------------------------------------------------- /Module 6/notesImages/cmd_redirection_output_example_image9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cmd_redirection_output_example_image9.png -------------------------------------------------------------------------------- /Module 6/notesImages/cut_cmd_varlog_syslogs_example_image41.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cut_cmd_varlog_syslogs_example_image41.png -------------------------------------------------------------------------------- /Module 6/notesImages/cut_command_example_image39.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cut_command_example_image39.png -------------------------------------------------------------------------------- /Module 6/notesImages/cut_command_example_image40.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/cut_command_example_image40.png -------------------------------------------------------------------------------- /Module 6/notesImages/for_loop_example_image35.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/for_loop_example_image35.png -------------------------------------------------------------------------------- /Module 6/notesImages/for_loop_rename_example_image36.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/for_loop_rename_example_image36.png -------------------------------------------------------------------------------- /Module 6/notesImages/for_loop_rename_example_image37.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/for_loop_rename_example_image37.png -------------------------------------------------------------------------------- /Module 6/notesImages/for_loop_rename_example_image38.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/for_loop_rename_example_image38.png -------------------------------------------------------------------------------- /Module 6/notesImages/gather_information_script_output_image24.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/gather_information_script_output_image24.png -------------------------------------------------------------------------------- /Module 6/notesImages/gather_information_script_output_image26.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/gather_information_script_output_image26.png -------------------------------------------------------------------------------- /Module 6/notesImages/glob_questionmark_example_image30.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/glob_questionmark_example_image30.png -------------------------------------------------------------------------------- /Module 6/notesImages/globs_star_example_image27.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/globs_star_example_image27.png -------------------------------------------------------------------------------- /Module 6/notesImages/globs_star_example_image29.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/globs_star_example_image29.png -------------------------------------------------------------------------------- /Module 6/notesImages/globs_star_prefix_example_image28.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/globs_star_prefix_example_image28.png -------------------------------------------------------------------------------- /Module 6/notesImages/linux_cmd_cp_example_image2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/linux_cmd_cp_example_image2.png -------------------------------------------------------------------------------- /Module 6/notesImages/linux_cmd_ls_la_example_image4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/linux_cmd_ls_la_example_image4.png -------------------------------------------------------------------------------- /Module 6/notesImages/linux_cmd_mv_cp_example_image5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/linux_cmd_mv_cp_example_image5.png -------------------------------------------------------------------------------- /Module 6/notesImages/linux_cmd_output_image1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/linux_cmd_output_image1.png -------------------------------------------------------------------------------- /Module 6/notesImages/linux_cmd_rm_example_image6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/linux_cmd_rm_example_image6.png -------------------------------------------------------------------------------- /Module 6/notesImages/linux_cmd_rmdir_example_image7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/linux_cmd_rmdir_example_image7.png -------------------------------------------------------------------------------- /Module 6/notesImages/linux_cmd_touch_example_image3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/linux_cmd_touch_example_image3.png -------------------------------------------------------------------------------- /Module 6/notesImages/ping_cmd_example_image19.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/ping_cmd_example_image19.png -------------------------------------------------------------------------------- /Module 6/notesImages/ping_cmd_kill_example_image23.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/ping_cmd_kill_example_image23.png -------------------------------------------------------------------------------- /Module 6/notesImages/ping_cmd_rerun_fg_example_image22.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/ping_cmd_rerun_fg_example_image22.png -------------------------------------------------------------------------------- /Module 6/notesImages/ping_cmd_terminate_ctrlZ_example_image21.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/ping_cmd_terminate_ctrlZ_example_image21.png -------------------------------------------------------------------------------- /Module 6/notesImages/ping_cmd_terminate_example_image20.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/ping_cmd_terminate_example_image20.png -------------------------------------------------------------------------------- /Module 6/notesImages/python_capitalize_example_image17.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/python_capitalize_example_image17.png -------------------------------------------------------------------------------- /Module 6/notesImages/python_capitalize_example_image18.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/python_capitalize_example_image18.png -------------------------------------------------------------------------------- /Module 6/notesImages/test_cmd_example_image32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/test_cmd_example_image32.png -------------------------------------------------------------------------------- /Module 6/notesImages/test_cmd_example_image33.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/test_cmd_example_image33.png -------------------------------------------------------------------------------- /Module 6/notesImages/variable_assignment_error_image25.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/variable_assignment_error_image25.png -------------------------------------------------------------------------------- /Module 6/notesImages/while_loop_example_image34.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 6/notesImages/while_loop_example_image34.png -------------------------------------------------------------------------------- /Module 7/Assignments/Final Project : Problem Statement Video/Help with Research and Planning/Help with Research and Planning.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 7/Assignments/Final Project : Problem Statement Video/Help with Research and Planning/Help with Research and Planning.mp4 -------------------------------------------------------------------------------- /Module 7/Assignments/Final Project : Problem Statement Video/Help with Research and Planning/subtitle.txt: -------------------------------------------------------------------------------- 1 | We've now gone over the problems statement 2 | of our final project. At first sight, it might 3 | sound pretty complex. But let's break it down into smaller more 4 | digestible pieces and discuss how we can move into the next steps to do the 5 | necessary research and planning. We've said that we want to find some specific log lines 6 | in the sy log file. We strongly recommend 7 | that you use regular expressions to find them. It'll be easier to extract 8 | information you want that way. To figure out the right 9 | regular expression, you can use a website 10 | like Greg X101.com which can help you 11 | test your expression and understand what's 12 | going on with it. Once you have a pattern 13 | that you think and work, try it out in a Python 14 | interpreter to verify that it matches the right lines and captures the 15 | right information. After extracting the information, you'll need to count 16 | how many errors are of the same type, and how many info 17 | and error messages there are for a given user. Can you think of what data structure might 18 | help you with that? If you're thinking dictionaries, then you're on the right track. You'll want to use a couple 19 | of different dictionaries. One to account error messages and another to count per user usage. You'll then need to sort the data in a dictionary's by 20 | different criteria. We looked at sorting in the Introduction 21 | to Python course. Feel free to re-watch 22 | that video and reread the Python 23 | documentation on sorting. The output of your Python script should be a couple of CSV files. Each of them containing 24 | the names of the columns and the data in the order that 25 | it needs to be presented. Once those files are generated, you'll need to call 26 | the CSV html.py script to create HTML 27 | files based on CSV data. You'll have access to look 28 | at how the script works but the key is to pass 29 | two parameters to it. The name of the CSV file to read and the name of 30 | the HTML file generate. You could do this last step from either a Python script 31 | or a bash script. Since the script will be only calling commands 32 | and moving files, we recommend doing a bash. Keep it short and sweet. We recommend that you research, plan and even write the pieces of code all before starting 33 | the actual lab. Good luck. You've got it. -------------------------------------------------------------------------------- /Module 7/Assignments/Final Project : Problem Statement Video/Help with Research and Planning/subtitles-en.vtt: -------------------------------------------------------------------------------- 1 | WEBVTT 2 | 3 | 1 4 | 00:00:07.640 --> 00:00:09.705 5 | We've now gone over 6 | 7 | 2 8 | 00:00:09.705 --> 00:00:12.090 9 | the problems statement 10 | of our final project. 11 | 12 | 3 13 | 00:00:12.090 --> 00:00:15.420 14 | At first sight, it might 15 | sound pretty complex. 16 | 17 | 4 18 | 00:00:15.420 --> 00:00:16.800 19 | But let's break it down into 20 | 21 | 5 22 | 00:00:16.800 --> 00:00:18.660 23 | smaller more 24 | digestible pieces and 25 | 26 | 6 27 | 00:00:18.660 --> 00:00:20.070 28 | discuss how we can move into 29 | 30 | 7 31 | 00:00:20.070 --> 00:00:22.590 32 | the next steps to do the 33 | necessary research and planning. 34 | 35 | 8 36 | 00:00:22.590 --> 00:00:24.150 37 | We've said that we want to find 38 | 39 | 9 40 | 00:00:24.150 --> 00:00:27.015 41 | some specific log lines 42 | in the sy log file. 43 | 44 | 10 45 | 00:00:27.015 --> 00:00:28.770 46 | We strongly recommend 47 | that you use 48 | 49 | 11 50 | 00:00:28.770 --> 00:00:30.705 51 | regular expressions to find them. 52 | 53 | 12 54 | 00:00:30.705 --> 00:00:33.690 55 | It'll be easier to extract 56 | information you want that way. 57 | 58 | 13 59 | 00:00:33.690 --> 00:00:35.960 60 | To figure out the right 61 | regular expression, 62 | 63 | 14 64 | 00:00:35.960 --> 00:00:38.925 65 | you can use a website 66 | like Greg X101.com 67 | 68 | 15 69 | 00:00:38.925 --> 00:00:40.595 70 | which can help you 71 | test your expression 72 | 73 | 16 74 | 00:00:40.595 --> 00:00:42.635 75 | and understand what's 76 | going on with it. 77 | 78 | 17 79 | 00:00:42.635 --> 00:00:45.095 80 | Once you have a pattern 81 | that you think and work, 82 | 83 | 18 84 | 00:00:45.095 --> 00:00:47.750 85 | try it out in a Python 86 | interpreter to verify that it 87 | 88 | 19 89 | 00:00:47.750 --> 00:00:49.010 90 | matches the right lines 91 | 92 | 20 93 | 00:00:49.010 --> 00:00:51.035 94 | and captures the 95 | right information. 96 | 97 | 21 98 | 00:00:51.035 --> 00:00:53.090 99 | After extracting the information, 100 | 101 | 22 102 | 00:00:53.090 --> 00:00:54.635 103 | you'll need to count 104 | how many errors 105 | 106 | 23 107 | 00:00:54.635 --> 00:00:55.820 108 | are of the same type, 109 | 110 | 24 111 | 00:00:55.820 --> 00:00:57.875 112 | and how many info 113 | and error messages 114 | 115 | 25 116 | 00:00:57.875 --> 00:00:59.660 117 | there are for a given user. 118 | 119 | 26 120 | 00:00:59.660 --> 00:01:00.830 121 | Can you think of what 122 | 123 | 27 124 | 00:01:00.830 --> 00:01:02.750 125 | data structure might 126 | help you with that? 127 | 128 | 28 129 | 00:01:02.750 --> 00:01:04.625 130 | If you're thinking dictionaries, 131 | 132 | 29 133 | 00:01:04.625 --> 00:01:06.140 134 | then you're on the right track. 135 | 136 | 30 137 | 00:01:06.140 --> 00:01:08.465 138 | You'll want to use a couple 139 | of different dictionaries. 140 | 141 | 31 142 | 00:01:08.465 --> 00:01:10.310 143 | One to account error messages and 144 | 145 | 32 146 | 00:01:10.310 --> 00:01:12.665 147 | another to count per user usage. 148 | 149 | 33 150 | 00:01:12.665 --> 00:01:14.735 151 | You'll then need to sort the data 152 | 153 | 34 154 | 00:01:14.735 --> 00:01:17.075 155 | in a dictionary's by 156 | different criteria. 157 | 158 | 35 159 | 00:01:17.075 --> 00:01:18.620 160 | We looked at sorting in 161 | 162 | 36 163 | 00:01:18.620 --> 00:01:20.510 164 | the Introduction 165 | to Python course. 166 | 167 | 37 168 | 00:01:20.510 --> 00:01:22.850 169 | Feel free to re-watch 170 | that video and 171 | 172 | 38 173 | 00:01:22.850 --> 00:01:25.640 174 | reread the Python 175 | documentation on sorting. 176 | 177 | 39 178 | 00:01:25.640 --> 00:01:27.320 179 | The output of your Python script 180 | 181 | 40 182 | 00:01:27.320 --> 00:01:29.060 183 | should be a couple of CSV files. 184 | 185 | 41 186 | 00:01:29.060 --> 00:01:31.430 187 | Each of them containing 188 | the names of the columns 189 | 190 | 42 191 | 00:01:31.430 --> 00:01:34.435 192 | and the data in the order that 193 | it needs to be presented. 194 | 195 | 43 196 | 00:01:34.435 --> 00:01:36.400 197 | Once those files are generated, 198 | 199 | 44 200 | 00:01:36.400 --> 00:01:39.185 201 | you'll need to call 202 | the CSV html.py 203 | 204 | 45 205 | 00:01:39.185 --> 00:01:42.995 206 | script to create HTML 207 | files based on CSV data. 208 | 209 | 46 210 | 00:01:42.995 --> 00:01:45.710 211 | You'll have access to look 212 | at how the script works 213 | 214 | 47 215 | 00:01:45.710 --> 00:01:48.440 216 | but the key is to pass 217 | two parameters to it. 218 | 219 | 48 220 | 00:01:48.440 --> 00:01:49.850 221 | The name of the CSV file to 222 | 223 | 49 224 | 00:01:49.850 --> 00:01:53.045 225 | read and the name of 226 | the HTML file generate. 227 | 228 | 50 229 | 00:01:53.045 --> 00:01:54.725 230 | You could do this last step from 231 | 232 | 51 233 | 00:01:54.725 --> 00:01:57.245 234 | either a Python script 235 | or a bash script. 236 | 237 | 52 238 | 00:01:57.245 --> 00:01:58.880 239 | Since the script will be only 240 | 241 | 53 242 | 00:01:58.880 --> 00:02:00.770 243 | calling commands 244 | and moving files, 245 | 246 | 54 247 | 00:02:00.770 --> 00:02:02.935 248 | we recommend doing a bash. 249 | 250 | 55 251 | 00:02:02.935 --> 00:02:05.105 252 | Keep it short and sweet. 253 | 254 | 56 255 | 00:02:05.105 --> 00:02:06.725 256 | We recommend that you research, 257 | 258 | 57 259 | 00:02:06.725 --> 00:02:08.330 260 | plan and even write the pieces of 261 | 262 | 58 263 | 00:02:08.330 --> 00:02:10.805 264 | code all before starting 265 | the actual lab. 266 | 267 | 59 268 | 00:02:10.805 --> 00:02:13.280 269 | Good luck. You've got it. -------------------------------------------------------------------------------- /Module 7/Assignments/Final Project : Problem Statement Video/Project Problem Statement/Project Problem Statement.mp4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 7/Assignments/Final Project : Problem Statement Video/Project Problem Statement/Project Problem Statement.mp4 -------------------------------------------------------------------------------- /Module 7/Assignments/Final Project : Problem Statement Video/Project Problem Statement/subtitle.txt: -------------------------------------------------------------------------------- 1 | Imagine a scenario, one of the servers used by your company runs a service called ticky. This service is an internal 2 | ticketing system used by a lot of different teams in the company to manage their work. The service logs a bunch 3 | of events to syslog, both when it runs successfully and when it encounters errors. Developers of the 4 | service are asking for your help with getting some information out of those logs, to better understand how 5 | the software is being used and how to 6 | improve it. No sweat. As an up and coming 7 | IT Professional, you enthusiastically 8 | accept this mission. So for your final 9 | project in this course, you'll write some 10 | automation scripts that will process the system log and generate a bunch of 11 | reports based on the information extracted 12 | from log files. The log lines follow a pattern similar to the 13 | ones we've seen before. Something like this. When the service runs correctly, it logs an info 14 | message to syslog, stating what it's done, the username, and the ticket 15 | number related to the event. If the service 16 | encounters a problem, it logs in error 17 | message to the syslog, indicating what was wrong and the username that 18 | triggered the action that caused the problem. The developers of 19 | the service want two different reports 20 | out of this data. The first one is a ranking of errors generated 21 | by the system. This means a list of all 22 | error messages logged, and how many times each 23 | of them was found, not taking into account 24 | the users involved. They should be sorted by 25 | the most common error to the least common error. The second one is a usage 26 | statistics for the service. This means, a list of all users 27 | that have used the system including how many 28 | info messages and how many error messages 29 | they've generated. This report should be 30 | sorted by username. To visualize the data 31 | in these reports, you want to generate a 32 | couple of webpages that'll be served by a web server 33 | running on the machine. To do this, you can make 34 | use of a script that's already in the system 35 | called csv_ to_html.py. This script converts 36 | the data in a CSV file into an HTML file containing 37 | a table with the data. Then, put the files 38 | in the directory that's used by the webserver 39 | to display the webpages. The goal is to have one 40 | script that can get all the necessary work 41 | done automatically, every day without any 42 | user interaction. This script doesn't need 43 | to do all the work itself. It can call on 44 | other scripts to do individual task and then 45 | put the results together. In fact, we recommend 46 | splitting the task so that each piece can be written 47 | and tested separately. I imagine that your 48 | mind is racing, your pulse might have 49 | spread up a little bit, and your palms are sweating 50 | all over the keyboard. Don't worry. This might 51 | sound like a lot of work. But once you've understood 52 | the problem and done some research and planning, everything will start 53 | to fall into place. In our next video, we'll 54 | give you some tips on how to start breaking this 55 | task down. Here we go. -------------------------------------------------------------------------------- /Module 7/Assignments/Final Project : Problem Statement Video/Project Problem Statement/subtitles-en.vtt: -------------------------------------------------------------------------------- 1 | WEBVTT 2 | 3 | 1 4 | 00:00:07.490 --> 00:00:10.500 5 | Imagine a scenario, one of 6 | 7 | 2 8 | 00:00:10.500 --> 00:00:11.910 9 | the servers used by your company 10 | 11 | 3 12 | 00:00:11.910 --> 00:00:13.875 13 | runs a service called ticky. 14 | 15 | 4 16 | 00:00:13.875 --> 00:00:16.920 17 | This service is an internal 18 | ticketing system used by 19 | 20 | 5 21 | 00:00:16.920 --> 00:00:18.210 22 | a lot of different teams in 23 | 24 | 6 25 | 00:00:18.210 --> 00:00:20.175 26 | the company to manage their work. 27 | 28 | 7 29 | 00:00:20.175 --> 00:00:23.100 30 | The service logs a bunch 31 | of events to syslog, 32 | 33 | 8 34 | 00:00:23.100 --> 00:00:24.960 35 | both when it runs successfully 36 | 37 | 9 38 | 00:00:24.960 --> 00:00:26.880 39 | and when it encounters errors. 40 | 41 | 10 42 | 00:00:26.880 --> 00:00:29.010 43 | Developers of the 44 | service are asking for 45 | 46 | 11 47 | 00:00:29.010 --> 00:00:30.165 48 | your help with getting some 49 | 50 | 12 51 | 00:00:30.165 --> 00:00:32.100 52 | information out of those logs, 53 | 54 | 13 55 | 00:00:32.100 --> 00:00:34.020 56 | to better understand how 57 | the software is being 58 | 59 | 14 60 | 00:00:34.020 --> 00:00:37.245 61 | used and how to 62 | improve it. No sweat. 63 | 64 | 15 65 | 00:00:37.245 --> 00:00:39.585 66 | As an up and coming 67 | IT Professional, 68 | 69 | 16 70 | 00:00:39.585 --> 00:00:42.150 71 | you enthusiastically 72 | accept this mission. 73 | 74 | 17 75 | 00:00:42.150 --> 00:00:45.325 76 | So for your final 77 | project in this course, 78 | 79 | 18 80 | 00:00:45.325 --> 00:00:47.300 81 | you'll write some 82 | automation scripts that 83 | 84 | 19 85 | 00:00:47.300 --> 00:00:49.220 86 | will process the system log and 87 | 88 | 20 89 | 00:00:49.220 --> 00:00:50.870 90 | generate a bunch of 91 | reports based on 92 | 93 | 21 94 | 00:00:50.870 --> 00:00:53.570 95 | the information extracted 96 | from log files. 97 | 98 | 22 99 | 00:00:53.570 --> 00:00:55.220 100 | The log lines follow 101 | 102 | 23 103 | 00:00:55.220 --> 00:00:57.820 104 | a pattern similar to the 105 | ones we've seen before. 106 | 107 | 24 108 | 00:00:57.820 --> 00:01:00.310 109 | Something like this. 110 | 111 | 25 112 | 00:01:01.640 --> 00:01:04.125 113 | When the service runs correctly, 114 | 115 | 26 116 | 00:01:04.125 --> 00:01:06.375 117 | it logs an info 118 | message to syslog, 119 | 120 | 27 121 | 00:01:06.375 --> 00:01:07.680 122 | stating what it's done, 123 | 124 | 28 125 | 00:01:07.680 --> 00:01:11.120 126 | the username, and the ticket 127 | number related to the event. 128 | 129 | 29 130 | 00:01:11.120 --> 00:01:13.425 131 | If the service 132 | encounters a problem, 133 | 134 | 30 135 | 00:01:13.425 --> 00:01:15.700 136 | it logs in error 137 | message to the syslog, 138 | 139 | 31 140 | 00:01:15.700 --> 00:01:17.630 141 | indicating what was wrong and the 142 | 143 | 32 144 | 00:01:17.630 --> 00:01:18.860 145 | username that 146 | triggered the action 147 | 148 | 33 149 | 00:01:18.860 --> 00:01:20.120 150 | that caused the problem. 151 | 152 | 34 153 | 00:01:20.120 --> 00:01:21.995 154 | The developers of 155 | the service want 156 | 157 | 35 158 | 00:01:21.995 --> 00:01:24.185 159 | two different reports 160 | out of this data. 161 | 162 | 36 163 | 00:01:24.185 --> 00:01:26.045 164 | The first one is a ranking 165 | 166 | 37 167 | 00:01:26.045 --> 00:01:28.130 168 | of errors generated 169 | by the system. 170 | 171 | 38 172 | 00:01:28.130 --> 00:01:31.279 173 | This means a list of all 174 | error messages logged, 175 | 176 | 39 177 | 00:01:31.279 --> 00:01:33.799 178 | and how many times each 179 | of them was found, 180 | 181 | 40 182 | 00:01:33.799 --> 00:01:36.485 183 | not taking into account 184 | the users involved. 185 | 186 | 41 187 | 00:01:36.485 --> 00:01:38.780 188 | They should be sorted by 189 | the most common error 190 | 191 | 42 192 | 00:01:38.780 --> 00:01:40.400 193 | to the least common error. 194 | 195 | 43 196 | 00:01:40.400 --> 00:01:44.495 197 | The second one is a usage 198 | statistics for the service. 199 | 200 | 44 201 | 00:01:44.495 --> 00:01:48.005 202 | This means, a list of all users 203 | that have used the system 204 | 205 | 45 206 | 00:01:48.005 --> 00:01:49.850 207 | including how many 208 | info messages and 209 | 210 | 46 211 | 00:01:49.850 --> 00:01:52.415 212 | how many error messages 213 | they've generated. 214 | 215 | 47 216 | 00:01:52.415 --> 00:01:55.700 217 | This report should be 218 | sorted by username. 219 | 220 | 48 221 | 00:01:55.700 --> 00:01:58.100 222 | To visualize the data 223 | in these reports, 224 | 225 | 49 226 | 00:01:58.100 --> 00:02:00.470 227 | you want to generate a 228 | couple of webpages that'll 229 | 230 | 50 231 | 00:02:00.470 --> 00:02:03.350 232 | be served by a web server 233 | running on the machine. 234 | 235 | 51 236 | 00:02:03.350 --> 00:02:06.185 237 | To do this, you can make 238 | use of a script that's 239 | 240 | 52 241 | 00:02:06.185 --> 00:02:09.830 242 | already in the system 243 | called csv_ to_html.py. 244 | 245 | 53 246 | 00:02:09.830 --> 00:02:13.145 247 | This script converts 248 | the data in a CSV file 249 | 250 | 54 251 | 00:02:13.145 --> 00:02:16.650 252 | into an HTML file containing 253 | a table with the data. 254 | 255 | 55 256 | 00:02:16.650 --> 00:02:19.430 257 | Then, put the files 258 | in the directory 259 | 260 | 56 261 | 00:02:19.430 --> 00:02:22.330 262 | that's used by the webserver 263 | to display the webpages. 264 | 265 | 57 266 | 00:02:22.330 --> 00:02:24.455 267 | The goal is to have one 268 | script that can get 269 | 270 | 58 271 | 00:02:24.455 --> 00:02:26.660 272 | all the necessary work 273 | done automatically, 274 | 275 | 59 276 | 00:02:26.660 --> 00:02:29.615 277 | every day without any 278 | user interaction. 279 | 280 | 60 281 | 00:02:29.615 --> 00:02:32.575 282 | This script doesn't need 283 | to do all the work itself. 284 | 285 | 61 286 | 00:02:32.575 --> 00:02:34.355 287 | It can call on 288 | other scripts to do 289 | 290 | 62 291 | 00:02:34.355 --> 00:02:37.070 292 | individual task and then 293 | put the results together. 294 | 295 | 63 296 | 00:02:37.070 --> 00:02:39.740 297 | In fact, we recommend 298 | splitting the task so 299 | 300 | 64 301 | 00:02:39.740 --> 00:02:42.545 302 | that each piece can be written 303 | and tested separately. 304 | 305 | 65 306 | 00:02:42.545 --> 00:02:44.635 307 | I imagine that your 308 | mind is racing, 309 | 310 | 66 311 | 00:02:44.635 --> 00:02:46.485 312 | your pulse might have 313 | spread up a little bit, 314 | 315 | 67 316 | 00:02:46.485 --> 00:02:49.010 317 | and your palms are sweating 318 | all over the keyboard. 319 | 320 | 68 321 | 00:02:49.010 --> 00:02:52.185 322 | Don't worry. This might 323 | sound like a lot of work. 324 | 325 | 69 326 | 00:02:52.185 --> 00:02:54.030 327 | But once you've understood 328 | the problem and 329 | 330 | 70 331 | 00:02:54.030 --> 00:02:56.050 332 | done some research and planning, 333 | 334 | 71 335 | 00:02:56.050 --> 00:02:58.295 336 | everything will start 337 | to fall into place. 338 | 339 | 72 340 | 00:02:58.295 --> 00:03:00.800 341 | In our next video, we'll 342 | give you some tips on how 343 | 344 | 73 345 | 00:03:00.800 --> 00:03:04.110 346 | to start breaking this 347 | task down. Here we go. -------------------------------------------------------------------------------- /Module 7/Assignments/Log Analysis Using Regular Expressions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 7/Assignments/Log Analysis Using Regular Expressions.pdf -------------------------------------------------------------------------------- /Module 7/Assignments/Log Analysis Using Regular Expressions.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 7/Assignments/Log Analysis Using Regular Expressions.png -------------------------------------------------------------------------------- /Module 7/Assignments/Solution/data/error_message.csv: -------------------------------------------------------------------------------- 1 | Error,Count 2 | Timeout while retrieving information,15 3 | Connection to DB failed,13 4 | Tried to add information to closed ticket,12 5 | Permission denied while closing ticket,10 6 | The ticket was modified while updating,9 7 | Ticket doesn't exist,7 8 | -------------------------------------------------------------------------------- /Module 7/Assignments/Solution/data/syslog.log: -------------------------------------------------------------------------------- 1 | Jan 31 00:09:39 ubuntu.local ticky: INFO Created ticket [#4217] (mdouglas) 2 | Jan 31 00:16:25 ubuntu.local ticky: INFO Closed ticket [#1754] (noel) 3 | Jan 31 00:21:30 ubuntu.local ticky: ERROR The ticket was modified while updating (breee) 4 | Jan 31 00:44:34 ubuntu.local ticky: ERROR Permission denied while closing ticket (ac) 5 | Jan 31 01:00:50 ubuntu.local ticky: INFO Commented on ticket [#4709] (blossom) 6 | Jan 31 01:29:16 ubuntu.local ticky: INFO Commented on ticket [#6518] (rr.robinson) 7 | Jan 31 01:33:12 ubuntu.local ticky: ERROR Tried to add information to closed ticket (mcintosh) 8 | Jan 31 01:43:10 ubuntu.local ticky: ERROR Tried to add information to closed ticket (jackowens) 9 | Jan 31 01:49:29 ubuntu.local ticky: ERROR Tried to add information to closed ticket (mdouglas) 10 | Jan 31 02:30:04 ubuntu.local ticky: ERROR Timeout while retrieving information (oren) 11 | Jan 31 02:55:31 ubuntu.local ticky: ERROR Ticket doesn't exist (xlg) 12 | Jan 31 03:05:35 ubuntu.local ticky: ERROR Timeout while retrieving information (ahmed.miller) 13 | Jan 31 03:08:55 ubuntu.local ticky: ERROR Ticket doesn't exist (blossom) 14 | Jan 31 03:39:27 ubuntu.local ticky: ERROR The ticket was modified while updating (bpacheco) 15 | Jan 31 03:47:24 ubuntu.local ticky: ERROR Ticket doesn't exist (enim.non) 16 | Jan 31 04:30:04 ubuntu.local ticky: ERROR Permission denied while closing ticket (rr.robinson) 17 | Jan 31 04:31:49 ubuntu.local ticky: ERROR Tried to add information to closed ticket (oren) 18 | Jan 31 04:32:49 ubuntu.local ticky: ERROR Timeout while retrieving information (mcintosh) 19 | Jan 31 04:44:23 ubuntu.local ticky: ERROR Timeout while retrieving information (ahmed.miller) 20 | Jan 31 04:44:46 ubuntu.local ticky: ERROR Connection to DB failed (jackowens) 21 | Jan 31 04:49:28 ubuntu.local ticky: ERROR Permission denied while closing ticket (flavia) 22 | Jan 31 05:12:39 ubuntu.local ticky: ERROR Tried to add information to closed ticket (oren) 23 | Jan 31 05:18:45 ubuntu.local ticky: ERROR Tried to add information to closed ticket (sri) 24 | Jan 31 05:23:14 ubuntu.local ticky: INFO Commented on ticket [#1097] (breee) 25 | Jan 31 05:35:00 ubuntu.local ticky: ERROR Connection to DB failed (nonummy) 26 | Jan 31 05:45:30 ubuntu.local ticky: INFO Created ticket [#7115] (noel) 27 | Jan 31 05:51:30 ubuntu.local ticky: ERROR The ticket was modified while updating (flavia) 28 | Jan 31 05:57:46 ubuntu.local ticky: INFO Commented on ticket [#2253] (nonummy) 29 | Jan 31 06:12:02 ubuntu.local ticky: ERROR Connection to DB failed (oren) 30 | Jan 31 06:26:38 ubuntu.local ticky: ERROR Timeout while retrieving information (xlg) 31 | Jan 31 06:32:26 ubuntu.local ticky: INFO Created ticket [#7298] (ahmed.miller) 32 | Jan 31 06:36:25 ubuntu.local ticky: ERROR Timeout while retrieving information (flavia) 33 | Jan 31 06:57:00 ubuntu.local ticky: ERROR Connection to DB failed (jackowens) 34 | Jan 31 06:59:57 ubuntu.local ticky: INFO Commented on ticket [#7255] (oren) 35 | Jan 31 07:59:56 ubuntu.local ticky: ERROR Ticket doesn't exist (flavia) 36 | Jan 31 08:01:40 ubuntu.local ticky: ERROR Tried to add information to closed ticket (jackowens) 37 | Jan 31 08:03:19 ubuntu.local ticky: INFO Closed ticket [#1712] (britanni) 38 | Jan 31 08:22:37 ubuntu.local ticky: INFO Created ticket [#2860] (mcintosh) 39 | Jan 31 08:28:07 ubuntu.local ticky: ERROR Timeout while retrieving information (montanap) 40 | Jan 31 08:49:15 ubuntu.local ticky: ERROR Permission denied while closing ticket (britanni) 41 | Jan 31 08:50:50 ubuntu.local ticky: ERROR Permission denied while closing ticket (montanap) 42 | Jan 31 09:04:27 ubuntu.local ticky: ERROR Tried to add information to closed ticket (noel) 43 | Jan 31 09:15:41 ubuntu.local ticky: ERROR Timeout while retrieving information (oren) 44 | Jan 31 09:18:47 ubuntu.local ticky: INFO Commented on ticket [#8385] (mdouglas) 45 | Jan 31 09:28:18 ubuntu.local ticky: INFO Closed ticket [#2452] (jackowens) 46 | Jan 31 09:41:16 ubuntu.local ticky: ERROR Connection to DB failed (ac) 47 | Jan 31 10:11:35 ubuntu.local ticky: ERROR Timeout while retrieving information (blossom) 48 | Jan 31 10:21:36 ubuntu.local ticky: ERROR Permission denied while closing ticket (montanap) 49 | Jan 31 11:04:02 ubuntu.local ticky: ERROR Tried to add information to closed ticket (breee) 50 | Jan 31 11:19:37 ubuntu.local ticky: ERROR Connection to DB failed (sri) 51 | Jan 31 11:22:06 ubuntu.local ticky: ERROR Timeout while retrieving information (montanap) 52 | Jan 31 11:31:34 ubuntu.local ticky: ERROR Permission denied while closing ticket (ahmed.miller) 53 | Jan 31 11:40:25 ubuntu.local ticky: ERROR Connection to DB failed (mai.hendrix) 54 | Jan 31 11:47:07 ubuntu.local ticky: INFO Commented on ticket [#4562] (ac) 55 | Jan 31 11:58:33 ubuntu.local ticky: ERROR Tried to add information to closed ticket (ahmed.miller) 56 | Jan 31 12:00:17 ubuntu.local ticky: INFO Created ticket [#7897] (kirknixon) 57 | Jan 31 12:02:49 ubuntu.local ticky: ERROR Permission denied while closing ticket (mai.hendrix) 58 | Jan 31 12:20:23 ubuntu.local ticky: ERROR Connection to DB failed (kirknixon) 59 | Jan 31 12:20:40 ubuntu.local ticky: ERROR Ticket doesn't exist (flavia) 60 | Jan 31 12:24:32 ubuntu.local ticky: INFO Created ticket [#5784] (sri) 61 | Jan 31 12:50:10 ubuntu.local ticky: ERROR Permission denied while closing ticket (blossom) 62 | Jan 31 12:58:16 ubuntu.local ticky: ERROR Tried to add information to closed ticket (nonummy) 63 | Jan 31 13:08:10 ubuntu.local ticky: INFO Closed ticket [#8685] (rr.robinson) 64 | Jan 31 13:48:45 ubuntu.local ticky: ERROR The ticket was modified while updating (breee) 65 | Jan 31 14:13:00 ubuntu.local ticky: INFO Commented on ticket [#4225] (noel) 66 | Jan 31 14:38:50 ubuntu.local ticky: ERROR The ticket was modified while updating (enim.non) 67 | Jan 31 14:41:18 ubuntu.local ticky: ERROR Timeout while retrieving information (xlg) 68 | Jan 31 14:45:55 ubuntu.local ticky: INFO Closed ticket [#7948] (noel) 69 | Jan 31 14:50:41 ubuntu.local ticky: INFO Commented on ticket [#8628] (noel) 70 | Jan 31 14:56:35 ubuntu.local ticky: ERROR Tried to add information to closed ticket (noel) 71 | Jan 31 15:27:53 ubuntu.local ticky: ERROR Ticket doesn't exist (blossom) 72 | Jan 31 15:28:15 ubuntu.local ticky: ERROR Permission denied while closing ticket (enim.non) 73 | Jan 31 15:44:25 ubuntu.local ticky: INFO Closed ticket [#7333] (enim.non) 74 | Jan 31 16:17:20 ubuntu.local ticky: INFO Commented on ticket [#1653] (noel) 75 | Jan 31 16:19:40 ubuntu.local ticky: ERROR The ticket was modified while updating (mdouglas) 76 | Jan 31 16:24:31 ubuntu.local ticky: INFO Created ticket [#5455] (ac) 77 | Jan 31 16:35:46 ubuntu.local ticky: ERROR Timeout while retrieving information (oren) 78 | Jan 31 16:53:54 ubuntu.local ticky: INFO Commented on ticket [#3813] (mcintosh) 79 | Jan 31 16:54:18 ubuntu.local ticky: ERROR Connection to DB failed (bpacheco) 80 | Jan 31 17:15:47 ubuntu.local ticky: ERROR The ticket was modified while updating (mcintosh) 81 | Jan 31 17:29:11 ubuntu.local ticky: ERROR Connection to DB failed (oren) 82 | Jan 31 17:51:52 ubuntu.local ticky: INFO Closed ticket [#8604] (mcintosh) 83 | Jan 31 18:09:17 ubuntu.local ticky: ERROR The ticket was modified while updating (noel) 84 | Jan 31 18:43:01 ubuntu.local ticky: ERROR Ticket doesn't exist (nonummy) 85 | Jan 31 19:00:23 ubuntu.local ticky: ERROR Timeout while retrieving information (blossom) 86 | Jan 31 19:20:22 ubuntu.local ticky: ERROR Timeout while retrieving information (mai.hendrix) 87 | Jan 31 19:59:06 ubuntu.local ticky: INFO Created ticket [#6361] (enim.non) 88 | Jan 31 20:02:41 ubuntu.local ticky: ERROR Timeout while retrieving information (xlg) 89 | Jan 31 20:21:55 ubuntu.local ticky: INFO Commented on ticket [#7159] (ahmed.miller) 90 | Jan 31 20:28:26 ubuntu.local ticky: ERROR Connection to DB failed (breee) 91 | Jan 31 20:35:17 ubuntu.local ticky: INFO Created ticket [#7737] (nonummy) 92 | Jan 31 20:48:02 ubuntu.local ticky: ERROR Connection to DB failed (mdouglas) 93 | Jan 31 20:56:58 ubuntu.local ticky: INFO Closed ticket [#4372] (oren) 94 | Jan 31 21:00:23 ubuntu.local ticky: INFO Commented on ticket [#2389] (sri) 95 | Jan 31 21:02:06 ubuntu.local ticky: ERROR Connection to DB failed (breee) 96 | Jan 31 21:20:33 ubuntu.local ticky: INFO Closed ticket [#3297] (kirknixon) 97 | Jan 31 21:29:24 ubuntu.local ticky: ERROR The ticket was modified while updating (blossom) 98 | Jan 31 22:58:55 ubuntu.local ticky: INFO Created ticket [#2461] (jackowens) 99 | Jan 31 23:25:18 ubuntu.local ticky: INFO Closed ticket [#9876] (blossom) 100 | Jan 31 23:35:40 ubuntu.local ticky: INFO Created ticket [#5896] (mcintosh) 101 | -------------------------------------------------------------------------------- /Module 7/Assignments/Solution/data/user_emails.csv: -------------------------------------------------------------------------------- 1 | Full Name, Email Address 2 | Blossom Gill, blossom@abc.edu 3 | Hayes Delgado, nonummy@utnisia.com 4 | Petra Jones, ac@abc.edu 5 | Oleg Noel, noel@liberomauris.ca 6 | Ahmed Miller, ahmed.miller@nequenonquam.co.uk 7 | Macaulay Douglas, mdouglas@abc.edu 8 | Aurora Grant, enim.non@abc.edu 9 | Madison Mcintosh, mcintosh@nisiaenean.net 10 | Montana Powell, montanap@semmagna.org 11 | Rogan Robinson, rr.robinson@abc.edu 12 | Simon Rivera, sri@abc.edu 13 | Benedict Pacheco, bpacheco@abc.edu 14 | Maisie Hendrix, mai.hendrix@abc.edu 15 | Xaviera Gould, xlg@utnisia.net 16 | Oren Rollins, oren@semmagna.com 17 | Flavia Santiago, flavia@utnisia.net 18 | Jackson Owens, jackowens@abc.edu 19 | Britanni Humphrey, britanni@ut.net 20 | Kirk Nixon, kirknixon@abc.edu 21 | Bree Campbell, breee@utnisia.net 22 | 23 | -------------------------------------------------------------------------------- /Module 7/Assignments/Solution/data/user_statistics.csv: -------------------------------------------------------------------------------- 1 | Username,INFO,ERROR 2 | ac,2,2 3 | ahmed.miller,2,4 4 | blossom,2,6 5 | bpacheco,0,2 6 | breee,1,5 7 | britanni,1,1 8 | enim.non,2,3 9 | flavia,0,5 10 | jackowens,2,4 11 | kirknixon,2,1 12 | mai.hendrix,0,3 13 | mcintosh,4,3 14 | mdouglas,2,3 15 | montanap,0,4 16 | noel,6,3 17 | nonummy,2,3 18 | oren,2,7 19 | rr.robinson,2,1 20 | sri,2,2 21 | xlg,0,4 22 | -------------------------------------------------------------------------------- /Module 7/Assignments/Solution/html/error_message.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | 23 |

Error Message

ErrorCount
Timeout while retrieving information15
Connection to DB failed13
Tried to add information to closed ticket12
Permission denied while closing ticket10
The ticket was modified while updating9
Ticket doesn't exist7
-------------------------------------------------------------------------------- /Module 7/Assignments/Solution/html/final_assignment.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | 23 |

User Emails

Full Name Email Address
Blossom Gill blossom@abc.edu
Hayes Delgado nonummy@utnisia.com
Petra Jones ac@abc.edu
Oleg Noel noel@liberomauris.ca
Ahmed Miller ahmed.miller@nequenonquam.co.uk
Macaulay Douglas mdouglas@abc.edu
Aurora Grant enim.non@abc.edu
Madison Mcintosh mcintosh@nisiaenean.net
Montana Powell montanap@semmagna.org
Rogan Robinson rr.robinson@abc.edu
Simon Rivera sri@abc.edu
Benedict Pacheco bpacheco@abc.edu
Maisie Hendrix mai.hendrix@abc.edu
Xaviera Gould xlg@utnisia.net
Oren Rollins oren@semmagna.com
Flavia Santiago flavia@utnisia.net
Jackson Owens jackowens@abc.edu
Britanni Humphrey britanni@ut.net
Kirk Nixon kirknixon@abc.edu
Bree Campbell breee@utnisia.net
-------------------------------------------------------------------------------- /Module 7/Assignments/Solution/html/user_statistics.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 21 | 22 | 23 |

User Statistics

UsernameINFOERROR
ac22
ahmed.miller24
blossom26
bpacheco02
breee15
britanni11
enim.non23
flavia05
jackowens24
kirknixon21
mai.hendrix03
mcintosh43
mdouglas23
montanap04
noel63
nonummy23
oren27
rr.robinson21
sri22
xlg04
-------------------------------------------------------------------------------- /Module 7/Assignments/Solution/scripts/csv_to_html.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import sys 3 | import csv 4 | import os 5 | 6 | def process_csv(csv_file): 7 | """Turn the contents of the CSV file into a list of lists""" 8 | print("Processing {}".format(csv_file)) 9 | with open(csv_file,"r") as datafile: 10 | data = list(csv.reader(datafile)) 11 | return data 12 | 13 | def data_to_html(title, data): 14 | """Turns a list of lists into an HTML table""" 15 | 16 | # HTML Headers 17 | html_content = """ 18 | 19 | 20 | 37 | 38 | 39 | """ 40 | 41 | 42 | # Add the header part with the given title 43 | html_content += "

{}

".format(title) 44 | 45 | # Add each row in data as a row in the table 46 | # The first line is special and gets treated separately 47 | for i, row in enumerate(data): 48 | html_content += "" 49 | for column in row: 50 | if i == 0: 51 | html_content += "".format(column) 52 | else: 53 | html_content += "".format(column) 54 | html_content += "" 55 | 56 | html_content += """
{}{}
""" 57 | return html_content 58 | 59 | 60 | def write_html_file(html_string, html_file): 61 | 62 | # Making a note of whether the html file we're writing exists or not 63 | if os.path.exists(html_file): 64 | print("{} already exists. Overwriting...".format(html_file)) 65 | 66 | with open(html_file,'w') as htmlfile: 67 | htmlfile.write(html_string) 68 | print("Table succesfully written to {}".format(html_file)) 69 | 70 | def main(): 71 | """Verifies the arguments and then calls the processing function""" 72 | # Check that command-line arguments are included 73 | if len(sys.argv) < 3: 74 | print("ERROR: Missing command-line argument!") 75 | print("Exiting program...") 76 | sys.exit(1) 77 | 78 | # Open the files 79 | csv_file = sys.argv[1] 80 | html_file = sys.argv[2] 81 | 82 | # Check that file extensions are included 83 | if ".csv" not in csv_file: 84 | print('Missing ".csv" file extension from first command-line argument!') 85 | print("Exiting program...") 86 | sys.exit(1) 87 | 88 | if ".html" not in html_file: 89 | print('Missing ".html" file extension from second command-line argument!') 90 | print("Exiting program...") 91 | sys.exit(1) 92 | 93 | # Check that the csv file exists 94 | if not os.path.exists(csv_file): 95 | print("{} does not exist".format(csv_file)) 96 | print("Exiting program...") 97 | sys.exit(1) 98 | 99 | # Process the data and turn it into an HTML 100 | data = process_csv(csv_file) 101 | title = os.path.splitext(os.path.basename(csv_file))[0].replace("_", " ").title() 102 | html_string = data_to_html(title, data) 103 | write_html_file(html_string, html_file) 104 | 105 | if __name__ == "__main__": 106 | main() 107 | -------------------------------------------------------------------------------- /Module 7/Assignments/Solution/scripts/ticky_check.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | import re 4 | import operator 5 | import os 6 | import csv 7 | 8 | error_msg = {} 9 | user_stat = {} 10 | 11 | error_pattern = r'ticky: ERROR ([\w\s\']*) \((.+)\)' 12 | info_pattern = r'ticky: INFO.* \((.+)\)' 13 | 14 | with open('syslog.log','r') as logs: 15 | for line in logs.readlines(): 16 | if re.search(error_pattern,line): 17 | extracts = re.search(error_pattern, line) 18 | error_msg.setdefault(extracts.group(1),0) 19 | error_msg[extracts.group(1)]+=1 20 | user_stat.setdefault(extracts.group(2),[0,0])[1]+=1 21 | if re.search(info_pattern,line): 22 | extracts = re.search(info_pattern, line) 23 | user_stat.setdefault(extracts.group(1),[0,0])[0]+=1 24 | 25 | error_sorted = sorted(error_msg.items(), key = operator.itemgetter(1), reverse = True) 26 | user_sorted = sorted(user_stat.items()) 27 | print(error_sorted) 28 | print(user_sorted) 29 | 30 | with open('error_message.csv','w') as output: 31 | writer = csv.writer(output) 32 | writer.writerow(['Error','Count']) 33 | writer.writerows(error_sorted) 34 | 35 | with open('user_statistics.csv','w') as output: 36 | writer = csv.writer(output) 37 | writer.writerow(['Username','INFO','ERROR']) 38 | for item in user_sorted: 39 | onerow = [item[0],item[1][0],item[1][1]] 40 | writer.writerow(onerow) 41 | -------------------------------------------------------------------------------- /Module 7/Assignments/googlecoursera.qwiklabs.com-Log Analysis Using Regular Expressions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/Module 7/Assignments/googlecoursera.qwiklabs.com-Log Analysis Using Regular Expressions.pdf -------------------------------------------------------------------------------- /Module 7/Scripts/README.md: -------------------------------------------------------------------------------- 1 | # FINAL SCRIPT 2 | 3 | ### different versions of final ticky_check.py 4 | -------------------------------------------------------------------------------- /Module 7/Scripts/ticky_check_1.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import re 3 | import csv 4 | import operator 5 | import sys 6 | 7 | per_users = {} 8 | errors = {} 9 | 10 | logfile = 'syslog.log' 11 | f = open(logfile, 'r') 12 | 13 | errorfile = 'error_message.csv' 14 | userfile = 'user_statistics.csv' 15 | 16 | for log in f: 17 | result = re.search(r"ticky: ([\w+]*):? ([\w' ]*) [\[[0-9#]*\]?]? ?\((.*)\)$", log) 18 | if result.group(2) not in errors.keys(): 19 | errors[result.group(2)] = 0 20 | errors[result.group(2)] += 1 21 | if result.group(3) not in per_users.keys(): 22 | per_users[result.group(3)] = {} 23 | per_users[result.group(3)] ["INFO"] = 0 24 | per_users[result.group(3)] ["ERROR"] = 0 25 | 26 | if result.group(1) == "INFO": 27 | per_users[result.group(3)] ["INFO"] += 1 28 | elif result.group(1) == "ERROR": 29 | per_users[result.group(3)] ["ERROR"] += 1 30 | 31 | errors = sorted(errors.items(), key = operator.itemgetter(1), reverse= True) 32 | per_users = sorted(per_users.items()) 33 | 34 | f.close() 35 | errors.insert(0, ('Error', 'Count')) 36 | 37 | f = open(errorfile, 'w') 38 | for error in errors: 39 | a,b = error 40 | f.write(str(a)+','+str(b)+'\n') 41 | f.close() 42 | 43 | f = open(userfile, 'w') 44 | f.write("Username,INFO,ERROR\n") 45 | for stats in per_users: 46 | a,b = stats 47 | f.write(str(a)+','+str(b["INFO"])+','+str(b["ERROR"])+'\n') -------------------------------------------------------------------------------- /Module 7/Scripts/ticky_check_2.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import subprocess 3 | import collections 4 | import re 5 | import operator 6 | import csv 7 | 8 | def error_csv(): 9 | errors = {} 10 | with open("syslog.log", "r") as file: 11 | for line in file.readlines(): 12 | val = re.search(r"ERROR ([\w ']*)", line) 13 | if val: 14 | val = val.group(1)[:-1] 15 | if val == None: 16 | continue 17 | if val not in errors: 18 | errors[val] = 1 19 | else: 20 | errors[val] = errors.get(val)+1 21 | sorted_errors = collections.OrderedDict(sorted(errors.items(), key=operator.itemgetter(1), reverse=True)) 22 | #print(sorted_errors) 23 | with open("error_message.csv", "w") as f: 24 | writer = csv.DictWriter(f, fieldnames=["Error", "Count"]) 25 | writer.writeheader() 26 | [f.write("{0}, {1}\n".format(key,value)) for key,value in sorted_errors.items()] 27 | return sorted_errors 28 | 29 | print(error_csv()) 30 | 31 | def user_csv(): 32 | userData = {} 33 | with open("syslog.log", "r") as file: 34 | for line in file.readlines(): 35 | val=line[line.find("(")+1:line.find(")")] 36 | if val not in userData: 37 | userData[val] = [0]*2 38 | if line.find("ERROR") > 0: 39 | errVal = userData.get(val)[1]+1 40 | if line.find("INFO") > 0: 41 | infVal = userData.get(val)[0]+1 42 | userData[val] = [infVal, errVal] 43 | sorted_userData = collections.OrderedDict(sorted(userData.items(), key=operator.itemgetter(0))) 44 | with open("user_statistic.csv", "w") as f: 45 | writer = csv.DictWriter(f, fieldnames=["Username", "INFO", "ERROR"]) 46 | writer.writeheader() 47 | [f.write("{0}, {1}\n".format(key,value)) for key,value in sorted_userData.items()] 48 | return sorted_userData 49 | 50 | print(user_csv()) -------------------------------------------------------------------------------- /Module 7/Scripts/ticky_check_3.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | import re 3 | import csv 4 | import operator 5 | 6 | error_messages = {} 7 | per_user = {} 8 | logfile =r"/home/student-03-c1bdb9d32e5c/syslog.log" 9 | pattern = r"(INFO|ERROR) ([\w' ]+|[\w\[\]#' ]+) (\(\w+\)|\(\w+\.\w+\))$" 10 | 11 | with open(logfile, "r") as f: 12 | for line in f: 13 | result = re.search(pattern, line) 14 | if result is None: 15 | continue 16 | if result.groups()[0] == "INFO": 17 | category = result.groups()[0] 18 | message = result.groups()[1] 19 | name = str(result.groups()[2])[1:-1] 20 | if name in per_user: 21 | user = per_user[name] 22 | user[category] += 1 23 | else: 24 | per_user[name] = {'INFO':1, 'ERROR':0} 25 | if result.groups()[0] == "ERROR": 26 | category = result.groups()[0] 27 | message = result.groups()[1] 28 | name = str(result.groups()[2])[1:-1] 29 | error_messages[message] = error_messages.get(message, 0) + 1 30 | if name in per_user: 31 | user = per_user[name] 32 | user[category] += 1 33 | else: 34 | per_user[name] = {'INFO':0, 'ERROR':1} 35 | 36 | sorted_messages = [("Error", "Count")] + sorted(error_messages.items(), key = operator.itemgetter(1), reverse=True) 37 | #sorted_messages = [("Error", "Count")] + sorted(error_messages.items(), key = lambda x: x[1], reverse=True) 38 | sorted_users = [("Username", "INFO", "ERROR")] + sorted(per_user.items())[0:8] 39 | #sorted_users = [("Username", "INFO", "ERROR")] + sorted(per_user.items()) 40 | 41 | with open("error_message.csv", "w") as error_file: 42 | for line in sorted_messages: 43 | error_file.write("{}, {}\n".format(line[0], line[1])) 44 | 45 | with open("user_statistics.csv", "w") as user_file: 46 | for line in sorted_users: 47 | if isinstance(line[1], dict): 48 | user_file.write("{}, {}, {}\n".format(line[0], line[1].get("INFO"), line[1].get("ERROR"))) 49 | else: 50 | user_file.write("{}, {}, {}\n".format(line[0], line[1], line[2])) -------------------------------------------------------------------------------- /Module 7/notes_module_7.md: -------------------------------------------------------------------------------- 1 | Using Python to Interact with the Operating System 2 | ================================================== 3 | 4 | by Google 5 | 6 | # Module 7 7 | # 8 | ## Title: Final Project 9 | 10 | ## ALL THE BEST FOR FINAL PROJECT !!! 11 | 12 | ### KUDOS !!! :-) -------------------------------------------------------------------------------- /google_logo-preview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sambhipiyush/Using-Python-to-Interact-with-the-Operating-System-by-Google/a3b96d240c434341d385e159f6f1c8ca6b086251/google_logo-preview.jpg --------------------------------------------------------------------------------