Last active
July 11, 2019 22:31
-
-
Save purarue/94b5c977c411cc28f51161146203fe33 to your computer and use it in GitHub Desktop.
Opens xkcd's downloaded using xkcd-dl chronologically, waiting for user input between each comic
This file contains 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
#!/usr/bin/env python3 | |
""" | |
Opens xkcd's downloaded using xkcd-dl chronologically using the show_xkcd function from | |
https://github.com/tasdikrahman/xkcd-dl/ | |
Assumes you already have the xkcd's downloaded in the xkcd_archive folder (i.e. using --download-all) | |
(though you could just have the start/end folders in xkcd_archive and xkcd-dl would download them when asked to open) | |
Can pass a start xkcd like: | |
xkcd-read 5 | |
If on mac, install using 'pip3 install git+https://github.com/tasdikrahman/xkcd-dl' as the version on pypi doesnt | |
current detect if you're on mac and assumes xdg-open | |
""" | |
import sys | |
import os | |
from xkcd_dl.cli import show_xkcd | |
# make sure xkcd_archive exists here | |
contents = os.listdir() | |
if "xkcd_archive" not in contents: | |
print("Couldnt find the xkcd_archive folder in current directory", file=sys.stderr) | |
sys.exit(1) | |
# get contents | |
xkcd_dir = os.path.join(os.getcwd(), "xkcd_archive") | |
sorted_dirs = sorted(os.listdir(xkcd_dir), key=int) | |
# check if user asked to start somewhere | |
start_at = 0 | |
try: | |
start_at = int(sys.argv[1]) - 1 | |
if start_at < 0: | |
start_at = 0 | |
except: | |
pass | |
# open each waiting for user input | |
for xkcd_n in sorted_dirs[start_at:]: | |
show_xkcd(xkcd_n) | |
input("Hit enter to view the next xkcd...") | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment