# ANCHOR: = Module DocString = """ Created by Jap-Slappa Date: 24th/Aug/2022 Module => String 2 URL v1.5 - Stand Alone Module - Flac Files AIO v3.0 Date: 24th/Aug/2022 - v1.0 - Began re-coding this module - Coverts a string encoded into a URL format, for a Query for Google Search - Will launch a Web-browser with the New encoded URL string when finished - And can be Test Run as a independent script. - Added: code control and execution, If run as Script Date: 11th/Sept/2022 - v1.5 - This program is now FULLY WORKING!!.... - Now starting full DocStrings & proper Code Comments """ # ANCHOR: = Imports = import time import urllib.parse import webbrowser import All_Timers as My_CD_Timers # ANCHOR: FUNC | make_string_2_url # ? CLASS: TrackInfo ==>> Method(2) def make_string_2_url(): """ make_string_2_url - Coverts a string encoded into a URL format - For a Query for Google Search - The URL String can then set as the class attr... self.search_4_string Returns: Str: Encoded into a URL format (Query String) """ # ANCHOR: PRINT | Processing START print('\n') print('========== make_string_2_url() || CLASS Function ========== ') time.sleep(1.0) print('========== Now Making URL From String: CLASS Attrs Process..... ') # time.sleep(2.0) print('') print(f'========== Artist Name: {track_artist}..... ') # time.sleep(2.0) print(f'========== Track Name: {track_name}..... ') # time.sleep(2.0) print('') print(f'========== Search Query Strings For Processing..... ') print(f'..... ** {track_artist} - {track_name} ** ') print('') My_CD_Timers.any_countdownTimer(2) # time.sleep(2.0) # ANCHOR: PRINT | urllib.parse # todo == urllib.parse.quote_plus FUNCTION == # THIS WORKS!! - Converts any string into a URL Query for Google Search search_4_string = urllib.parse.quote_plus(f'{track_artist} - {track_name}') # ANCHOR: PRINT | Processing COMPLETE # time.sleep(1.0) print('========== Search Query Strings: Processing: Now COMPLETE!!..... ') print('================================================================= ') # noqa print('') # time.sleep(2.0) print('========== Google Search ====================') print('===============================================') # time.sleep(2.0) print(f'https://www.google.co.uk/search?q={search_4_string}') print('') # print('') My_CD_Timers.any_countdownTimer(2) # time.sleep(2.0) # ANCHOR: PRINT | Launch Browser # https://www.geeksforgeeks.org/python-launch-a-web-browser-using-webbrowser-module/ # todo: === Launch New Tab In Browser === print('') print('================================================================= ') # noqa print('========== Launching New Tab In Browser... ========== ') print('') time.sleep(1.0) google_search = f'https://www.google.co.uk/search?q={search_4_string}' webbrowser.open_new_tab(google_search) time.sleep(1.0) print('========== DONE!! =================================== ') print('================================================================= ') # noqa # *End Of Method/(Function) # ANCHOR: = __name__ = # My_Info.code_control_and_execution_name if __name__ == '__main__': # ? Fill-in the required variables HERE # "UB40"+"Labour of Love / Labour of Love II # track_artist = 'Various Artists' track_artist = 'Various Artists' track_name = "12'/80s Grooves" make_string_2_url()