AutomateTheBoringStuff.Ch15.Projects package

Submodules

AutomateTheBoringStuff.Ch15.Projects.P1_prettifiedStopwatch module

Prettified stopwatch

Expand P3_stopwatch from this chapter so that it uses str.rjust() and str.ljust() string methods to “prettify” the output.

Instead of output such as this:

Lap #1: 3.56 (3.56)
Lap #2: 8.63 (5.07)
Lap #3: 17.68 (9.05)
Lap #4: 19.11 (1.43)

… the output will look like this:

Lap # 1:  3.56 (  3.56)
Lap # 2:  8.63 (  5.07)
Lap # 3: 17.68 (  9.05)
Lap # 4: 19.11 (  1.43)

Next, use pyperclip to copy the text output to the clipboard so the user can quickly paste the output to a text file or email.

AutomateTheBoringStuff.Ch15.Projects.P1_prettifiedStopwatch.main()[source]

AutomateTheBoringStuff.Ch15.Projects.P2_scheduledComicDownloader module

Scheduled comic downloader

Write a program that checks the websites of several web comics and automatically downloads the images if the comic was updated since the program’s last visit.

Your operating system’s scheduler (Scheduled Tasks on Windows, launchd on OS X, and cron on Linux) can run your Python program once a day.

The Python program itself can download the comic and then copy it to your desktop so that it is easy to find. This will free you from having to check the website yourself to see whether it has updated.

Note

This only downloads from http://www.lefthandedtoons.com/ and http://buttersafe.com/ because all websites are different.

AutomateTheBoringStuff.Ch15.Projects.P2_scheduledComicDownloader.check_key(shelf_arg: shelve.open, url_arg: str) → bool[source]

Check key

Checks if given url is a key in the given shelf.

Parameters:
Returns:

True if the url is in the shelf, False otherwise.

AutomateTheBoringStuff.Ch15.Projects.P2_scheduledComicDownloader.compare_timestamps(timestamp_arg: str, shelf_arg: shelve.open, url_arg: str) → bool[source]

Compare timestamps

Compares timestamp of current comic to last downloaded comic timestamp of given url.

Parameters:
  • timestamp_arg – String with date in Month DD, YYYY format.
  • shelf_argshelve object with urls as keys and datetime.datetime.date() as values.
  • url_arg – String with website url.
Returns:

True if comic’s timestamp is after saved timestamp, False otherwise.

AutomateTheBoringStuff.Ch15.Projects.P2_scheduledComicDownloader.get_soup(url_arg: str) → <sphinx.ext.autodoc.importer._MockObject object at 0x7f7f2ff74438>[source]

Get soup

Downloads given url with requests and converts it to bs4.BeautifulSoup.

Parameters:url_arg – String with url to soupify.
Returns:BeautifulSoup object of given url.
Raises:requests.exceptions.HTTPError – If download of website url failed.
AutomateTheBoringStuff.Ch15.Projects.P2_scheduledComicDownloader.main()[source]
AutomateTheBoringStuff.Ch15.Projects.P2_scheduledComicDownloader.save_comic(comic_url_arg: str, shelf_arg: shelve.open, url_arg: str) → None[source]

Save comic

Downloads given comic url and saves to desktop, then updates download time of given website url in given shelf.

Parameters:
  • comic_url_arg – String with url of comic image.
  • shelf_argshelve object with urls as keys and datetime.datetime.date() as values.
  • url_arg – String with website url.
Returns:

None. Comic image is saved to desktop.

Raises:

requests.exceptions.HTTPError – If download of comic url failed.

Module contents