Python for Daily Life Productivity
By: Lucas Soares
Tags: Programming, Python, Learning, Learning To Code, Productivity

1. Python for automating emails

Sending e-mails is a major part of any person’s daily activity. You read them, you write them, you spend way too much time on them.

So, Python to the rescue! Let’s take a look at how to send e-mails with Python so that you can automate at least some part of your daily e-mail tasks:

Steps

Set up an SMTP (Simple Mail Transfer Protocol) server and login to your account:

import smtplib

from string import Template

from email.mime.multipart import MIMEMultipart

from email.mime.text import MIMEText MY_ADDRESS = "my_email@mine.com"

PWD = "My_SUpEr_SeCReT_PAsSWoRD!@#$" s = smtplib.SMTP(host='your host', port="your port number")

s.starttls()

s.login(MY_ADDRESS, PWD)

For the host and port number, you have to check which applies to your e-mail type. Here is a good source to solve that.

2. Define the parameters of your message

msg = MIMEMultipart()

email = " name = "Lucas"email = " y ouremail@pythonrules.com" msg['From']=MY_ADDRESS

msg['To']=email

msg['Subject']="Python rules!!!"

3. Insert the message on your e-mail

msg.attach(MIMEText(message, 'plain'))

4. Send the message using the server that you set up and terminate the SMTP session

s.send_message(msg)

del msg

That’s it! You just sent an e-mail with Python! Ideas for how to take this to another level can be found here on two of my favorite sources on this subject:

2. Python for checking the news

Ok, so far we have learned how to send e-mails with Python. How about informing ourselves about what is going on with the world?

First, we must define exactly what this means. In this context it would be: Knowing the main topics in the news on a given day.

The benefit of using Python is that we can get information summarized in one place so that we don’t have to go around opening dozens of websites and pages to know what is going on. To do this, I will use a very interesting library I heard about here on medium on this nice post by Farhad Malik:

Steps

1. Instantiate the GoogleNews() class

from pygooglenews import GoogleNews gn = GoogleNews()

2. Get the top news of the day

top_news = gn.top_news()["entries"] print("TOP NEWS")

for news in top_news:

print(news["title"])

Output:

TOP NEWS Steve Bannon, three others charged with fraud in border wall fundraising campaign - CNN

Trump Pennsylvania speech to attack Biden on trade, energy, immigration - Fox News

Trump Must Turn Over Tax Returns to D.A., Judge Rules - The New York Times

California wildfires more than double in size, force, and degrade air quality; tens of thousands to evacuate - The Washington Post

Alexei Navalny, Voice Of Russia's Opposition, Is Hospitalized In Possible Poisoning - NPR

New York Will Allow Voters to Cast Mail-In Ballots - The New York Times

Flint Settlement Would Provide $600 Million To Resolve Claims - NPR

Fauci out of surgery for vocal cord polyp - CNN

3 States Will Start Paying $400 Extra In Weekly Unemployment Benefits, Not $300 - Forbes

...

3. Get the top news per topic of interest

tech_news = gn.topic_headlines("technology")["entries"] print("TOP NEWS IN TECH")

for news in tech_news:

print(news["title"])

Output:

TOP NEWS IN TECH

Exclusive: Is this the first sign of a budget Samsung foldable phone? - SamMobile

Xbox Series X - Official Next Gen UI Features Trailer - IGN

Demon's Souls On PS5 Could Be Launching Soon, Suggests South Korean Rating - GameSpot

YouTube Music is rolling out lyrics on the web client - Android Police

PS5 developers explain how the DualSense controller changes gameplay - Engadget

Razer’s Pro Click wireless mouse puts ergonomics ahead of gaming features - The Verge

Apple appears to post Sept. 10 stream details for 5G iPhone event on YouTube - CNET

Report: Apple quietly acquired Israel’s Camerai, formerly Tipit, a specialist in AR and camera tech - TechCrunch

Why are People Selling 'Fortnite' iPhones for Thousands of Dollars? - Lifehacker

Zombie BlackBerrys! QWERTY BlackBerry Android phones are coming back - Ars Technica

12 Microsoft Flight Simulator tips and tricks guide - Polygon

Gmail down for hours as Google services suffered major outage - New York Post

Google Maps is tracking the spread of America's wildfires hour by hour - Engadget

5 Fortnite alternative mobile games you can try - The Indian Express

Zoom Wants to Be Everywhere - Motley Fool

First Call of Duty: Black Ops Cold War promo art released ahead of reveal event - GamesRadar+

Here’s your best look yet at ZTE’s first smartphone with an under-display camera - The Verge

Wireless Android Auto works on all Android 11 devices with 5GHz Wi-Fi - XDA Developers

Speed Test G: Pixel 4a vs Pixel 3a (The Snapdragon 730G advantage) - Android Authority

Cadillac CT5-V Blackwing may rocket past 200 mph - CNET

....

4. Get the top news per geographic location

lisbon_news = gn.geo_headlines("Lisbon")["entries"] print("TOP NEWS IN LISBON")

for news in lisbon_news:

print(news["title"])

Output:

TOP NEWS IN LISBON Rick Steves’s rules for Lisbon: Stay up late and immerse yourself in the fado scene - Washington Post

Lisbon’s High-End Prices Have Jumped 98% in a Decade - Barron's

Struggling live-event workers protest in Lisbon to save pandemic-hit sector - Reuters

Heineken® 'Painted' Portugal Green to launch the UEFA Champions League action in Lisbon - PRNewswire

Lisbon Airbnb: Portugal Pushes Affordable Housing Plan - Bloomberg

'Racism kills': hundreds protest after Black actor shot dead in Lisbon - Reuters

Lisbon's startup ecosystem at a glance - EU-Startups

Portugal Keeps Lisbon Under Stricter COVID Curbs Until End-August - U.S. News & World Report

Qatar Airways resumes Lisbon route - STAT Times

Lisbon's back-alley fado legends – photo essay | Art and design - The Guardian

FC Barcelona players arrive in Lisbon ahead of Bayern match - Yahoo Sports

Lisbon's partial reconfinement extended until end of July - The Brussels Times

Lisbon might have solved its Airbnb problem - The Real Deal

Overrun risk underlined after third similar EasyJet take-off incident at Lisbon - Flightglobal

....

5. Get the news that mentions a specific search query (over the last 3 months)

search_news = gn.search('Data Science', when = '3m')["entries"] print("TOP NEWS ABOUT DATA SCIENCE")

for news in search_news:

print(news["title"])

Output:

TOP NEWS ABOUT DATA SCIENCE 3M Still Can't Make America Enough N95 Masks | Marker - Marker

Insider Selling: 3M Co (NYSE:MMM) SVP Sells 2228 Shares of Stock - MarketBeat

Polyvinylidene Difluoride Membrane Market Statistics and Research Analysis Released in Latest Industry Report 2020 | Coronavirus-

...

That’s it! Now you are all caught up on the main headlines and it only took a few lines of code! I highly recommend you check out the GitHub on this library from where I took the code for their quickstart tutorial:

3. Python for research

Academia is not an exception when it comes to Python automation. We can use the scholarly library that you can find here to search for papers and the author’s information.

Steps

1. Search for author’s information

from scholarly import scholarly author_data = scholarly.search_author(“Author's name”)

author_info = next(author_data).fill()

print(author_info)

2. Get the titles of the author’s publications

print([pub.bib[‘title’] for pub in author_info.publications])

3. Search papers by keyword

search_query = scholarly.search_keyword('KEYWORD')

print(next(search_query))

I recommend you check their documentation to have some fun with the capabilities of the library. Note the potential of using Python for optimizing your research by considering libraries that allow you to automate part of the search process.

Conclusion

There are countless tools Python offers to optimize so many aspects of our digital routines. Therefore, take these ideas as inspiration to automate whatever is relevant to you to help your workflow.