AutomateTheBoringStuff.Ch16.Projects package

Submodules

AutomateTheBoringStuff.Ch16.Projects.P1_assignChores module

Assign chores

Write a program that takes a list of people’s email addresses and a list of chores that need to be done and randomly assigns chores to people. Email each person their assigned chores.

If you’re feeling ambitious, keep a record of each person’s previously assigned chores so that you can make sure the program avoids assigning anyone the same chore they did last time.

For another possible feature, schedule the program to run once a week automatically.

Notes

  • smtp_info file has each item on a separate line.
  • Use input() for password to prevent storing in unencrypted file.
  • It may be easier to:
    • Setup a crontab to run weekly.
    • Store saved_time and prev_chores in a shelve database.
AutomateTheBoringStuff.Ch16.Projects.P1_assignChores.main()[source]

AutomateTheBoringStuff.Ch16.Projects.P2_rememberUmbrella module

Remember umbrella

Use requests to scrape data from http://weather.gov/.

Write a program that runs just before you wake up in the morning and checks whether it’s raining that day. If so, have the program text you a reminder to pack an umbrella before leaving the house.

AutomateTheBoringStuff.Ch16.Projects.P2_rememberUmbrella.check_time(time_arg: datetime.time) → bool[source]

Check time

Checks if given time is after current time as given by datetime.datetime.now().

Parameters:time_argdatetime.time object to compare with current time.
Returns:True if given time is after current time.
AutomateTheBoringStuff.Ch16.Projects.P2_rememberUmbrella.get_weather(url_arg: str) → str[source]

Get weather

Uses requests to download given weather page url, then uses bs4 to get the current weather data text.

Parameters:url_arg – String containing url to specified city’s http://weather.gov/ weather page.
Returns:String with current weather data text.
AutomateTheBoringStuff.Ch16.Projects.P2_rememberUmbrella.main()[source]
AutomateTheBoringStuff.Ch16.Projects.P2_rememberUmbrella.remember_umbrella(weather_arg: str) → bool[source]

Remember umbrella

Checks current weather data text from get_weather() for keywords indicating rain.

Parameters:weather_arg – String containing current weather text of specified city.
Returns:True if any of the rain keywords are found, False otherwise.

AutomateTheBoringStuff.Ch16.Projects.P3_autoUnsubscribe module

Auto unsubscribe

Write a program that scans through your email account, finds all the unsubscribe links in all your emails, and automatically opens them in a browser. This program will have to log in to your email provider’s IMAP server and download all of your emails. You can use BeautifulSoup to check for any instance where the word unsubscribe occurs within an HTML link tag.

Once you have a list of these URLs, you can use webbrowser.open() to automatically open all of these links in a browser.

Notes

  • imap_info file has each item on a separate line.
  • Email address used is specially created for this chapter.
  • Use input() for password to prevent storing in unencrypted file.
AutomateTheBoringStuff.Ch16.Projects.P3_autoUnsubscribe.main()[source]

AutomateTheBoringStuff.Ch16.Projects.P4_autoDownloadTorrent module

Auto download torrent

Write a program that checks an email account every 15 minutes for any instructions you email it and executes those instructions automatically.

For example, BitTorrent is a peer-to-peer downloading system. Using free BitTorrent software such as qBittorrent, you can download large media files on your home computer. If you email the program a (completely legal, not at all piratical) BitTorrent link, the program will eventually check its email, find this message, extract the link, and then launch qBittorrent to start downloading the file. This way, you can have your home computer begin downloads while you’re away, and the (completely legal, not at all piratical) download can be finished by the time you return home.

Notes

  • Shutting down after downloading is considered “Hit ‘n’ run” and goes against torrenting.

    • Consider setting up a seed ratio limit and let it stop sharing afterward.
  • Transmission torrent client is used since it is available in Ubuntu by default.

    • A bash script is ultimately needed to shutdown Transmission.
    • Remote access is needed to run the bash script (hint).
AutomateTheBoringStuff.Ch16.Projects.P4_autoDownloadTorrent.autodownload_torrent(url_arg: str) → None[source]

Auto download torrent

Starts subprocess with Transmission client and waits until given torrent url is downloaded.

Parameters:url_arg – String with url of torrent to download.
Returns:None. Torrent client specifies where torrent is downloaded to.

Note

Configured specifically for Transmission torrent client in Ubuntu.

AutomateTheBoringStuff.Ch16.Projects.P4_autoDownloadTorrent.fetch_emails(imap_obj_arg: <sphinx.ext.autodoc.importer._MockObject object at 0x7f7f2fc68780>) → tuple[source]

Fetch emails

Gets emails from IMAP server and returns the email’s uids and their raw messages.

Parameters:imap_obj_arg – Configured imapclient.IMAPClient object from login_imap().
Returns:Tuple with a list of message uids and a dictionary of raw messages with message uids as keys.
AutomateTheBoringStuff.Ch16.Projects.P4_autoDownloadTorrent.fetch_torrents(uids_arg: list, raw_messages_arg: dict) → dict[source]

Fetch torrents

Takes given list of message uids and dictionary of raw messages from fetch_emails() and parses out the torrent urls.

Parameters:
  • uids_arg – List of message uids.
  • raw_messages_arg – Dictionary of raw messages with message uids as keys and message data as values.
Returns:

Dictionary with message uids as keys and the torrent url string as values.

AutomateTheBoringStuff.Ch16.Projects.P4_autoDownloadTorrent.login_imap(file_arg: str) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f7f2fc687b8>[source]

Login IMAP

Logs into IMAP server with credentials from given file, then returns the configured imapclient.IMAPClient object.

Parameters:file_arg – String with path to IMAP server information file.
Returns:Configured imapclient.IMAPClient object.
AutomateTheBoringStuff.Ch16.Projects.P4_autoDownloadTorrent.login_smtp(file_arg: str) → tuple[source]

Login SMTP

Logs into SMTP server with credentials from given file, then returns the configured smtplib.SMTP_SSL object and account email.

Parameters:file_arg – String with path to SMTP server information file.
Returns:Tuple with smtplib.SMTP_SSL object and account email.
AutomateTheBoringStuff.Ch16.Projects.P4_autoDownloadTorrent.main()[source]

Module contents