Booky / Python

Source »

Booky is a program to gather random book data by scraping Goodreads.

Thanks to Code Review user MrGrj for the suggested code improvements (present in v2 onward) and to Code Review user alecxe for the suggested code improvements (present in v5).

Booky-v5.py

$ python3 Booky-v5.py -h
usage: Booky-v5.py [-h] [-v {0,1,2,3}] [-mr MIN_RATING] filepath

Gather random book data from Goodreads and append it to a file in CSV format, until the program is manually closed or until a connection issue. I recommend having the CSV header: Title,Pages,Rating.

positional arguments:
  filepath              output file, only supports FULL path (no tilde, etc.)

optional arguments:
  -h, --help            show this help message and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        specify verbosity level, default = 2
                        0 = no output
                        1 = continually print line count after appending to file
                        2 = after keyboard interrupt, print count of lines added since program start and program run time
                        3 = both verbosity options 1 and 2
  -mr MIN_RATING, --min-rating MIN_RATING
                        specify the minimum accepted rating, default = 30

Booky-v4.py

$ python3 Booky-v4.py -h
usage: Booky-v4.py [-h] [-v {0,1,2,3}] [-mr MIN_RATING] filename

Gather random book data from Goodreads and append it to a file in CSV format, until the program is manually closed or until a connection issue.

example command: Booky-v4.py -v3 -mr /path/to/file.csv

positional arguments:
  filename              output file, only supports FULL path (no tilde, etc.)

optional arguments:
  -h, --help            show this help message and exit
  -v {0,1,2,3}, --verbosity {0,1,2,3}
                        specify verbosity level, default = 2
                        0 = no output
                        1 = continually print line count after appending to file
                        2 = after keyboard interrupt, print count of lines added since program start and program run time
                        3 = both verbosity options 1 and 2
  -mr MIN_RATING, --min-rating MIN_RATING
                        specify the minimum accepted rating, default = 30

Booky-v3.py

Booky-v2.py

Example output

$ python3 Booky-v2.py
My Kitchen Table: 100 Cakes and Bakes	208	4.33
Vita nel Medioevo	209	3.58
Fushigi Yûgi: The Mysterious Play, Vol. 18: Bride 	191	4.22
Silently Seduced: When Parents Make Their Children Partners	168	4.06
Gravitation, Band 10 	192	3.95

Booky.py

This version simply prints out the data. The program will continue until it is manually closed or crashes because of an error — there is no error handling in this version.

Example output

$ python3 Booky.py
Liberté sur parole	192	4.12
The Citadel	401	4.11
Working on Yourself Alone	154	3.98
Wolf Bait	35	3.94
Prudence 	451	3.8