Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Python Automation Office script

2025-01-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you the example analysis of Python automation office script, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

1. Automatically read web news

This script can grab text from a web page and then automatically read it aloud, which is a good choice when you want to hear the news.

The code is divided into two parts, the first is to crawl the web page text through the crawler, and the second is to read the text aloud through the reading tool.

Required third-party libraries:

Beautiful Soup-A classic HTML/XML text parser used to extract information from crawled web pages

Requests-an unnatural HTTP tool used to send requests for data to web pages

Pyttsx3-converts text to voice and controls rate, frequency, and voice

Import pyttsx3import requestsfrom bs4 import BeautifulSoupengine = pyttsx3.init ('sapi5') voices = engine.getProperty (' voices') newVoiceRate = 130 # # Reduce The Speech Rateengine.setProperty ('rate',newVoiceRate) engine.setProperty (' voice', voices [1] .id) def speak (audio): engine.say (audio) engine.runAndWait () text = str (input ("Paste article\ n") res = requests.get (text) soup = BeautifulSoup (res.text 'html.parser') articles = [] for i in range (len (soup.select (' .p')): article = soup.select ('.p') [I] .getText (). Strip () articles.append (article) text = "" .join (articles) speak (text) # engine.save_to_file (text, 'test.mp3') # # If you want to save the speech as an audio fileengine.runAndWait () 2, generate sketch automatically

This script can convert color pictures into pencil sketches, which has a good effect on portraits and scenery.

And only a few lines of code can be generated with one click, suitable for batch operation, very fast.

Required third-party libraries:

Opencv-computer vision tool, can achieve a variety of image and video processing, with Python interface

"Photo Sketching Using Python" import cv2 img = cv2.imread ("elon.jpg") # # Image to Gray Image gray_image = cv2.cvtColor (img,cv2.COLOR_BGR2GRAY) # # Gray Image to Inverted Gray Image inverted_gray_image = 255-gray_image # # Blurring The Inverted Gray Image blurred_inverted_gray_image = cv2.GaussianBlur (inverted_gray_image, (1951) 0) # # Inverting the blurred image inverted_blurred_image = 255-blurred_inverted_gray_image # Preparing Photo sketching sketck = cv2.divide (gray_image, inverted_blurred_image,scale= 256.0) cv2.imshow ("Original Image", img) cv2.imshow ("Pencil Sketch", sketck) cv2.waitKey (0) 3, automatically send multiple messages

This script can help us send emails in batches and periodically, and the contents and attachments can also be customized and adjusted, which is very practical.

Compared with the mail client, the advantage of Python script is that the mail service can be deployed intelligently, in batches, and highly customized.

Required third-party libraries:

Email-used to manage email messages

Smtlib-sends an email to the SMTP server, which defines a SMTP client session object that can send messages to any computer on the Internet with SMTP or ESMTP listeners

Pandas-A tool for cleaning data analysis

Import smtplib from email.message import EmailMessageimport pandas as pddef send_email (remail, rsubject Rcontent): email = EmailMessage () # # Creating an object for EmailMessage email ['from'] =' The Pythoneer Here' # # Person who is sending email ['to'] = remail # # Whom we are sending email [' subject'] = rsubject # # Subject of email email.set_content (rcontent) # # content of email with smtplib.SMTP (host='smtp.gmail.com' Port=587) as smtp: smtp.ehlo () # # server object smtp.starttls () # # used to send data between server and client smtp.login ("deltadelta371@gmail.com" "delta@371") # # login id and password of gmail smtp.send_message (email) # # Sending email print ("email send to", remail) # # Printing success messageif _ _ name__ = ='_ main__': df = pd.read_excel ('list.xlsx') length = len (df) + 1 for index Item in df.iterrows (): email = item [0] subject = item [1] content = item [2] send_email (email,subject,content) 4, Automation data Exploration

Data exploration is the first step in a data science project, and you need to understand the basic information of the data in order to further analyze the value.

Generally speaking, we use pandas, matplotlib and other tools to explore data, but we need to write a lot of code ourselves. If we want to improve efficiency, Dtale is a good choice.

Dtale is characterized by generating automated analysis reports with one line of code, which combines Flask back-end and React front-end, and provides us with an easy way to view and analyze Pandas data structures.

We can use Dtale on Jupyter.

Required third-party libraries:

Dtale-automatically generate analysis report

# Importing Seaborn Library For Some Datasetsimport seaborn as sns### Printing Inbuilt Datasets of Seaborn Libraryprint (sns.get_dataset_names ()) # Loading Titanic Datasetdf=sns.load_dataset ('titanic') # Importing The Libraryimport dtale#### Generating Quick Summarydtale.show (df)

5. Automatic desktop prompt

This script automatically triggers windows desktop notifications, prompting important items, such as: you have been working for two hours and it is time to take a break

We can set fixed time prompts, such as 10 minutes, 1 hour, etc.

Third-party libraries used:

Win10toast-tool for sending desktop notifications

From win10toast import ToastNotifierimport timetoaster = ToastNotifier () header = input ("What You Want Me To Remember\ n") text = input ("Releated Message\ n") time_min=float (input ("In how many minutes?\ n") time_min= time_min * 60print ("Setting up reminder..") time.sleep (2) print ("all set!") time.sleep (time_min) toaster.show_toast (f "{header}", f "{text}", duration=10 Threaded=True) while toaster.notification_active (): time.sleep (0.005)

The above is all the contents of the article "sample Analysis of Python Automation Office script". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

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: 245

*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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report