This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tkinter import * | |
| from tkinter import messagebox | |
| from string import ascii_letters, digits | |
| from random import choices, shuffle | |
| import pyperclip | |
| import json | |
| symbols = '!#$%&()*+' | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from tkinter import * | |
| from tkinter import messagebox | |
| import winsound | |
| # ---------------------------- CONSTANTS ------------------------------- # | |
| # www.colorhunt.io | |
| PINK, RED, GREEN, YELLOW = "#e2979c", "#e7305b", "#9bdeac", "#f7f5dd" | |
| FONT_NAME = "Courier" | |
| # ---------------------------- VARIABLES ------------------------------- # | |
| reps, work_time, timer = 0, 0, 0 | |
| work_min, short_break_min, long_break_min = 25, 5, 20 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! python3 | |
| ''' | |
| Prettified Stopwatch | |
| Expand the stopwatch project from this chapter so that it uses the rjust() | |
| and ljust() string methods to “prettify” the output. (These methods were | |
| covered in Chapter 6.) 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Usage: excel-to-csvConverter.py folderPath or via input() | |
| Excel-to-CSV Converter | |
| Excel can save a spreadsheet to a CSV file with a few mouse clicks, but if | |
| you had to convert hundreds of Excel files to CSVs, it would take hours of | |
| clicking. Using the openpyxl module from Chapter 12, write a program that | |
| reads all the Excel files in the current working directory and outputs them | |
| as CSV files. | |
| A single Excel file might contain multiple sheets; you’ll have to | |
| create one CSV file per sheet. The filenames of the CSV files should be |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Brute-Force PDF Password Breaker | |
| Say you have an encrypted PDF that you have forgotten the password to, | |
| but you remember it was a single English word. Trying to guess your forgot- | |
| ten password is quite a boring task. Instead you can write a program that | |
| will decrypt the PDF by trying every possible English word until it finds one | |
| that works. This is called a brute-force password attack. Download the text file | |
| dictionary.txt from https://nostarch.com/automatestuff2/. This dictionary file | |
| contains over 44,000 English words with one word per line. | |
| Using the file-reading skills you learned in Chapter 9, create a list of |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Custom Invitations as Word Documents | |
| Say you have a text file of guest names. This guests.txt file has one name per | |
| line, as follows: | |
| Prof. Plum | |
| Miss Scarlet | |
| Col. Mustard | |
| Al Sweigart | |
| RoboCop | |
| Write a program that would generate a Word document with custom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| PDF Paranoia | |
| Using the os.walk() function from Chapter 10, write a script that will go | |
| through every PDF in a folder (and its subfolders) and encrypt the PDFs | |
| using a password provided on the command line. Save each encrypted PDF | |
| with an _encrypted.pdf suffix added to the original filename. Before deleting | |
| the original file, have the program attempt to read and decrypt the file to | |
| ensure that it was encrypted correctly. | |
| Then, write a program that finds all encrypted PDFs in a folder (and its | |
| subfolders) and creates a decrypted copy of the PDF using a provided pass- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| After a long day at the bean-counting office, I’ve finished a spreadsheet | |
| with all the bean totals and uploaded them to Google Sheets. The spread- | |
| sheet is publicly viewable (but not editable). You can get this spreadsheet | |
| with the following code: | |
| >>> import ezsheets | |
| >>> ss = ezsheets.Spreadsheet('1jDZEdvSIh4TmZxccyy0ZXrH-ELlrwq8_YYiZrEOB4jg') | |
| You can look at this spreadsheet in your browser by going to https://docs | |
| .google.com/spreadsheets/d/1jDZEdvSIh4TmZxccyy0ZXrH-ELlrwq8_YYiZrEOB4jg | |
| /edit?usp=sharing/. The columns of the first sheet in this spreadsheet are |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Spreadsheet to Text Files | |
| Write a program that performs the tasks of the previous program in reverse | |
| order: the program should open a spreadsheet and write the cells of column | |
| A into one text file, the cells of column B into another text file, and so on. | |
| ''' | |
| import os | |
| import re | |
| import openpyxl | |
| from openpyxl.utils import get_column_letter as GCL |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ''' | |
| Text Files to Spreadsheet | |
| Write a program to read in the contents of several text files (you can make | |
| the text files yourself) and insert those contents into a spreadsheet, with | |
| one line of text per row. The lines of the first text file will be in the cells of | |
| column A, the lines of the second text file will be in the cells of column B, | |
| and so on. | |
| Use the readlines() File object method to return a list of strings, one | |
| string per line in the file. For the first file, output the first line to column 1, | |
| row 1. The second line should be written to column 1, row 2, and so on. The |
NewerOlder