Skip to content
This repository has been archived by the owner on Nov 1, 2022. It is now read-only.

Commit

Permalink
It now downloads alt text
Browse files Browse the repository at this point in the history
Downloads the `alttext` when mouse is hovered over the xkcd image

Closes #19
  • Loading branch information
BlitzKraft authored and prodicus committed Apr 7, 2016
1 parent 51f1a65 commit f2bdb48
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
9 changes: 8 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Features
- ``date-publised``
- url value
- a small description of that xkcd
- The alt text on the comic

- written in uncomplicated ``python``.

Expand Down Expand Up @@ -144,7 +145,7 @@ Demo
Each Comic is stored in it's own individual folder with a
``description.txt`` placed in it. It contains meta-data like -
``img-link`` - ``title`` - ``date-published``
``img-link`` - ``title`` - ``date-published`` - ``alt``

Here's a little example for the same

Expand Down Expand Up @@ -250,6 +251,8 @@ To-do
- [ ] Adding support to open a particular xkcd at the CLI itself.
(Thinking of using `img2txt <https://github.com/hit9/img2txt>`__ for
that)
- [ ] add exclude list to easily recognize and ignore dynamic comics
i.e. comics without a default image.
Known Issues
Expand All @@ -263,6 +266,10 @@ Known Issues
you don't have ``pip3`` installed.
``$ sudo apt-get install python3-pip`` should fix that. To check your
version of pip
- When there is a comic without an image (example: 1608) it fails with an
"UnboundLocalError: local variable 'img_link' referenced before assignment"
On the todo list now.
 
.. code:: bash
Expand Down
12 changes: 8 additions & 4 deletions xkcd_dl/cli.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

r'''
'''
Run `xkcd-dl --update-db` if running for the first time.
Usage:
xkcd-dl --update-db
Expand Down Expand Up @@ -109,6 +109,8 @@ def download_latest():
publishing_date = "{date}-{month}-{year}".format(date=date, month=mon, year=year)

title = response_content['title']
alt = response_content['alt']

stripped_title = title.replace(" ", "_").replace(":", "_").replace("/", "_").replace("*", "_").replace("$", "_").replace("@", "_")

xkcd_url = "{base}/{xkcd_num}".format(base=BASE_URL, xkcd_num=xkcd_number)
Expand All @@ -125,10 +127,11 @@ def download_latest():
content = """title : {description}
date-publised: {date}
url = {url}
""".format(
alt = {altText} \n""".format(
description=title,
date=publishing_date,
url=xkcd_url
url=xkcd_url,
altText=alt
)
f.write(content)

Expand Down Expand Up @@ -276,6 +279,7 @@ def download_one(xkcd_dict, xkcd_num):
path=new_folder
)
)
alt=requests.get(to_download_single+'info.0.json').json()['alt']
## check if file already exists! i.e xkcd has been downloaded
if os.path.exists(new_folder):
print("xkcd number '{num}' has already been downloaded!".format(num=xkcd_number))
Expand All @@ -287,7 +291,7 @@ def download_one(xkcd_dict, xkcd_num):
content = """title : {description}
date-publised: {date}
url = {url}
""".format(description=description, date=date, url=to_download_single)
alt = {altText} \n""".format(description=description, date=date, url=to_download_single, altText=alt)
f.write(content)

######################################
Expand Down

0 comments on commit f2bdb48

Please sign in to comment.