In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
What are the Python automation scripts, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can gain something.
Foreword:
Have you noticed that you may perform many repetitive tasks every day, such as reading pdf, playing music, opening bookmarks, cleaning folders, etc.
I'll share four useful python automation scripts, which are handy without having to manually accomplish these tasks over and over again.
1. Convert PDF to audio file
The script can convert pdf into audio files, the principle is also very simple, first use PyPDF to extract the text in pdf, and then use Pyttsx3 to convert the text to voice. You can also read this article about the conversion from text to voice.
FastAPI: quickly develop a text-to-language interface.
The code is as follows:
Import pyttsx3,PyPDF2pdfreader = PyPDF2.PdfFileReader (open ('story.pdf','rb')) speaker = pyttsx3.init () for page_num in range (pdfreader.numPages): text = pdfreader.getPage (page_num). ExtractText () # # extracting text from the PDF cleaned_text = text.strip (). Replace ('\ n' '') # # Removes unnecessary spaces and break lines print (cleaned_text) # # Print the text from PDF # speaker.say (cleaned_text) # # Let The Speaker Speak The Text speaker.save_to_file (cleaned_text,'story.mp3') # # Saving Text In an audio file 'story.mp3' speaker.runAndWait () speaker.stop () 2. Play random music from the list
This script will randomly select a song from the songs folder to play, it is important to note that os.startfile only supports Windows systems.
Import random, osmusic_dir ='G:\ new english songs'songs = os.listdir (music_dir) song = random.randint (0Len (songs)) print (songs [song]) # # Prints The Song Nameos.startfile (os.path.join (music_dir, songs [0])) 3, no more bookmarks
Every day before going to bed, I will search the Internet for some good content, and I can read it the next day. Most of the time, I bookmark websites or articles I encounter, but my bookmarks are growing every day, so much so that there are now more than 100 bookmarks around my browser. So, with the help of python, I came up with another way to solve this problem. Now, I copy and paste the links to these sites into a text file, and every morning I run a script to open all of these sites again in my browser.
Import webbrowserwith open ('. / websites.txt') as reader: for link in reader: webbrowser.open (link.strip ())
The code uses webbrowser, a library in Python that automatically opens URL in the default browser.
4. Clean up the download folder
One of the most confusing things in the world is the developer's download folder, which contains a lot of disorganized files. This script will clean up your download folder according to the size limit.
Limited cleanup of older files:
Import osimport threadingimport time def get_file_list (file_path): # Files are sorted by last modification time dir_list = os.listdir (file_path) if not dir_list: return else: dir_list = sorted (dir_list, key=lambda x: os.path.getmtime (os.path.join (file_path) X)) return dir_list def get_size (file_path): "[summary] Args: file_path ([type]): [directory] Returns: [type]: returns the directory size MB "totalsize=0 for filename in os.listdir (file_path): totalsize=totalsize+os.path.getsize (os.path.join (file_path, filename)) # print (totalsize / 1024 / 1024) return totalsize / 1024 / 1024 def detect_file_size (file_path, size_Max) Size_Del): "[summary] Args: file_path ([type]): [file directory] size_Max ([type]): [folder maximum size] size_Del ([type]): [size to be deleted when size_Max is exceeded]" print (get_size (file_path)) if get_size (file) _ path) > size_Max: fileList = get_file_list (file_path) for i in range (len (fileList)): if get_size (file_path) > (size_Max-size_Del): print ("del:% d% s"% (I + 1) FileList [I]) # os.remove (file_path + fileList [I]) def detectFileSize (): # detect thread Check while True every 5 seconds: print ('= detect=') detect_file_size ("/ Users/aaron/Downloads/", 100,30) time.sleep (5) if _ _ name__ = "_ _ main__": # create a detection thread detect_thread = threading.Thread (target = detectFileSize) detect_thread.start () does it help you to read the above? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.