Skip to main content

comics

Project description

comics

GoComics API wrapper

pypiv Python 3.7+ continuous-integration Licence

Installation

pip install comics

Quick start

Find and download the Calvin and Hobbes comic strip published on January 2, 1990:

import comics

ch = comics.search("calvinandhobbes").date("January 2, 1990")
ch.download("calvinandhobbes.png")

Find comics

Available comics can be found using the directory class:

import comics

# List available comics - total of 475
comics.directory.listall()
# >>> ("1-and-done", "9-chickweed-lane-classics", "9chickweedlane", "9to5", ... )

# Find endpoints for Calvin and Hobbes
comics.directory.search("Calvin and Hobbes")
# >>> ("calvinandhobbes", "calvinandhobbesenespanol")

First, pass the desired endpoint to comics.search. For example, to search for Calvin and Hobbes comics in english use comics.search("calvinandhobbes"); for spanish, use comics.search("calvinandhobbesenespanol").

Search and download comics

Then, search for a comic strip using the date or random_date method:

import comics

# Get a Calvin and Hobbes comic strip by date
ch = comics.search("calvinandhobbes").date("2013-05-13")  # Also accepts datetime object

# Get a random Calvin and Hobbes comic strip
random_ch = comics.search("calvinandhobbes").random_date()

Finally, show, download, or stream the comic strip:

# Show comic strip - opens in default image viewer application
ch.show()

# Download comic strip - defaults to {endpoint}.png if an export path is not provided
# E.g., a Calvin and Hobbes comic strip will be exported as "calvinandhobbes.png" in the current working directory
ch.download()

# Stream comic strip - useful if custom image content manipulation is desired
ch.stream()

Attributes

An instantiated search class will have the following public attributes:

import comics

garfield = comics.search("garfield")
garfield.endpoint
# >>> "garfield"
garfield.title
# >>> "Garfield"
garfield.start_date
# >>> "1978-06-19"

An instantiated search class with date or random_date will have the following public attributes:

import comics

garfield = comics.search("garfield").date("08/20/2000")
garfield.endpoint
# >>> "garfield"
garfield.title
# >>> "Garfield"
garfield.date
# >>> "2000-08-20"
garfield.url
# >>> "https://www.gocomics.com/garfield/2000/08/20"
garfield.image_url
# >>> "https://assets.amuniversal.com/6694c52099bd01365606005056a9545d"

Exceptions

An exception will be thrown if the queried date is unregistered or before the comic's origin date:

import comics
from comics.exceptions import InvalidDateError

try:
    peanuts = comics.search("peanuts").date("1900-01-01")
    peanuts.download()
except InvalidDateError:
    print("Whoops, an invalid date was queried.")

An exception will be thrown if the queried endpoint is unregistered:

import comics
from comics.exceptions import InvalidEndpointError

try:
    invalid_comic = comics.search("invalid_endpoint").date("2000-01-01")
    invalid_comic.download()
except InvalidEndpointError:
    print("Whoops, an invalid endpoint was queried.")

Contribute

Support

If you are having issues or would like to propose a new feature, please use the issues tracker.

License

This project is licensed under the MIT license.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

comics-0.3.2.tar.gz (236.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

comics-0.3.2-py3-none-any.whl (16.8 kB view details)

Uploaded Python 3

File details

Details for the file comics-0.3.2.tar.gz.

File metadata

  • Download URL: comics-0.3.2.tar.gz
  • Upload date:
  • Size: 236.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for comics-0.3.2.tar.gz
Algorithm Hash digest
SHA256 c7587d2d768bfcca83614dc48cf3dbc418b1f2611ff4b5e4c4c78f0f2cfc2ef0
MD5 09491fed260644b9c787245042115f2c
BLAKE2b-256 ff579159486a327183a471c7878a34602f2268a9ccc8af1d1aaf9ebe3cbc2b0e

See more details on using hashes here.

File details

Details for the file comics-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: comics-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 16.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.28.1

File hashes

Hashes for comics-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79b64139d5fc5223495b63f4e52a11952decb8da0c47cf241c848db8de95f7e2
MD5 201ce5a97bb42a3c5e783ecb44eb8773
BLAKE2b-256 85821b00205d701fb7309a6f3704d2e244fee0dcd597d0ec8e5473e6842429b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page