├── .editorconfig ├── .github ├── dependabot.yaml └── workflows │ ├── publishing.yaml │ └── testing.yaml ├── .pre-commit-config.yaml ├── .readthedocs.yaml ├── LICENSE ├── README.md ├── docs ├── index.md └── simyan │ ├── __init__.md │ ├── comicvine.md │ ├── exceptions.md │ ├── schemas │ ├── __init__.md │ ├── character.md │ ├── concept.md │ ├── creator.md │ ├── generic_entries.md │ ├── issue.md │ ├── item.md │ ├── location.md │ ├── origin.md │ ├── power.md │ ├── publisher.md │ ├── story_arc.md │ ├── team.md │ └── volume.md │ └── sqlite_cache.md ├── mkdocs.yaml ├── pyproject.toml ├── simyan ├── __init__.py ├── comicvine.py ├── exceptions.py ├── schemas │ ├── __init__.py │ ├── character.py │ ├── concept.py │ ├── creator.py │ ├── generic_entries.py │ ├── issue.py │ ├── item.py │ ├── location.py │ ├── origin.py │ ├── power.py │ ├── publisher.py │ ├── story_arc.py │ ├── team.py │ └── volume.py └── sqlite_cache.py └── tests ├── README.md ├── __init__.py ├── cache.sqlite ├── characters_test.py ├── concepts_test.py ├── conftest.py ├── creators_test.py ├── exceptions_test.py ├── issues_test.py ├── items_test.py ├── locations_test.py ├── origins_test.py ├── powers_test.py ├── publishers_test.py ├── story_arcs_test.py ├── teams_test.py └── volumes_test.py /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = space 5 | indent_size = 2 6 | end_of_line = lf 7 | charset = utf-8 8 | trim_trailing_whitespace = true 9 | insert_final_newline = true 10 | max_line_length = 100 11 | 12 | [*.bat] 13 | indent_style = tab 14 | 15 | [*.json] 16 | insert_final_newline = false 17 | 18 | [*.md] 19 | trim_trailing_whitespace = false 20 | 21 | [*.py] 22 | indent_size = 4 23 | 24 | [{*.xml,*.xsd}] 25 | indent_size = 4 26 | indent_style = tab 27 | insert_final_newline = false 28 | 29 | [{*.yaml,*.yml}] 30 | indent_style = tab 31 | -------------------------------------------------------------------------------- /.github/dependabot.yaml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | directory: / 5 | schedule: 6 | interval: daily 7 | groups: 8 | github_actions: 9 | patterns: 10 | - "*" 11 | 12 | - package-ecosystem: pip 13 | directory: / 14 | schedule: 15 | interval: daily 16 | groups: 17 | python: 18 | patterns: 19 | - "*" 20 | -------------------------------------------------------------------------------- /.github/workflows/publishing.yaml: -------------------------------------------------------------------------------- 1 | name: Publishing 2 | 3 | on: push 4 | 5 | jobs: 6 | build: 7 | name: Build 8 | runs-on: ubuntu-latest 9 | 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-python@v5 13 | with: 14 | python-version: '3.12' 15 | - name: Install pypa/build 16 | run: pip install build 17 | - name: Build a binary wheel and a source tarball 18 | run: python -m build 19 | - uses: actions/upload-artifact@v4 20 | with: 21 | name: python-package-distributions 22 | path: dist/ 23 | 24 | publish-to-pypi: 25 | name: Publish to PyPI 26 | if: startsWith(github.ref, 'refs/tags/') 27 | needs: 28 | - build 29 | runs-on: ubuntu-latest 30 | environment: 31 | name: pypi 32 | url: https://pypi.org/p/simyan 33 | permissions: 34 | id-token: write 35 | 36 | steps: 37 | - uses: actions/download-artifact@v4 38 | with: 39 | name: python-package-distributions 40 | path: dist/ 41 | - uses: pypa/gh-action-pypi-publish@release/v1 42 | -------------------------------------------------------------------------------- /.github/workflows/testing.yaml: -------------------------------------------------------------------------------- 1 | name: Testing 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | paths-ignore: 8 | - docs/** 9 | pull_request: 10 | branches: 11 | - main 12 | paths-ignore: 13 | - docs/** 14 | 15 | concurrency: 16 | group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} 17 | cancel-in-progress: true 18 | 19 | jobs: 20 | pytest: 21 | strategy: 22 | fail-fast: false 23 | matrix: 24 | python-version: 25 | - '3.9' 26 | - '3.10' 27 | - '3.11' 28 | - '3.12' 29 | - '3.13' 30 | os: 31 | - ubuntu-latest 32 | - macos-latest 33 | - windows-latest 34 | runs-on: ${{ matrix.os }} 35 | steps: 36 | - uses: actions/checkout@v4 37 | - uses: astral-sh/setup-uv@v6 38 | - name: Setup Python 39 | run: uv python install ${{ matrix.python-version }} 40 | - name: Install project 41 | run: uv sync --group tests 42 | - name: Run tests 43 | env: 44 | COMICVINE__API_KEY: IGNORED 45 | run: uv run pytest 46 | collector: 47 | needs: [pytest] 48 | if: always() 49 | runs-on: ubuntu-latest 50 | steps: 51 | - name: Check for failures 52 | if: contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') 53 | run: echo job failed && exit 1 54 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/astral-sh/ruff-pre-commit 3 | rev: v0.8.4 4 | hooks: 5 | - id: ruff-format 6 | - id: ruff 7 | - repo: https://github.com/executablebooks/mdformat 8 | rev: 0.7.21 9 | hooks: 10 | - id: mdformat 11 | additional_dependencies: 12 | - mdformat-gfm 13 | - mdformat-tables 14 | args: 15 | - --number 16 | - --wrap=keep 17 | - repo: https://github.com/pre-commit/pre-commit-hooks 18 | rev: v5.0.0 19 | hooks: 20 | - id: check-ast 21 | - id: check-builtin-literals 22 | - id: check-case-conflict 23 | - id: check-docstring-first 24 | - id: check-merge-conflict 25 | args: 26 | - --assume-in-merge 27 | - id: check-toml 28 | - id: check-yaml 29 | args: 30 | - --allow-multiple-documents 31 | - id: end-of-file-fixer 32 | exclude_types: 33 | - json 34 | - xml 35 | - id: fix-byte-order-marker 36 | - id: forbid-submodules 37 | - id: mixed-line-ending 38 | args: 39 | - --fix=auto 40 | - id: name-tests-test 41 | - id: trailing-whitespace 42 | args: 43 | - --markdown-linebreak-ext=md 44 | - repo: https://github.com/pappasam/toml-sort 45 | rev: v0.24.2 46 | hooks: 47 | - id: toml-sort 48 | args: 49 | - --in-place 50 | - --all 51 | - repo: meta 52 | hooks: 53 | - id: check-hooks-apply 54 | - id: check-useless-excludes 55 | -------------------------------------------------------------------------------- /.readthedocs.yaml: -------------------------------------------------------------------------------- 1 | # Read the Docs configuration file for MkDocs projects 2 | # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details 3 | 4 | # Required 5 | version: 2 6 | 7 | # Set the version of Python and other tools you might need 8 | build: 9 | os: ubuntu-22.04 10 | tools: 11 | python: "3.13" 12 | jobs: 13 | post_create_environment: 14 | - pip install uv 15 | post_install: 16 | - UV_PROJECT_ENVIRONMENT=$READTHEDOCS_VIRTUALENV_PATH uv sync --group docs --inexact 17 | 18 | mkdocs: 19 | configuration: mkdocs.yaml 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simyan 2 | 3 | [![PyPI - Python](https://img.shields.io/pypi/pyversions/Simyan.svg?logo=Python&label=Python&style=flat-square)](https://pypi.python.org/pypi/Simyan/) 4 | [![PyPI - Status](https://img.shields.io/pypi/status/Simyan.svg?logo=Python&label=Status&style=flat-square)](https://pypi.python.org/pypi/Simyan/) 5 | [![PyPI - Version](https://img.shields.io/pypi/v/Simyan.svg?logo=Python&label=Version&style=flat-square)](https://pypi.python.org/pypi/Simyan/) 6 | [![PyPI - License](https://img.shields.io/pypi/l/Simyan.svg?logo=Python&label=License&style=flat-square)](https://opensource.org/licenses/GPL-3.0) 7 | 8 | [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-informational?logo=pre-commit&style=flat-square)](https://github.com/pre-commit/pre-commit) 9 | [![Ruff](https://img.shields.io/badge/ruff-enabled-informational?logo=ruff&style=flat-square)](https://github.com/astral-sh/ruff) 10 | 11 | [![Github - Contributors](https://img.shields.io/github/contributors/Metron-Project/Simyan.svg?logo=Github&label=Contributors&style=flat-square)](https://github.com/Metron-Project/Simyan/graphs/contributors) 12 | [![Github Action - Testing](https://img.shields.io/github/actions/workflow/status/Metron-Project/Simyan/testing.yaml?branch=main&logo=Github&label=Testing&style=flat-square)](https://github.com/Metron-Project/Simyan/actions/workflows/testing.yaml) 13 | [![Github Action - Publishing](https://img.shields.io/github/actions/workflow/status/Metron-Project/Simyan/publishing.yaml?branch=main&logo=Github&label=Publishing&style=flat-square)](https://github.com/Metron-Project/Simyan/actions/workflows/publishing.yaml) 14 | 15 | [![Read the Docs](https://img.shields.io/readthedocs/simyan?label=Read-the-Docs&logo=Read-the-Docs&style=flat-square)](https://simyan.readthedocs.io/en/stable) 16 | 17 | A [Python](https://www.python.org/) wrapper for the [Comicvine API](https://comicvine.gamespot.com/api/). 18 | 19 | ## Installation 20 | 21 | ```console 22 | pip install --user Simyan 23 | ``` 24 | 25 | ### Example Usage 26 | 27 | ```python 28 | from simyan.comicvine import Comicvine 29 | from simyan.sqlite_cache import SQLiteCache 30 | 31 | session = Comicvine(api_key="Comicvine API Key", cache=SQLiteCache()) 32 | 33 | # Search for Publisher 34 | results = session.list_publishers(params={"filter": "name:DC Comics"}) 35 | for publisher in results: 36 | print(f"{publisher.id} | {publisher.name} - {publisher.site_url}") 37 | 38 | # Get details for a Volume 39 | result = session.get_volume(volume_id=26266) 40 | print(result.summary) 41 | ``` 42 | 43 | ## Documentation 44 | 45 | - [Simyan](https://simyan.readthedocs.io/en/stable) 46 | - [Comicvine API](https://comicvine.gamespot.com/api/documentation) 47 | 48 | ## Bugs/Requests 49 | 50 | Please use the [GitHub issue tracker](https://github.com/Metron-Project/Simyan/issues) to submit bugs or request features. 51 | 52 | ## Contributing 53 | 54 | - When running a new test for the first time, set the environment variable `COMICVINE__API_KEY` to your Comicvine API key. 55 | The responses will be cached in the `tests/cache.sqlite` database without your key. 56 | 57 | ## Socials 58 | 59 | [![Social - Matrix](https://img.shields.io/matrix/metron-general:matrix.org?label=Metron%20General&logo=matrix&style=for-the-badge)](https://matrix.to/#/#metron-general:matrix.org) 60 | [![Social - Matrix](https://img.shields.io/matrix/metron-devel:matrix.org?label=Metron%20Development&logo=matrix&style=for-the-badge)](https://matrix.to/#/#metron-development:matrix.org) 61 | -------------------------------------------------------------------------------- /docs/index.md: -------------------------------------------------------------------------------- 1 | {% 2 | include-markdown "../README.md" 3 | %} 4 | -------------------------------------------------------------------------------- /docs/simyan/__init__.md: -------------------------------------------------------------------------------- 1 | # Package Contents 2 | 3 | ::: simyan.get_cache_root 4 | -------------------------------------------------------------------------------- /docs/simyan/comicvine.md: -------------------------------------------------------------------------------- 1 | # Comicvine 2 | 3 | ::: simyan.comicvine.Comicvine 4 | ::: simyan.comicvine.ComicvineResource 5 | -------------------------------------------------------------------------------- /docs/simyan/exceptions.md: -------------------------------------------------------------------------------- 1 | # Exceptions 2 | 3 | ::: simyan.exceptions.AuthenticationError 4 | ::: simyan.exceptions.ServiceError 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/__init__.md: -------------------------------------------------------------------------------- 1 | # Package Contents 2 | 3 | ::: simyan.schemas.BaseModel 4 | -------------------------------------------------------------------------------- /docs/simyan/schemas/character.md: -------------------------------------------------------------------------------- 1 | # Character 2 | 3 | ::: simyan.schemas.character.BasicCharacter 4 | ::: simyan.schemas.character.Character 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/concept.md: -------------------------------------------------------------------------------- 1 | # Concept 2 | 3 | ::: simyan.schemas.concept.BasicConcept 4 | ::: simyan.schemas.concept.Concept 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/creator.md: -------------------------------------------------------------------------------- 1 | # Creator 2 | 3 | ::: simyan.schemas.creator.BasicCreator 4 | ::: simyan.schemas.creator.Creator 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/generic_entries.md: -------------------------------------------------------------------------------- 1 | # Generic Entries 2 | 3 | ::: simyan.schemas.generic_entries.AssociatedImage 4 | ::: simyan.schemas.generic_entries.GenericCount 5 | ::: simyan.schemas.generic_entries.GenericCreator 6 | ::: simyan.schemas.generic_entries.GenericEntry 7 | ::: simyan.schemas.generic_entries.GenericIssue 8 | ::: simyan.schemas.generic_entries.Images 9 | -------------------------------------------------------------------------------- /docs/simyan/schemas/issue.md: -------------------------------------------------------------------------------- 1 | # Issue 2 | 3 | ::: simyan.schemas.issue.BasicIssue 4 | ::: simyan.schemas.issue.Issue 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/item.md: -------------------------------------------------------------------------------- 1 | # Item 2 | 3 | ::: simyan.schemas.item.BasicItem 4 | ::: simyan.schemas.item.Item 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/location.md: -------------------------------------------------------------------------------- 1 | # Location 2 | 3 | ::: simyan.schemas.location.BasicLocation 4 | ::: simyan.schemas.location.Location 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/origin.md: -------------------------------------------------------------------------------- 1 | # Origin 2 | 3 | ::: simyan.schemas.origin.BasicOrigin 4 | ::: simyan.schemas.origin.Origin 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/power.md: -------------------------------------------------------------------------------- 1 | # Power 2 | 3 | ::: simyan.schemas.power.BasicPower 4 | ::: simyan.schemas.power.Power 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/publisher.md: -------------------------------------------------------------------------------- 1 | # Publisher 2 | 3 | ::: simyan.schemas.publisher.BasicPublisher 4 | ::: simyan.schemas.publisher.Publisher 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/story_arc.md: -------------------------------------------------------------------------------- 1 | # Story Arc 2 | 3 | ::: simyan.schemas.story_arc.BasicStoryArc 4 | ::: simyan.schemas.story_arc.StoryArc 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/team.md: -------------------------------------------------------------------------------- 1 | # Team 2 | 3 | ::: simyan.schemas.team.BasicTeam 4 | ::: simyan.schemas.team.Team 5 | -------------------------------------------------------------------------------- /docs/simyan/schemas/volume.md: -------------------------------------------------------------------------------- 1 | # Volume 2 | 3 | ::: simyan.schemas.volume.BasicVolume 4 | ::: simyan.schemas.volume.Volume 5 | -------------------------------------------------------------------------------- /docs/simyan/sqlite_cache.md: -------------------------------------------------------------------------------- 1 | # SQLite Cache 2 | 3 | ::: simyan.sqlite_cache.SQLiteCache 4 | -------------------------------------------------------------------------------- /mkdocs.yaml: -------------------------------------------------------------------------------- 1 | site_name: Simyan 2 | site_url: https://simyan.readthedocs.io/en/latest/ 3 | site_description: A Python wrapper for the Comicvine API. 4 | site_author: Jonah Jackson 5 | 6 | copyright: GPL-3.0 7 | 8 | repo_url: https://github.com/Metron-Project/Simyan 9 | repo_name: Metron-Project/Simyan 10 | 11 | theme: 12 | name: material 13 | features: 14 | - content.code.copy 15 | - navigation.expand 16 | - navigation.top 17 | icon: 18 | repo: material/github 19 | palette: 20 | - media: "(prefers-color-scheme: light)" 21 | scheme: default 22 | primary: teal 23 | toggle: 24 | icon: material/weather-sunny 25 | name: Switch to dark mode 26 | - media: "(prefers-color-scheme: dark)" 27 | scheme: slate 28 | primary: teal 29 | toggle: 30 | icon: material/weather-night 31 | name: Switch to light mode 32 | 33 | extra: 34 | social: 35 | - icon: material/github 36 | link: https://github.com/Buried-In-Code 37 | - icon: material/language-python 38 | link: https://pypi.org/project/simyan/ 39 | - icon: material/mastodon 40 | link: https://fosstodon.org/@BuriedInCode 41 | - icon: simple/matrix 42 | link: https://matrix.to/#/#metron-general:matrix.org 43 | 44 | markdown_extensions: 45 | - pymdownx.highlight: 46 | auto_title: true 47 | - pymdownx.inlinehilite 48 | - pymdownx.superfences 49 | 50 | 51 | nav: 52 | - Home: index.md 53 | - simyan: 54 | - Package: simyan/__init__.md 55 | - exceptions: simyan/exceptions.md 56 | - comicvine: simyan/comicvine.md 57 | - sqlite_cache: simyan/sqlite_cache.md 58 | - simyan.schemas: 59 | - Package: simyan/schemas/__init__.md 60 | - character: simyan/schemas/character.md 61 | - concept: simyan/schemas/concept.md 62 | - creator: simyan/schemas/creator.md 63 | - generic_entries: simyan/schemas/generic_entries.md 64 | - issue: simyan/schemas/issue.md 65 | - item: simyan/schemas/item.md 66 | - location: simyan/schemas/location.md 67 | - origin: simyan/schemas/origin.md 68 | - power: simyan/schemas/power.md 69 | - publisher: simyan/schemas/publisher.md 70 | - story_arc: simyan/schemas/story_arc.md 71 | - team: simyan/schemas/team.md 72 | - volume: simyan/schemas/volume.md 73 | 74 | plugins: 75 | - search 76 | - mkdocstrings: 77 | default_handler: python 78 | handlers: 79 | python: 80 | options: 81 | show_root_heading: True 82 | show_root_full_path: False 83 | show_category_heading: True 84 | # Docstrings 85 | docstring_style: google 86 | docstring_section_style: spacy 87 | line_length: 100 88 | merge_init_into_class: True 89 | show_signature_annotations: True 90 | # Additional 91 | show_source: False 92 | - include-markdown 93 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | build-backend = "hatchling.build" 3 | requires = ["hatchling"] 4 | 5 | [dependency-groups] 6 | dev = [ 7 | "pre-commit >= 4.0.1" 8 | ] 9 | docs = [ 10 | "mkdocs >= 1.6.1", 11 | "mkdocs-include-markdown-plugin >= 7.1.2", 12 | "mkdocs-material >= 9.5.48", 13 | "mkdocstrings[python] >= 0.27.0" 14 | ] 15 | tests = [ 16 | "pytest >= 8.3.4", 17 | "pytest-cov >= 6.0.0", 18 | "tox >= 4.23.2", 19 | "tox-uv >= 1.16.1" 20 | ] 21 | 22 | [project] 23 | authors = [ 24 | {email = "BuriedInCode@tuta.io", name = "BuriedInCode"} 25 | ] 26 | classifiers = [ 27 | "Development Status :: 4 - Beta", 28 | "Environment :: Console", 29 | "Intended Audience :: Developers", 30 | "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", 31 | "Natural Language :: English", 32 | "Operating System :: MacOS", 33 | "Operating System :: Microsoft :: Windows", 34 | "Operating System :: POSIX :: Linux", 35 | "Programming Language :: Python :: 3.10", 36 | "Programming Language :: Python :: 3.11", 37 | "Programming Language :: Python :: 3.12", 38 | "Programming Language :: Python :: 3.13", 39 | "Programming Language :: Python :: 3.9", 40 | "Programming Language :: Python", 41 | "Topic :: Internet", 42 | "Typing :: Typed" 43 | ] 44 | dependencies = [ 45 | "eval-type-backport >= 0.2.0; python_version < '3.10'", 46 | "pydantic >= 2.10.4", 47 | "ratelimit >= 2.2.1", 48 | "requests >= 2.32.3" 49 | ] 50 | description = "A Python wrapper for the Comicvine API." 51 | dynamic = ["version"] 52 | keywords = ["comic", "comics", "metadata"] 53 | license = {text = "GPL-3.0-or-later"} 54 | maintainers = [ 55 | {email = "BuriedInCode@tuta.io", name = "BuriedInCode"} 56 | ] 57 | name = "Simyan" 58 | readme = "README.md" 59 | requires-python = ">= 3.9" 60 | 61 | [project.urls] 62 | Documentation = "https://simyan.readthedocs.io/en/latest/" 63 | Homepage = "https://pypi.org/project/Simyan" 64 | Issues = "https://github.com/Metron-Project/Simyan/issues" 65 | Source = "https://github.com/Metron-Project/Simyan" 66 | 67 | [tool.coverage.report] 68 | show_missing = true 69 | 70 | [tool.coverage.run] 71 | source = ["simyan"] 72 | 73 | [tool.hatch.build.targets.sdist] 74 | exclude = [".github/"] 75 | 76 | [tool.hatch.version] 77 | path = "simyan/__init__.py" 78 | 79 | [tool.pytest.ini_options] 80 | addopts = ["--cov"] 81 | 82 | [tool.ruff] 83 | fix = true 84 | line-length = 100 85 | output-format = "grouped" 86 | show-fixes = true 87 | unsafe-fixes = true 88 | 89 | [tool.ruff.format] 90 | docstring-code-format = true 91 | line-ending = "native" 92 | skip-magic-trailing-comma = true 93 | 94 | [tool.ruff.lint] 95 | ignore = [ 96 | "COM812", 97 | "D107", 98 | "DTZ001", 99 | "EM101", 100 | "EM102", 101 | "FBT", 102 | "PLR2004", 103 | "TCH", 104 | "TRY003" 105 | ] 106 | select = ["ALL"] 107 | 108 | [tool.ruff.lint.flake8-annotations] 109 | allow-star-arg-any = true 110 | mypy-init-return = true 111 | 112 | [tool.ruff.lint.flake8-tidy-imports] 113 | ban-relative-imports = "all" 114 | 115 | [tool.ruff.lint.flake8-unused-arguments] 116 | ignore-variadic-names = true 117 | 118 | [tool.ruff.lint.isort] 119 | combine-as-imports = true 120 | split-on-trailing-comma = false 121 | 122 | [tool.ruff.lint.pep8-naming] 123 | classmethod-decorators = ["classmethod", "pydantic.field_validator"] 124 | 125 | [tool.ruff.lint.per-file-ignores] 126 | "tests/*" = ["PLR2004", "S101"] 127 | 128 | [tool.ruff.lint.pydocstyle] 129 | convention = "google" 130 | 131 | [tool.ruff.lint.pyupgrade] 132 | keep-runtime-typing = true 133 | 134 | [tool.tomlsort] 135 | all = true 136 | overrides."tool.tox.env_list".inline_arrays = false 137 | overrides."tool.tox.testenv.commands".inline_arrays = false 138 | 139 | [tool.tox] 140 | env_list = ["3.9", "3.10", "3.11", "3.12", "3.13"] 141 | min_version = "4.22" 142 | 143 | [tool.tox.env_run_base] 144 | commands = [["pytest"]] 145 | dependency_groups = ["tests"] 146 | passenv = ["COMICVINE__API_KEY"] 147 | -------------------------------------------------------------------------------- /simyan/__init__.py: -------------------------------------------------------------------------------- 1 | """simyan package entry file.""" 2 | 3 | __all__ = ["__version__", "get_cache_root"] 4 | __version__ = "1.4.0" 5 | 6 | import os 7 | from pathlib import Path 8 | 9 | 10 | def get_cache_root() -> Path: 11 | """Create and return the path to the cache for Simyan, supports XDG_CACHE_HOME env. 12 | 13 | Returns: 14 | The path to the Simyan cache folder. 15 | """ 16 | cache_home = os.getenv("XDG_CACHE_HOME", default=str(Path.home() / ".cache")) 17 | folder = Path(cache_home).resolve() / "simyan" 18 | folder.mkdir(parents=True, exist_ok=True) 19 | return folder 20 | -------------------------------------------------------------------------------- /simyan/comicvine.py: -------------------------------------------------------------------------------- 1 | """The Comicvine module. 2 | 3 | This module provides the following classes: 4 | - Comicvine 5 | - ComicvineResource 6 | """ 7 | 8 | __all__ = ["Comicvine", "ComicvineResource"] 9 | 10 | import platform 11 | import re 12 | from enum import Enum 13 | from typing import Any, Optional, TypeVar, Union 14 | from urllib.parse import urlencode 15 | 16 | from pydantic import TypeAdapter, ValidationError 17 | from ratelimit import limits, sleep_and_retry 18 | from requests import get 19 | from requests.exceptions import ( 20 | ConnectionError, # noqa: A004 21 | HTTPError, 22 | JSONDecodeError, 23 | ReadTimeout, 24 | ) 25 | 26 | from simyan import __version__ 27 | from simyan.exceptions import AuthenticationError, ServiceError 28 | from simyan.schemas.character import BasicCharacter, Character 29 | from simyan.schemas.concept import BasicConcept, Concept 30 | from simyan.schemas.creator import BasicCreator, Creator 31 | from simyan.schemas.issue import BasicIssue, Issue 32 | from simyan.schemas.item import BasicItem, Item 33 | from simyan.schemas.location import BasicLocation, Location 34 | from simyan.schemas.origin import BasicOrigin, Origin 35 | from simyan.schemas.power import BasicPower, Power 36 | from simyan.schemas.publisher import BasicPublisher, Publisher 37 | from simyan.schemas.story_arc import BasicStoryArc, StoryArc 38 | from simyan.schemas.team import BasicTeam, Team 39 | from simyan.schemas.volume import BasicVolume, Volume 40 | from simyan.sqlite_cache import SQLiteCache 41 | 42 | MINUTE = 60 43 | T = TypeVar("T") 44 | 45 | 46 | class ComicvineResource(Enum): 47 | """Enum class for Comicvine Resources.""" 48 | 49 | ISSUE = (4000, "issue", list[BasicIssue]) 50 | """""" 51 | CHARACTER = (4005, "character", list[BasicCharacter]) 52 | """""" 53 | PUBLISHER = (4010, "publisher", list[BasicPublisher]) 54 | """""" 55 | CONCEPT = (4015, "concept", list[BasicConcept]) 56 | """""" 57 | LOCATION = (4020, "location", list[BasicLocation]) 58 | """""" 59 | ORIGIN = (4030, "origin", list[BasicOrigin]) 60 | """""" 61 | POWER = (4035, "power", list[BasicPower]) 62 | """""" 63 | CREATOR = (4040, "person", list[BasicCreator]) 64 | """""" 65 | STORY_ARC = (4045, "story_arc", list[BasicStoryArc]) 66 | """""" 67 | VOLUME = (4050, "volume", list[BasicVolume]) 68 | """""" 69 | ITEM = (4055, "object", list[BasicItem]) 70 | """""" 71 | TEAM = (4060, "team", list[BasicTeam]) 72 | """""" 73 | 74 | @property 75 | def resource_id(self) -> int: 76 | """Start of id used by Comicvine to create unique ids.""" 77 | return self.value[0] 78 | 79 | @property 80 | def search_resource(self) -> str: 81 | """Resource string for filtering searches.""" 82 | return self.value[1] 83 | 84 | @property 85 | def search_response(self) -> type[T]: 86 | """Response type for resource when using a search endpoint.""" 87 | return self.value[2] 88 | 89 | 90 | class Comicvine: 91 | """Class with functionality to request Comicvine API endpoints. 92 | 93 | Args: 94 | api_key: User's API key to access the Comicvine API. 95 | timeout: Set how long requests will wait for a response (in seconds). 96 | cache: SQLiteCache to use if set. 97 | """ 98 | 99 | API_URL = "https://comicvine.gamespot.com/api" 100 | 101 | def __init__(self, api_key: str, timeout: int = 30, cache: Optional[SQLiteCache] = None): 102 | self.headers = { 103 | "Accept": "application/json", 104 | "User-Agent": f"Simyan/{__version__}/{platform.system()}: {platform.release()}", 105 | } 106 | self.api_key = api_key 107 | self.timeout = timeout 108 | self.cache = cache 109 | 110 | @sleep_and_retry 111 | @limits(calls=20, period=MINUTE) 112 | def _perform_get_request( 113 | self, url: str, params: Optional[dict[str, str]] = None 114 | ) -> dict[str, Any]: 115 | """Make GET request to Comicvine API endpoint. 116 | 117 | Args: 118 | url: The url to request information from. 119 | params: Parameters to add to the request. 120 | 121 | Returns: 122 | Json response from the Comicvine API. 123 | 124 | Raises: 125 | ServiceError: If there is an issue with the request or response from the Comicvine API. 126 | """ 127 | if params is None: 128 | params = {} 129 | 130 | try: 131 | response = get(url, params=params, headers=self.headers, timeout=self.timeout) 132 | response.raise_for_status() 133 | return response.json() 134 | except ConnectionError as err: 135 | raise ServiceError(f"Unable to connect to '{url}'") from err 136 | except HTTPError as err: 137 | try: 138 | if err.response.status_code in (401, 420): 139 | # This should be 429 but CV uses 420 for ratelimiting 140 | raise AuthenticationError(err.response.json()["error"]) from err 141 | if err.response.status_code == 404: 142 | raise ServiceError("404: Not Found") from err 143 | if err.response.status_code in (502, 503): 144 | raise ServiceError("Service error, retry again later") from err 145 | raise ServiceError(err.response.json()["error"]) from err 146 | except JSONDecodeError as err: 147 | raise ServiceError(f"Unable to parse response from '{url}' as Json") from err 148 | except JSONDecodeError as err: 149 | raise ServiceError(f"Unable to parse response from '{url} as Json") from err 150 | except ReadTimeout as err: 151 | raise ServiceError("Service took too long to respond") from err 152 | 153 | def _get_request( 154 | self, endpoint: str, params: Optional[dict[str, str]] = None, skip_cache: bool = False 155 | ) -> dict[str, Any]: 156 | """Check cache or make GET request to Comicvine API endpoint. 157 | 158 | Args: 159 | endpoint: The endpoint to request information from. 160 | params: Parameters to add to the request. 161 | skip_cache: Skip read and writing to the cache. 162 | 163 | Returns: 164 | Json response from the Comicvine API. 165 | 166 | Raises: 167 | ServiceError: If there is an issue with the request or response from the Comicvine API. 168 | AuthenticationError: If Comicvine returns with an invalid API key response. 169 | """ 170 | if params is None: 171 | params = {} 172 | params["api_key"] = self.api_key 173 | params["format"] = "json" 174 | 175 | url = self.API_URL + endpoint + "/" 176 | cache_params = f"?{urlencode({k: params[k] for k in sorted(params)})}" 177 | cache_key = f"{url}{cache_params}" 178 | cache_key = re.sub(r"(.+api_key=)(.+?)(&.+)", r"\1*****\3", cache_key) 179 | 180 | if self.cache and not skip_cache: 181 | cached_response = self.cache.select(query=cache_key) 182 | if cached_response: 183 | return cached_response 184 | 185 | response = self._perform_get_request(url=url, params=params) 186 | if "error" in response and response["error"] != "OK": 187 | raise ServiceError(response["error"]) 188 | 189 | if self.cache and not skip_cache: 190 | self.cache.insert(query=cache_key, response=response) 191 | 192 | return response 193 | 194 | def _get_offset_request( 195 | self, endpoint: str, params: Optional[dict[str, Any]] = None, max_results: int = 500 196 | ) -> list[dict[str, Any]]: 197 | """Get results from offset requests. 198 | 199 | Args: 200 | endpoint: The endpoint to request information from. 201 | params: Parameters to add to the request. 202 | max_results: Limits the amount of results looked up and returned. 203 | 204 | Returns: 205 | A list of Json response results. 206 | """ 207 | if params is None: 208 | params = {} 209 | params["limit"] = 100 210 | response = self._get_request(endpoint=endpoint, params=params) 211 | results = response["results"] 212 | while ( 213 | response["results"] 214 | and len(results) < response["number_of_total_results"] 215 | and len(results) < max_results 216 | ): 217 | params["offset"] = len(results) 218 | response = self._get_request(endpoint=endpoint, params=params) 219 | results.extend(response["results"]) 220 | return results[:max_results] 221 | 222 | def _get_paged_request( 223 | self, endpoint: str, params: Optional[dict[str, Any]] = None, max_results: int = 500 224 | ) -> list[dict[str, Any]]: 225 | """Get results from paged requests. 226 | 227 | Args: 228 | endpoint: The endpoint to request information from. 229 | params: Parameters to add to the request. 230 | max_results: Limits the amount of results looked up and returned. 231 | 232 | Returns: 233 | A list of Json response results. 234 | """ 235 | if params is None: 236 | params = {} 237 | params["page"] = 1 238 | params["limit"] = 100 239 | response = self._get_request(endpoint=endpoint, params=params) 240 | results = response["results"] 241 | while ( 242 | response["results"] 243 | and len(results) < response["number_of_total_results"] 244 | and len(results) < max_results 245 | ): 246 | params["page"] += 1 247 | response = self._get_request(endpoint=endpoint, params=params) 248 | results.extend(response["results"]) 249 | return results[:max_results] 250 | 251 | def list_publishers( 252 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 253 | ) -> list[BasicPublisher]: 254 | """Request a list of Publishers. 255 | 256 | Args: 257 | params: Parameters to add to the request. 258 | max_results: Limits the amount of results looked up and returned. 259 | 260 | Returns: 261 | A list of Publisher objects. 262 | 263 | Raises: 264 | ServiceError: If there is an issue with validating the response. 265 | """ 266 | try: 267 | results = self._get_offset_request( 268 | endpoint="/publishers", params=params, max_results=max_results 269 | ) 270 | return TypeAdapter(list[BasicPublisher]).validate_python(results) 271 | except ValidationError as err: 272 | raise ServiceError(err) from err 273 | 274 | def get_publisher(self, publisher_id: int) -> Publisher: 275 | """Request a Publisher using its id. 276 | 277 | Args: 278 | publisher_id: The Publisher id. 279 | 280 | Returns: 281 | A Publisher object or None if not found. 282 | 283 | Raises: 284 | ServiceError: If there is an issue with validating the response. 285 | """ 286 | try: 287 | result = self._get_request( 288 | endpoint=f"/publisher/{ComicvineResource.PUBLISHER.resource_id}-{publisher_id}" 289 | )["results"] 290 | return TypeAdapter(Publisher).validate_python(result) 291 | except ValidationError as err: 292 | raise ServiceError(err) from err 293 | 294 | def list_volumes( 295 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 296 | ) -> list[BasicVolume]: 297 | """Request a list of Volumes. 298 | 299 | Args: 300 | params: Parameters to add to the request. 301 | max_results: Limits the amount of results looked up and returned. 302 | 303 | Returns: 304 | A list of Volume objects. 305 | 306 | Raises: 307 | ServiceError: If there is an issue with validating the response. 308 | """ 309 | try: 310 | results = self._get_offset_request( 311 | endpoint="/volumes", params=params, max_results=max_results 312 | ) 313 | return TypeAdapter(list[BasicVolume]).validate_python(results) 314 | except ValidationError as err: 315 | raise ServiceError(err) from err 316 | 317 | def get_volume(self, volume_id: int) -> Volume: 318 | """Request a Volume using its id. 319 | 320 | Args: 321 | volume_id: The Volume id. 322 | 323 | Returns: 324 | A Volume object or None if not found. 325 | 326 | Raises: 327 | ServiceError: If there is an issue with validating the response. 328 | """ 329 | try: 330 | result = self._get_request( 331 | endpoint=f"/volume/{ComicvineResource.VOLUME.resource_id}-{volume_id}" 332 | )["results"] 333 | return TypeAdapter(Volume).validate_python(result) 334 | except ValidationError as err: 335 | raise ServiceError(err) from err 336 | 337 | def list_issues( 338 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 339 | ) -> list[BasicIssue]: 340 | """Request a list of Issues. 341 | 342 | Args: 343 | params: Parameters to add to the request. 344 | max_results: Limits the amount of results looked up and returned. 345 | 346 | Returns: 347 | A list of Issue objects. 348 | 349 | Raises: 350 | ServiceError: If there is an issue with validating the response. 351 | """ 352 | try: 353 | results = self._get_offset_request( 354 | endpoint="/issues", params=params, max_results=max_results 355 | ) 356 | return TypeAdapter(list[BasicIssue]).validate_python(results) 357 | except ValidationError as err: 358 | raise ServiceError(err) from err 359 | 360 | def get_issue(self, issue_id: int) -> Issue: 361 | """Request an Issue using its id. 362 | 363 | Args: 364 | issue_id: The Issue id. 365 | 366 | Returns: 367 | A Issue object or None if not found. 368 | 369 | Raises: 370 | ServiceError: If there is an issue with validating the response. 371 | """ 372 | try: 373 | result = self._get_request( 374 | endpoint=f"/issue/{ComicvineResource.ISSUE.resource_id}-{issue_id}" 375 | )["results"] 376 | return TypeAdapter(Issue).validate_python(result) 377 | except ValidationError as err: 378 | raise ServiceError(err) from err 379 | 380 | def list_story_arcs( 381 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 382 | ) -> list[BasicStoryArc]: 383 | """Request a list of Story Arcs. 384 | 385 | Args: 386 | params: Parameters to add to the request. 387 | max_results: Limits the amount of results looked up and returned. 388 | 389 | Returns: 390 | A list of StoryArc objects. 391 | 392 | Raises: 393 | ServiceError: If there is an issue with validating the response. 394 | """ 395 | try: 396 | results = self._get_offset_request( 397 | endpoint="/story_arcs", params=params, max_results=max_results 398 | ) 399 | return TypeAdapter(list[BasicStoryArc]).validate_python(results) 400 | except ValidationError as err: 401 | raise ServiceError(err) from err 402 | 403 | def get_story_arc(self, story_arc_id: int) -> StoryArc: 404 | """Request a Story Arc using its id. 405 | 406 | Args: 407 | story_arc_id: The StoryArc id. 408 | 409 | Returns: 410 | A StoryArc object or None if not found. 411 | 412 | Raises: 413 | ServiceError: If there is an issue with validating the response. 414 | """ 415 | try: 416 | result = self._get_request( 417 | endpoint=f"/story_arc/{ComicvineResource.STORY_ARC.resource_id}-{story_arc_id}" 418 | )["results"] 419 | return TypeAdapter(StoryArc).validate_python(result) 420 | except ValidationError as err: 421 | raise ServiceError(err) from err 422 | 423 | def list_creators( 424 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 425 | ) -> list[BasicCreator]: 426 | """Request a list of Creators. 427 | 428 | Args: 429 | params: Parameters to add to the request. 430 | max_results: Limits the amount of results looked up and returned. 431 | 432 | Returns: 433 | A list of Creator objects. 434 | 435 | Raises: 436 | ServiceError: If there is an issue with validating the response. 437 | """ 438 | try: 439 | results = self._get_offset_request( 440 | endpoint="/people", params=params, max_results=max_results 441 | ) 442 | return TypeAdapter(list[BasicCreator]).validate_python(results) 443 | except ValidationError as err: 444 | raise ServiceError(err) from err 445 | 446 | def get_creator(self, creator_id: int) -> Creator: 447 | """Request a Creator using its id. 448 | 449 | Args: 450 | creator_id: The Creator id. 451 | 452 | Returns: 453 | A Creator object or None if not found. 454 | 455 | Raises: 456 | ServiceError: If there is an issue with validating the response. 457 | """ 458 | try: 459 | result = self._get_request( 460 | endpoint=f"/person/{ComicvineResource.CREATOR.resource_id}-{creator_id}" 461 | )["results"] 462 | return TypeAdapter(Creator).validate_python(result) 463 | except ValidationError as err: 464 | raise ServiceError(err) from err 465 | 466 | def list_characters( 467 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 468 | ) -> list[BasicCharacter]: 469 | """Request a list of Characters. 470 | 471 | Args: 472 | params: Parameters to add to the request. 473 | max_results: Limits the amount of results looked up and returned. 474 | 475 | Returns: 476 | A list of Character objects. 477 | 478 | Raises: 479 | ServiceError: If there is an issue with validating the response. 480 | """ 481 | try: 482 | results = self._get_offset_request( 483 | endpoint="/characters", params=params, max_results=max_results 484 | ) 485 | return TypeAdapter(list[BasicCharacter]).validate_python(results) 486 | except ValidationError as err: 487 | raise ServiceError(err) from err 488 | 489 | def get_character(self, character_id: int) -> Character: 490 | """Request a Character using its id. 491 | 492 | Args: 493 | character_id: The Character id. 494 | 495 | Returns: 496 | A Character object or None if not found. 497 | 498 | Raises: 499 | ServiceError: If there is an issue with validating the response. 500 | """ 501 | try: 502 | result = self._get_request( 503 | endpoint=f"/character/{ComicvineResource.CHARACTER.resource_id}-{character_id}" 504 | )["results"] 505 | return TypeAdapter(Character).validate_python(result) 506 | except ValidationError as err: 507 | raise ServiceError(err) from err 508 | 509 | def list_teams( 510 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 511 | ) -> list[BasicTeam]: 512 | """Request a list of Teams. 513 | 514 | Args: 515 | params: Parameters to add to the request. 516 | max_results: Limits the amount of results looked up and returned. 517 | 518 | Returns: 519 | A list of Team objects. 520 | 521 | Raises: 522 | ServiceError: If there is an issue with validating the response. 523 | """ 524 | try: 525 | results = self._get_offset_request( 526 | endpoint="/teams", params=params, max_results=max_results 527 | ) 528 | return TypeAdapter(list[BasicTeam]).validate_python(results) 529 | except ValidationError as err: 530 | raise ServiceError(err) from err 531 | 532 | def get_team(self, team_id: int) -> Team: 533 | """Request a Team using its id. 534 | 535 | Args: 536 | team_id: The Team id. 537 | 538 | Returns: 539 | A Team object or None if not found. 540 | 541 | Raises: 542 | ServiceError: If there is an issue with validating the response. 543 | """ 544 | try: 545 | result = self._get_request( 546 | endpoint=f"/team/{ComicvineResource.TEAM.resource_id}-{team_id}" 547 | )["results"] 548 | return TypeAdapter(Team).validate_python(result) 549 | except ValidationError as err: 550 | raise ServiceError(err) from err 551 | 552 | def list_locations( 553 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 554 | ) -> list[BasicLocation]: 555 | """Request a list of Locations. 556 | 557 | Args: 558 | params: Parameters to add to the request. 559 | max_results: Limits the amount of results looked up and returned. 560 | 561 | Returns: 562 | A list of Location objects. 563 | 564 | Raises: 565 | ServiceError: If there is an issue with validating the response. 566 | """ 567 | try: 568 | results = self._get_offset_request( 569 | endpoint="/locations", params=params, max_results=max_results 570 | ) 571 | return TypeAdapter(list[BasicLocation]).validate_python(results) 572 | except ValidationError as err: 573 | raise ServiceError(err) from err 574 | 575 | def get_location(self, location_id: int) -> Location: 576 | """Request a Location using its id. 577 | 578 | Args: 579 | location_id: The Location id. 580 | 581 | Returns: 582 | A Location object or None if not found. 583 | 584 | Raises: 585 | ServiceError: If there is an issue with validating the response. 586 | """ 587 | try: 588 | result = self._get_request( 589 | endpoint=f"/location/{ComicvineResource.LOCATION.resource_id}-{location_id}" 590 | )["results"] 591 | return TypeAdapter(Location).validate_python(result) 592 | except ValidationError as err: 593 | raise ServiceError(err) from err 594 | 595 | def list_concepts( 596 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 597 | ) -> list[BasicConcept]: 598 | """Request a list of Concepts. 599 | 600 | Args: 601 | params: Parameters to add to the request. 602 | max_results: Limits the amount of results looked up and returned. 603 | 604 | Returns: 605 | A list of Concept objects. 606 | 607 | Raises: 608 | ServiceError: If there is an issue with validating the response. 609 | """ 610 | try: 611 | results = self._get_offset_request( 612 | endpoint="/concepts", params=params, max_results=max_results 613 | ) 614 | return TypeAdapter(list[BasicConcept]).validate_python(results) 615 | except ValidationError as err: 616 | raise ServiceError(err) from err 617 | 618 | def get_concept(self, concept_id: int) -> Concept: 619 | """Request a Concept using its id. 620 | 621 | Args: 622 | concept_id: The Concept id. 623 | 624 | Returns: 625 | A Concept object or None if not found. 626 | 627 | Raises: 628 | ServiceError: If there is an issue with validating the response. 629 | """ 630 | try: 631 | result = self._get_request( 632 | endpoint=f"/concept/{ComicvineResource.CONCEPT.resource_id}-{concept_id}" 633 | )["results"] 634 | return TypeAdapter(Concept).validate_python(result) 635 | except ValidationError as err: 636 | raise ServiceError(err) from err 637 | 638 | def list_powers( 639 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 640 | ) -> list[BasicPower]: 641 | """Request a list of Powers. 642 | 643 | Args: 644 | params: Parameters to add to the request. 645 | max_results: Limits the amount of results looked up and returned. 646 | 647 | Returns: 648 | A list of Power objects. 649 | 650 | Raises: 651 | ServiceError: If there is an issue with validating the response. 652 | """ 653 | try: 654 | results = self._get_offset_request( 655 | endpoint="/powers", params=params, max_results=max_results 656 | ) 657 | return TypeAdapter(list[BasicPower]).validate_python(results) 658 | except ValidationError as err: 659 | raise ServiceError(err) from err 660 | 661 | def get_power(self, power_id: int) -> Power: 662 | """Request a Power using its id. 663 | 664 | Args: 665 | power_id: The Power id. 666 | 667 | Returns: 668 | A Power object or None if not found. 669 | 670 | Raises: 671 | ServiceError: If there is an issue with validating the response. 672 | """ 673 | try: 674 | result = self._get_request( 675 | endpoint=f"/power/{ComicvineResource.POWER.resource_id}-{power_id}" 676 | )["results"] 677 | return TypeAdapter(Power).validate_python(result) 678 | except ValidationError as err: 679 | raise ServiceError(err) from err 680 | 681 | def list_origins( 682 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 683 | ) -> list[BasicOrigin]: 684 | """Request a list of Origins. 685 | 686 | Args: 687 | params: Parameters to add to the request. 688 | max_results: Limits the amount of results looked up and returned. 689 | 690 | Returns: 691 | A list of Origin objects. 692 | 693 | Raises: 694 | ServiceError: If there is an issue with validating the response. 695 | """ 696 | try: 697 | results = self._get_offset_request( 698 | endpoint="/origins", params=params, max_results=max_results 699 | ) 700 | return TypeAdapter(list[BasicOrigin]).validate_python(results) 701 | except ValidationError as err: 702 | raise ServiceError(err) from err 703 | 704 | def get_origin(self, origin_id: int) -> Origin: 705 | """Request an Origin using its id. 706 | 707 | Args: 708 | origin_id: The Origin id. 709 | 710 | Returns: 711 | An Origin object or None if not found. 712 | 713 | Raises: 714 | ServiceError: If there is an issue with validating the response. 715 | """ 716 | try: 717 | result = self._get_request( 718 | endpoint=f"/origin/{ComicvineResource.ORIGIN.resource_id}-{origin_id}" 719 | )["results"] 720 | return TypeAdapter(Origin).validate_python(result) 721 | except ValidationError as err: 722 | raise ServiceError(err) from err 723 | 724 | def list_items( 725 | self, params: Optional[dict[str, Any]] = None, max_results: int = 500 726 | ) -> list[BasicItem]: 727 | """Request a list of Items. 728 | 729 | Args: 730 | params: Parameters to add to the request. 731 | max_results: Limits the amount of results looked up and returned. 732 | 733 | Returns: 734 | A list of Item objects. 735 | 736 | Raises: 737 | ServiceError: If there is an issue with validating the response. 738 | """ 739 | try: 740 | results = self._get_offset_request( 741 | endpoint="/objects", params=params, max_results=max_results 742 | ) 743 | return TypeAdapter(list[BasicItem]).validate_python(results) 744 | except ValidationError as err: 745 | raise ServiceError(err) from err 746 | 747 | def get_item(self, item_id: int) -> Item: 748 | """Request an Item using its id. 749 | 750 | Args: 751 | item_id: The Item id. 752 | 753 | Returns: 754 | An Item object or None if not found. 755 | 756 | Raises: 757 | ServiceError: If there is an issue with validating the response. 758 | """ 759 | try: 760 | result = self._get_request( 761 | endpoint=f"/object/{ComicvineResource.ITEM.resource_id}-{item_id}" 762 | )["results"] 763 | return TypeAdapter(Item).validate_python(result) 764 | except ValidationError as err: 765 | raise ServiceError(err) from err 766 | 767 | def search( 768 | self, resource: ComicvineResource, query: str, max_results: int = 500 769 | ) -> Union[ 770 | list[BasicPublisher], 771 | list[BasicVolume], 772 | list[BasicIssue], 773 | list[BasicStoryArc], 774 | list[BasicCreator], 775 | list[BasicCharacter], 776 | list[BasicTeam], 777 | list[BasicLocation], 778 | list[BasicConcept], 779 | list[BasicPower], 780 | list[BasicOrigin], 781 | list[BasicItem], 782 | ]: 783 | """Request a list of search results filtered by provided resource. 784 | 785 | Args: 786 | resource: Filter which type of resource to return. 787 | query: Search query string. 788 | max_results: Limits the amount of results looked up and returned. 789 | 790 | Returns: 791 | A list of results, mapped to the given resource. 792 | 793 | Raises: 794 | ServiceError: If there is an issue with validating the response. 795 | """ 796 | try: 797 | results = self._get_paged_request( 798 | endpoint="/search", 799 | params={"query": query, "resources": resource.search_resource}, 800 | max_results=max_results, 801 | ) 802 | return TypeAdapter(resource.search_response).validate_python(results) 803 | except ValidationError as err: 804 | raise ServiceError(err) from err 805 | -------------------------------------------------------------------------------- /simyan/exceptions.py: -------------------------------------------------------------------------------- 1 | """The Exceptions module. 2 | 3 | This module provides the following classes: 4 | - AuthenticationError 5 | - ServiceError 6 | """ 7 | 8 | __all__ = ["AuthenticationError", "ServiceError"] 9 | 10 | 11 | class ServiceError(Exception): 12 | """Class for any API errors.""" 13 | 14 | 15 | class AuthenticationError(ServiceError): 16 | """Class for any authentication errors.""" 17 | -------------------------------------------------------------------------------- /simyan/schemas/__init__.py: -------------------------------------------------------------------------------- 1 | """simyan.schemas package entry file. 2 | 3 | This module provides the following classes: 4 | - BaseModel 5 | """ 6 | 7 | __all__ = ["BaseModel"] 8 | 9 | from pydantic import BaseModel as PydanticModel 10 | 11 | 12 | class BaseModel( 13 | PydanticModel, 14 | populate_by_name=True, 15 | str_strip_whitespace=True, 16 | validate_assignment=True, 17 | revalidate_instances="always", 18 | extra="ignore", 19 | ): 20 | """Base model for Simyan resources.""" 21 | -------------------------------------------------------------------------------- /simyan/schemas/character.py: -------------------------------------------------------------------------------- 1 | """The Character module. 2 | 3 | This module provides the following classes: 4 | - BasicCharacter 5 | - Character 6 | """ 7 | 8 | __all__ = ["BasicCharacter", "Character"] 9 | 10 | from datetime import date, datetime 11 | from typing import Any, Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry, GenericIssue, Images 17 | 18 | 19 | class BasicCharacter(BaseModel): 20 | r"""Contains fields for all Characters. 21 | 22 | Attributes: 23 | aliases: List of names used by the Character, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Character was added. 26 | date_last_updated: Date and time when the Character was last updated. 27 | date_of_birth: Date when the Character was born. 28 | description: Long description of the Character. 29 | first_issue: First issue the Character appeared in. 30 | gender: Character gender. 31 | id: Identifier used by Comicvine. 32 | image: Different sized images, posters and thumbnails for the Character. 33 | issue_count: Number of issues the Character appears in. 34 | name: Real name or public identity of Character. 35 | origin: The type of Character. 36 | publisher: The publisher of the Character. 37 | real_name: Name of the Character. 38 | site_url: Url to the resource in Comicvine. 39 | summary: Short description of the Character. 40 | """ 41 | 42 | aliases: Optional[str] = None 43 | api_url: HttpUrl = Field(alias="api_detail_url") 44 | date_added: datetime 45 | date_last_updated: datetime 46 | date_of_birth: Optional[date] = Field(alias="birth", default=None) 47 | description: Optional[str] = None 48 | first_issue: Optional[GenericIssue] = Field(alias="first_appeared_in_issue", default=None) 49 | gender: int 50 | id: int 51 | image: Images 52 | issue_count: int = Field(alias="count_of_issue_appearances") 53 | name: str 54 | origin: Optional[GenericEntry] = None 55 | publisher: Optional[GenericEntry] = None 56 | real_name: Optional[str] = None 57 | site_url: HttpUrl = Field(alias="site_detail_url") 58 | summary: Optional[str] = Field(alias="deck", default=None) 59 | 60 | def __init__(self, **data: Any): 61 | if data.get("birth"): 62 | data["birth"] = datetime.strptime(data["birth"], "%b %d, %Y").date() # noqa: DTZ007 63 | super().__init__(**data) 64 | 65 | 66 | class Character(BasicCharacter): 67 | r"""Extends BasicCharacter by including all the list references of a character. 68 | 69 | Attributes: 70 | creators: List of creators which worked on the Character. 71 | deaths: List of times when the Character has died. 72 | enemies: List of enemies the Character has. 73 | enemy_teams: List of enemy teams the Character has. 74 | friendly_teams: List of friendly teams the Character has. 75 | friends: List of friends the Character has. 76 | issues: List of issues the Character appears in. 77 | powers: List of powers the Character has. 78 | story_arcs: List of story arcs the Character appears in. 79 | teams: List of teams the Character appears in. 80 | volumes: List of volumes the Character appears in. 81 | """ 82 | 83 | creators: list[GenericEntry] = Field(default_factory=list) 84 | deaths: list[GenericEntry] = Field(alias="issues_died_in", default_factory=list) 85 | enemies: list[GenericEntry] = Field(alias="character_enemies", default_factory=list) 86 | enemy_teams: list[GenericEntry] = Field(alias="team_enemies", default_factory=list) 87 | friendly_teams: list[GenericEntry] = Field(alias="team_friends", default_factory=list) 88 | friends: list[GenericEntry] = Field(alias="character_friends", default_factory=list) 89 | issues: list[GenericEntry] = Field(alias="issue_credits", default_factory=list) 90 | powers: list[GenericEntry] = Field(default_factory=list) 91 | story_arcs: list[GenericEntry] = Field(alias="story_arc_credits", default_factory=list) 92 | teams: list[GenericEntry] = Field(default_factory=list) 93 | volumes: list[GenericEntry] = Field(alias="volume_credits", default_factory=list) 94 | -------------------------------------------------------------------------------- /simyan/schemas/concept.py: -------------------------------------------------------------------------------- 1 | """The Concept module. 2 | 3 | This module provides the following classes: 4 | - BasicConcept 5 | - Concept 6 | """ 7 | 8 | __all__ = ["BasicConcept", "Concept"] 9 | 10 | from datetime import datetime 11 | from typing import Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry, GenericIssue, Images 17 | 18 | 19 | class BasicConcept(BaseModel): 20 | r"""Contains fields for all Concepts. 21 | 22 | Attributes: 23 | aliases: List of names used by the Concept, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Concept was added. 26 | date_last_updated: Date and time when the Concept was last updated. 27 | description: Long description of the Concept. 28 | first_issue: First issue this concept appears. 29 | id: Identifier used by Comicvine. 30 | image: Different sized images, posters and thumbnails for the Concept. 31 | issue_count: Number of issues with the Concept. 32 | name: Name/Title of the Concept. 33 | site_url: Url to the resource in Comicvine. 34 | start_year: Year the Concept first appeared. 35 | summary: Short description of the Concept. 36 | """ 37 | 38 | aliases: Optional[str] = None 39 | api_url: HttpUrl = Field(alias="api_detail_url") 40 | date_added: datetime 41 | date_last_updated: datetime 42 | description: Optional[str] = None 43 | first_issue: Optional[GenericIssue] = Field(alias="first_appeared_in_issue", default=None) 44 | id: int 45 | image: Images 46 | issue_count: int = Field(alias="count_of_isssue_appearances") 47 | name: str 48 | site_url: HttpUrl = Field(alias="site_detail_url") 49 | start_year: Optional[int] = None 50 | summary: Optional[str] = Field(alias="deck", default=None) 51 | 52 | 53 | class Concept(BasicConcept): 54 | r"""Extends BasicConcept by including all the list references of a concept. 55 | 56 | Attributes: 57 | issues: List of issues the Concept appears. 58 | volumes: List of volumes the Concept appears. 59 | """ 60 | 61 | issues: list[GenericIssue] = Field(alias="issue_credits", default_factory=list) 62 | volumes: list[GenericEntry] = Field(alias="volume_credits", default_factory=list) 63 | -------------------------------------------------------------------------------- /simyan/schemas/creator.py: -------------------------------------------------------------------------------- 1 | """The Creator module. 2 | 3 | This module provides the following classes: 4 | - BasicCreator 5 | - Creator 6 | """ 7 | 8 | __all__ = ["BasicCreator", "Creator"] 9 | 10 | from datetime import date, datetime 11 | from typing import Any, Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry, Images 17 | 18 | 19 | class BasicCreator(BaseModel): 20 | r"""Contains fields for all Creators. 21 | 22 | Attributes: 23 | aliases: List of names used by the Creator, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | country: Country of origin. 26 | date_added: Date and time when the Creator was added. 27 | date_last_updated: Date and time when the Creator was last updated. 28 | date_of_birth: Date when the Creator was born. 29 | date_of_death: Date when the Creator died. 30 | description: Long description of the Creator. 31 | email: Email address of the Creator. 32 | gender: Creator gender. 33 | hometown: Hometown of the Creator. 34 | id: Identifier used by Comicvine. 35 | image: Different sized images, posters and thumbnails for the Creator. 36 | issue_count: Number of issues the Creator appears in. 37 | name: Name/Title of the Creator. 38 | site_url: Url to the resource in Comicvine. 39 | summary: Short description of the Creator. 40 | website: Url to the Creator's website. 41 | """ 42 | 43 | aliases: Optional[str] = None 44 | api_url: HttpUrl = Field(alias="api_detail_url") 45 | country: Optional[str] = None 46 | date_added: datetime 47 | date_last_updated: datetime 48 | date_of_birth: Optional[date] = Field(alias="birth", default=None) 49 | date_of_death: Optional[date] = Field(alias="death", default=None) 50 | description: Optional[str] = None 51 | email: Optional[str] = None 52 | gender: int 53 | hometown: Optional[str] = None 54 | id: int 55 | image: Images 56 | issue_count: Optional[int] = Field(alias="count_of_isssue_appearances", default=None) 57 | name: str 58 | site_url: HttpUrl = Field(alias="site_detail_url") 59 | summary: Optional[str] = Field(alias="deck", default=None) 60 | website: Optional[HttpUrl] = None 61 | 62 | def __init__(self, **data: Any): 63 | if data.get("death"): 64 | data["death"] = data["death"]["date"].split()[0] 65 | if data.get("birth"): 66 | data["birth"] = data["birth"].split()[0] 67 | super().__init__(**data) 68 | 69 | 70 | class Creator(BasicCreator): 71 | r"""Extends BasicCreator by including all the list references of a creator. 72 | 73 | Attributes: 74 | characters: List of characters the Creator has created. 75 | issues: List of issues the Creator appears in. 76 | story_arcs: List of story arcs the Creator appears in. 77 | volumes: List of volumes the Creator appears in. 78 | """ 79 | 80 | characters: list[GenericEntry] = Field(alias="created_characters", default_factory=list) 81 | issues: list[GenericEntry] = Field(default_factory=list) 82 | story_arcs: list[GenericEntry] = Field(alias="story_arc_credits", default_factory=list) 83 | volumes: list[GenericEntry] = Field(alias="volume_credits", default_factory=list) 84 | -------------------------------------------------------------------------------- /simyan/schemas/generic_entries.py: -------------------------------------------------------------------------------- 1 | """The GenericEntries module. 2 | 3 | This module provides the following classes: 4 | - AssociatedImage 5 | - GenericCount 6 | - GenericCreator 7 | - GenericEntry 8 | - GenericIssue 9 | - Images 10 | """ 11 | 12 | __all__ = [ 13 | "AssociatedImage", 14 | "GenericCount", 15 | "GenericCreator", 16 | "GenericEntry", 17 | "GenericIssue", 18 | "Images", 19 | ] 20 | 21 | from typing import Optional 22 | 23 | from pydantic import Field, HttpUrl 24 | 25 | from simyan.schemas import BaseModel 26 | 27 | 28 | class GenericEntry(BaseModel, extra="forbid"): 29 | """The GenericEntry object contains generic information. 30 | 31 | Attributes: 32 | api_url: Url to the resource in the Comicvine API. 33 | id: Identifier used by Comicvine. 34 | name: 35 | site_url: Url to the resource in Comicvine. 36 | """ 37 | 38 | api_url: HttpUrl = Field(alias="api_detail_url") 39 | id: int 40 | name: Optional[str] = None 41 | site_url: Optional[HttpUrl] = Field(default=None, alias="site_detail_url") 42 | 43 | 44 | class GenericCount(GenericEntry): 45 | r"""Extends GenericEntry by including attributes for tracking counts. 46 | 47 | Attributes: 48 | count: 49 | """ 50 | 51 | count: int 52 | 53 | 54 | class GenericIssue(GenericEntry): 55 | r"""Extends GenericEntry by including attributes of an Issue. 56 | 57 | Attributes: 58 | number: 59 | """ 60 | 61 | number: Optional[str] = Field(default=None, alias="issue_number") 62 | 63 | 64 | class GenericCreator(GenericEntry): 65 | r"""Extends GenericEntry by including attributes of a Creator. 66 | 67 | Attributes: 68 | roles: List of roles used by the Creator, collected in a string. 69 | """ 70 | 71 | roles: str = Field(alias="role") 72 | 73 | 74 | class Images(BaseModel, extra="forbid"): 75 | """The Images object contains image information. 76 | 77 | Attributes: 78 | icon_url: Url to an image at icon size. 79 | large_screen_url: Url to an image at large screen size. 80 | medium_url: Url to an image at medium size. 81 | original_url: Url to an image at original size. 82 | screen_url: Url to an image at screen size. 83 | small_url: Url to an image at small size. 84 | super_url: Url to an image at super size. 85 | thumbnail: Url to an image at thumbnail size. 86 | tiny_url: Url to an image at tiny size. 87 | tags: 88 | """ 89 | 90 | icon_url: HttpUrl 91 | large_screen_url: HttpUrl = Field(alias="screen_large_url") 92 | medium_url: HttpUrl 93 | original_url: HttpUrl 94 | screen_url: HttpUrl 95 | small_url: HttpUrl 96 | super_url: HttpUrl 97 | thumbnail: HttpUrl = Field(alias="thumb_url") 98 | tiny_url: HttpUrl 99 | tags: Optional[str] = Field(default=None, alias="image_tags") 100 | 101 | 102 | class AssociatedImage(BaseModel, extra="forbid"): 103 | """The AssociatedImage object contains image information. 104 | 105 | Attributes: 106 | url: Url to image. 107 | id: Identifier used by Comicvine. 108 | caption: Caption/description of the image. 109 | tags: 110 | """ 111 | 112 | url: HttpUrl = Field(alias="original_url") 113 | id: int 114 | caption: Optional[str] = None 115 | tags: Optional[str] = Field(default=None, alias="image_tags") 116 | -------------------------------------------------------------------------------- /simyan/schemas/issue.py: -------------------------------------------------------------------------------- 1 | """The Issue module. 2 | 3 | This module provides the following classes: 4 | - BasicIssue 5 | - Issue 6 | """ 7 | 8 | __all__ = ["BasicIssue", "Issue"] 9 | 10 | from datetime import date, datetime 11 | from typing import Optional, Union 12 | 13 | from pydantic import Field, HttpUrl, field_validator 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import AssociatedImage, GenericCreator, GenericEntry, Images 17 | 18 | 19 | class BasicIssue(BaseModel): 20 | r"""Contains fields for all Issues. 21 | 22 | Attributes: 23 | aliases: List of names used by the Issue, collected in a string. 24 | associated_images: List of different images associated with the Issue. 25 | api_url: Url to the resource in the Comicvine API. 26 | cover_date: Date on the cover of the Issue. 27 | date_added: Date and time when the Issue was added. 28 | date_last_updated: Date and time when the Issue was last updated. 29 | description: Long description of the Issue. 30 | id: Identifier used by Comicvine. 31 | image: Different sized images, posters and thumbnails for the Issue. 32 | name: Name/Title of the Issue. 33 | number: The Issue number. 34 | site_url: Url to the resource in Comicvine. 35 | store_date: Date the Issue went on sale on stores. 36 | summary: Short description of the Issue. 37 | volume: The volume the Issue is in. 38 | """ 39 | 40 | aliases: Optional[str] = None 41 | associated_images: list[AssociatedImage] = Field(default_factory=list) 42 | api_url: HttpUrl = Field(alias="api_detail_url") 43 | cover_date: Optional[date] = None 44 | date_added: datetime 45 | date_last_updated: datetime 46 | description: Optional[str] = None 47 | id: int 48 | image: Images 49 | name: Optional[str] = None 50 | number: Optional[str] = Field(alias="issue_number", default=None) 51 | site_url: HttpUrl = Field(alias="site_detail_url") 52 | store_date: Optional[date] = None 53 | summary: Optional[str] = Field(alias="deck", default=None) 54 | volume: GenericEntry 55 | 56 | 57 | class Issue(BasicIssue): 58 | r"""Extends BasicIssue by including all the list references of an issue. 59 | 60 | Attributes: 61 | characters: List of characters in the Issue. 62 | concepts: List of concepts in the Issue. 63 | creators: List of creators in the Issue. 64 | deaths: List of characters who died in the Issue. 65 | first_appearance_characters: List of characters who first appear in the Issue. 66 | first_appearance_concepts: List of concepts which first appear in the Issue. 67 | first_appearance_locations: List of locations which first appear in the Issue. 68 | first_appearance_objects: List of objects which first appear in the Issue. 69 | first_appearance_story_arcs: List of story arcs which first appear in the Issue. 70 | first_appearance_teams: List of teams who first appear in the Issue. 71 | locations: List of locations in the Issue. 72 | objects: List of objects in the Issue. 73 | story_arcs: List of story arcs in the Issue. 74 | teams: List of teams in the Issue. 75 | teams_disbanded: List of teams who disbanded in the Issue. 76 | """ 77 | 78 | characters: list[GenericEntry] = Field(alias="character_credits", default_factory=list) 79 | concepts: list[GenericEntry] = Field(alias="concept_credits", default_factory=list) 80 | creators: list[GenericCreator] = Field(alias="person_credits", default_factory=list) 81 | deaths: list[GenericEntry] = Field(alias="character_died_in", default_factory=list) 82 | first_appearance_characters: list[GenericEntry] = Field(default_factory=list) 83 | first_appearance_concepts: list[GenericEntry] = Field(default_factory=list) 84 | first_appearance_locations: list[GenericEntry] = Field(default_factory=list) 85 | first_appearance_objects: list[GenericEntry] = Field(default_factory=list) 86 | first_appearance_story_arcs: list[GenericEntry] = Field( 87 | alias="first_appearance_storyarcs", default_factory=list 88 | ) 89 | first_appearance_teams: list[GenericEntry] = Field(default_factory=list) 90 | locations: list[GenericEntry] = Field(alias="location_credits", default_factory=list) 91 | objects: list[GenericEntry] = Field(alias="object_credits", default_factory=list) 92 | story_arcs: list[GenericEntry] = Field(alias="story_arc_credits", default_factory=list) 93 | teams: list[GenericEntry] = Field(alias="team_credits", default_factory=list) 94 | teams_disbanded: list[GenericEntry] = Field(alias="team_disbanded_in", default_factory=list) 95 | 96 | @field_validator( 97 | "first_appearance_characters", 98 | "first_appearance_concepts", 99 | "first_appearance_locations", 100 | "first_appearance_objects", 101 | "first_appearance_story_arcs", 102 | "first_appearance_teams", 103 | mode="before", 104 | ) 105 | def handle_blank_list(cls, value: Union[str, list, None]) -> list: 106 | """Convert a blank or None value to an empty list. 107 | 108 | Args: 109 | value: The value to check. 110 | 111 | Returns: 112 | An empty list if the value is None or an empty string, otherwise the original list. 113 | """ 114 | return value or [] 115 | -------------------------------------------------------------------------------- /simyan/schemas/item.py: -------------------------------------------------------------------------------- 1 | """The Item module. 2 | 3 | This module provides the following classes: 4 | - BasicItem 5 | - Item 6 | """ 7 | 8 | __all__ = ["BasicItem", "Item"] 9 | 10 | from datetime import datetime 11 | from typing import Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry, GenericIssue, Images 17 | 18 | 19 | class BasicItem(BaseModel): 20 | r"""Contains fields for all Items. 21 | 22 | Attributes: 23 | aliases: List of names used by the Item, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Item was added. 26 | date_last_updated: Date and time when the Item was last updated. 27 | description: Long description of the Item. 28 | first_issue: First issue the Item appeared in. 29 | id: Identifier used by Comicvine. 30 | image: Different sized images, posters and thumbnails for the Item. 31 | issue_count: Number of issues the Item appears in. 32 | name: Name/Title of the Item. 33 | site_url: Url to the resource in Comicvine. 34 | start_year: The year the Item first appeared. 35 | summary: Short description of the Item. 36 | """ 37 | 38 | aliases: Optional[str] = None 39 | api_url: HttpUrl = Field(alias="api_detail_url") 40 | date_added: datetime 41 | date_last_updated: datetime 42 | description: Optional[str] = None 43 | first_issue: Optional[GenericIssue] = Field(alias="first_appeared_in_issue", default=None) 44 | id: int 45 | image: Images 46 | issue_count: int = Field(alias="count_of_issue_appearances") 47 | name: str 48 | site_url: HttpUrl = Field(alias="site_detail_url") 49 | start_year: Optional[int] = None 50 | summary: Optional[str] = Field(alias="deck", default=None) 51 | 52 | 53 | class Item(BasicItem): 54 | r"""Extends BasicItem by including all the list references of a item. 55 | 56 | Attributes: 57 | issues: List of issues the Item appears in. 58 | story_arcs: List of story arcs the Item appears in. 59 | volumes: List of volumes the Item appears in. 60 | """ 61 | 62 | issues: list[GenericEntry] = Field(alias="issue_credits", default_factory=list) 63 | story_arcs: list[GenericEntry] = Field(alias="story_arc_credits", default_factory=list) 64 | volumes: list[GenericEntry] = Field(alias="volume_credits", default_factory=list) 65 | -------------------------------------------------------------------------------- /simyan/schemas/location.py: -------------------------------------------------------------------------------- 1 | """The Location module. 2 | 3 | This module provides the following classes: 4 | - BasicLocation 5 | - Location 6 | """ 7 | 8 | __all__ = ["BasicLocation", "Location"] 9 | 10 | from datetime import datetime 11 | from typing import Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry, GenericIssue, Images 17 | 18 | 19 | class BasicLocation(BaseModel): 20 | r"""Contains fields for all Locations. 21 | 22 | Attributes: 23 | aliases: List of names used by the Location, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Location was added. 26 | date_last_updated: Date and time when the Location was last updated. 27 | description: Long description of the Location. 28 | first_issue: First issue the Location appeared in. 29 | id: Identifier used by Comicvine. 30 | image: Different sized images, posters and thumbnails for the Location. 31 | issue_count: Number of issues the Location appears in. 32 | name: Name/Title of the Location. 33 | site_url: Url to the resource in Comicvine. 34 | start_year: The year the Location was first used. 35 | summary: Short description of the Location. 36 | """ 37 | 38 | aliases: Optional[str] = None 39 | api_url: HttpUrl = Field(alias="api_detail_url") 40 | date_added: datetime 41 | date_last_updated: datetime 42 | description: Optional[str] = None 43 | first_issue: Optional[GenericIssue] = Field(alias="first_appeared_in_issue", default=None) 44 | id: int 45 | image: Images 46 | issue_count: Optional[int] = Field(alias="count_of_issue_appearances", default=None) 47 | name: str 48 | site_url: str = Field(alias="site_detail_url") 49 | start_year: Optional[int] = None 50 | summary: Optional[str] = Field(alias="deck", default=None) 51 | 52 | 53 | class Location(BasicLocation): 54 | r"""Extends BasicLocation by including all the list references of a location. 55 | 56 | Attributes: 57 | issues: List of issues the Location appears in. 58 | story_arcs: List of story arcs the Location appears in. 59 | volumes: List of volumes the Location appears in. 60 | """ 61 | 62 | issues: list[GenericIssue] = Field(alias="issue_credits", default_factory=list) 63 | story_arcs: list[GenericEntry] = Field(alias="story_arc_credits", default_factory=list) 64 | volumes: list[GenericEntry] = Field(alias="volume_credits", default_factory=list) 65 | -------------------------------------------------------------------------------- /simyan/schemas/origin.py: -------------------------------------------------------------------------------- 1 | """The Origin module. 2 | 3 | This module provides the following classes: 4 | - BasicOrigin 5 | - Origin 6 | """ 7 | 8 | __all__ = ["BasicOrigin", "Origin"] 9 | 10 | from typing import Optional 11 | 12 | from pydantic import Field, HttpUrl 13 | 14 | from simyan.schemas import BaseModel 15 | from simyan.schemas.generic_entries import GenericEntry 16 | 17 | 18 | class BasicOrigin(BaseModel): 19 | r"""Contains fields for all Origins. 20 | 21 | Attributes: 22 | api_url: Url to the resource in the Comicvine API. 23 | id: Identifier used by Comicvine. 24 | name: Name/Title of the Origin. 25 | site_url: Url to the resource in Comicvine. 26 | """ 27 | 28 | api_url: HttpUrl = Field(alias="api_detail_url") 29 | id: int 30 | name: str 31 | site_url: HttpUrl = Field(alias="site_detail_url") 32 | 33 | 34 | class Origin(BasicOrigin): 35 | r"""Extends BasicOrigin by including all the list references of a origin. 36 | 37 | Attributes: 38 | character_set: 39 | characters: List of characters with the Origin. 40 | profiles: 41 | """ 42 | 43 | character_set: Optional[int] = None 44 | characters: list[GenericEntry] = Field(default_factory=list) 45 | profiles: list[int] = Field(default_factory=list) 46 | -------------------------------------------------------------------------------- /simyan/schemas/power.py: -------------------------------------------------------------------------------- 1 | """The Power module. 2 | 3 | This module provides the following classes: 4 | - BasicPower 5 | - Power 6 | """ 7 | 8 | __all__ = ["BasicPower", "Power"] 9 | 10 | from datetime import datetime 11 | from typing import Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry 17 | 18 | 19 | class BasicPower(BaseModel): 20 | r"""Contains fields for all Powers. 21 | 22 | Attributes: 23 | aliases: List of names used by the Power, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Power was added. 26 | date_last_updated: Date and time when the Power was last updated. 27 | description: Long description of the Power. 28 | id: Identifier used by Comicvine. 29 | name: Name/Title of the Power. 30 | site_url: Url to the resource in Comicvine. 31 | """ 32 | 33 | aliases: Optional[str] = None 34 | api_url: HttpUrl = Field(alias="api_detail_url") 35 | date_added: datetime 36 | date_last_updated: datetime 37 | description: Optional[str] = None 38 | id: int 39 | name: str 40 | site_url: HttpUrl = Field(alias="site_detail_url") 41 | 42 | 43 | class Power(BasicPower): 44 | r"""Extends BasicPower by including all the list references of a power. 45 | 46 | Attributes: 47 | characters: List of characters with the Power. 48 | """ 49 | 50 | characters: list[GenericEntry] = Field(default_factory=list) 51 | -------------------------------------------------------------------------------- /simyan/schemas/publisher.py: -------------------------------------------------------------------------------- 1 | """The Publisher module. 2 | 3 | This module provides the following classes: 4 | - BasicPublisher 5 | - Publisher 6 | """ 7 | 8 | __all__ = ["BasicPublisher", "Publisher"] 9 | 10 | from datetime import datetime 11 | from typing import Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry, Images 17 | 18 | 19 | class BasicPublisher(BaseModel): 20 | r"""Contains fields for all Publishers. 21 | 22 | Attributes: 23 | aliases: List of names used by the Publisher, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Publisher was added. 26 | date_last_updated: Date and time when the Publisher was last updated. 27 | description: Long description of the Publisher. 28 | id: Identifier used by Comicvine. 29 | image: Different sized images, posters and thumbnails for the Publisher. 30 | location_address: Address the Publisher is located. 31 | location_city: City the Publisher is located. 32 | location_state: State the Publisher is located. 33 | name: Name/Title of the Publisher. 34 | site_url: Url to the resource in Comicvine. 35 | summary: Short description of the Publisher. 36 | """ 37 | 38 | aliases: Optional[str] = None 39 | api_url: HttpUrl = Field(alias="api_detail_url") 40 | date_added: datetime 41 | date_last_updated: datetime 42 | description: Optional[str] = None 43 | id: int 44 | image: Images 45 | location_address: Optional[str] = None 46 | location_city: Optional[str] = None 47 | location_state: Optional[str] = None 48 | name: str 49 | site_url: HttpUrl = Field(alias="site_detail_url") 50 | summary: Optional[str] = Field(alias="deck", default=None) 51 | 52 | 53 | class Publisher(BasicPublisher): 54 | r"""Extends BasicPublisher by including all the list references of a publisher. 55 | 56 | Attributes: 57 | characters: List of characters the Publisher created. 58 | story_arcs: List of story arcs the Publisher created. 59 | teams: List of teams the Publisher created. 60 | volumes: List of volumes the Publisher created. 61 | """ 62 | 63 | characters: list[GenericEntry] = Field(default_factory=list) 64 | story_arcs: list[GenericEntry] = Field(default_factory=list) 65 | teams: list[GenericEntry] = Field(default_factory=list) 66 | volumes: list[GenericEntry] = Field(default_factory=list) 67 | -------------------------------------------------------------------------------- /simyan/schemas/story_arc.py: -------------------------------------------------------------------------------- 1 | """The StoryArc module. 2 | 3 | This module provides the following classes: 4 | - BasicStoryArc 5 | - StoryArc 6 | """ 7 | 8 | __all__ = ["BasicStoryArc", "StoryArc"] 9 | 10 | from datetime import datetime 11 | from typing import Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry, GenericIssue, Images 17 | 18 | 19 | class BasicStoryArc(BaseModel): 20 | r"""Contains fields for all Story Arcs. 21 | 22 | Attributes: 23 | aliases: List of names used by the Story Arc, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Story Arc was added. 26 | date_last_updated: Date and time when the Story Arc was last updated. 27 | description: Long description of the Story Arc. 28 | first_issue: First issue of the Story Arc. 29 | id: Identifier used by Comicvine. 30 | image: Different sized images, posters and thumbnails for the Story Arc. 31 | issue_count: Number of issues in the Story Arc. 32 | name: Name/Title of the Story Arc. 33 | publisher: The publisher of the Story Arc. 34 | site_url: Url to the resource in Comicvine. 35 | summary: Short description of the Story Arc. 36 | """ 37 | 38 | aliases: Optional[str] = None 39 | api_url: HttpUrl = Field(alias="api_detail_url") 40 | date_added: datetime 41 | date_last_updated: datetime 42 | description: Optional[str] = None 43 | first_issue: Optional[GenericIssue] = Field(alias="first_appeared_in_issue", default=None) 44 | id: int 45 | image: Images 46 | issue_count: int = Field(alias="count_of_isssue_appearances") 47 | name: str 48 | publisher: Optional[GenericEntry] = None 49 | site_url: HttpUrl = Field(alias="site_detail_url") 50 | summary: Optional[str] = Field(alias="deck", default=None) 51 | 52 | 53 | class StoryArc(BasicStoryArc): 54 | r"""Extends BasicStoryArc by including all the list references of a story arc. 55 | 56 | Attributes: 57 | issues: List of issues in the Story Arc. 58 | """ 59 | 60 | issues: list[GenericEntry] = Field(default_factory=list) 61 | -------------------------------------------------------------------------------- /simyan/schemas/team.py: -------------------------------------------------------------------------------- 1 | """The Team module. 2 | 3 | This module provides the following classes: 4 | - BasicTeam 5 | - Team 6 | """ 7 | 8 | __all__ = ["BasicTeam", "Team"] 9 | 10 | from datetime import datetime 11 | from typing import Optional 12 | 13 | from pydantic import Field, HttpUrl 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericEntry, GenericIssue, Images 17 | 18 | 19 | class BasicTeam(BaseModel): 20 | r"""Contains fields for all Teams. 21 | 22 | Attributes: 23 | aliases: List of names used by the Team, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Team was added. 26 | date_last_updated: Date and time when the Team was last updated. 27 | description: Long description of the Team. 28 | first_issue: First issue the Team appeared in. 29 | id: Identifier used by Comicvine. 30 | image: Different sized images, posters and thumbnails for the Team. 31 | issue_count: Number of issues the Team appears in. 32 | member_count: Number of members in the Team. 33 | name: Name/Title of the Team. 34 | publisher: The publisher of the Team. 35 | site_url: Url to the resource in Comicvine. 36 | summary: Short description of the Team. 37 | """ 38 | 39 | aliases: Optional[str] = None 40 | api_url: HttpUrl = Field(alias="api_detail_url") 41 | date_added: datetime 42 | date_last_updated: datetime 43 | description: Optional[str] = None 44 | first_issue: Optional[GenericIssue] = Field(alias="first_appeared_in_issue", default=None) 45 | id: int 46 | image: Images 47 | issue_count: int = Field(alias="count_of_isssue_appearances") 48 | member_count: int = Field(alias="count_of_team_members") 49 | name: str 50 | publisher: Optional[GenericEntry] = None 51 | site_url: HttpUrl = Field(alias="site_detail_url") 52 | summary: Optional[str] = Field(alias="deck", default=None) 53 | 54 | 55 | class Team(BasicTeam): 56 | r"""Extends BasicTeam by including all the list references of a team. 57 | 58 | Attributes: 59 | enemies: List of enemies of the Team. 60 | friends: List of friends of the Team. 61 | issues: List of issues the Team appears in. 62 | issues_disbanded_in: List of issues the Team disbanded in. 63 | members: List of members in the Team. 64 | story_arcs: List of story arcs the Team appears in. 65 | volumes: List of volumes the Team appears in. 66 | """ 67 | 68 | enemies: list[GenericEntry] = Field(alias="character_enemies", default_factory=list) 69 | friends: list[GenericEntry] = Field(alias="character_friends", default_factory=list) 70 | issues: list[GenericEntry] = Field(alias="issue_credits", default_factory=list) 71 | issues_disbanded_in: list[GenericEntry] = Field( 72 | alias="disbanded_in_issues", default_factory=list 73 | ) 74 | members: list[GenericEntry] = Field(alias="characters", default_factory=list) 75 | story_arcs: list[GenericEntry] = Field(alias="story_arc_credits", default_factory=list) 76 | volumes: list[GenericEntry] = Field(alias="volume_credits", default_factory=list) 77 | -------------------------------------------------------------------------------- /simyan/schemas/volume.py: -------------------------------------------------------------------------------- 1 | """The Volume module. 2 | 3 | This module provides the following classes: 4 | - BasicVolume 5 | - Volume 6 | """ 7 | 8 | __all__ = ["BasicVolume", "Volume"] 9 | 10 | from datetime import datetime 11 | from typing import Optional 12 | 13 | from pydantic import Field, HttpUrl, field_validator 14 | 15 | from simyan.schemas import BaseModel 16 | from simyan.schemas.generic_entries import GenericCount, GenericEntry, GenericIssue, Images 17 | 18 | 19 | class BasicVolume(BaseModel): 20 | r"""Contains fields for all Volumes. 21 | 22 | Attributes: 23 | aliases: List of names used by the Volume, collected in a string. 24 | api_url: Url to the resource in the Comicvine API. 25 | date_added: Date and time when the Volume was added. 26 | date_last_updated: Date and time when the Volume was last updated. 27 | description: Long description of the Volume. 28 | first_issue: First issue of the Volume. 29 | id: Identifier used by Comicvine. 30 | image: Different sized images, posters and thumbnails for the Volume. 31 | issue_count: Number of issues in the Volume. 32 | last_issue: Last issue of the Volume. 33 | name: Name/Title of the Volume. 34 | publisher: The publisher of the Volume. 35 | site_url: Url to the resource in Comicvine. 36 | start_year: The year the Volume started. 37 | summary: Short description of the Volume. 38 | """ 39 | 40 | aliases: Optional[str] = None 41 | api_url: HttpUrl = Field(alias="api_detail_url") 42 | date_added: datetime 43 | date_last_updated: datetime 44 | description: Optional[str] = None 45 | first_issue: Optional[GenericIssue] = None 46 | id: int 47 | image: Images 48 | issue_count: int = Field(alias="count_of_issues") 49 | last_issue: Optional[GenericIssue] = None 50 | name: str 51 | publisher: Optional[GenericEntry] = None 52 | site_url: HttpUrl = Field(alias="site_detail_url") 53 | start_year: Optional[int] = None 54 | summary: Optional[str] = Field(alias="deck", default=None) 55 | 56 | @field_validator("start_year", mode="before") 57 | def validate_start_year(cls, value: str) -> Optional[int]: 58 | """Convert start_year to int or None. 59 | 60 | Args: 61 | value: String value of the start_year 62 | 63 | Returns: 64 | int or None version of the start_year 65 | """ 66 | if value: 67 | try: 68 | return int(value) 69 | except ValueError: 70 | return None 71 | return None 72 | 73 | 74 | class Volume(BasicVolume): 75 | r"""Extends BasicVolume by including all the list references of a volume. 76 | 77 | Attributes: 78 | characters: List of characters in the Volume. 79 | concepts: List of concepts in the Volume. 80 | creators: List of creators in the Volume. 81 | issues: List of issues in the Volume. 82 | locations: List of locations in the Volume. 83 | objects: List of objects in the Volume. 84 | """ 85 | 86 | characters: list[GenericCount] = Field(default_factory=list) 87 | concepts: list[GenericCount] = Field(default_factory=list) 88 | creators: list[GenericCount] = Field(alias="people", default_factory=list) 89 | issues: list[GenericIssue] = Field(default_factory=list) 90 | locations: list[GenericCount] = Field(default_factory=list) 91 | objects: list[GenericCount] = Field(default_factory=list) 92 | -------------------------------------------------------------------------------- /simyan/sqlite_cache.py: -------------------------------------------------------------------------------- 1 | """The SQLiteCache module. 2 | 3 | This module provides the following classes: 4 | - SQLiteCache 5 | """ 6 | 7 | __all__ = ["SQLiteCache"] 8 | import json 9 | import sqlite3 10 | from datetime import datetime, timedelta, timezone 11 | from pathlib import Path 12 | from typing import Any, Optional 13 | 14 | from simyan import get_cache_root 15 | 16 | 17 | class SQLiteCache: 18 | """The SQLiteCache object to cache search results from Comicvine. 19 | 20 | Args: 21 | path: Path to database. 22 | expiry: How long to keep cache results. 23 | """ 24 | 25 | def __init__(self, path: Optional[Path] = None, expiry: Optional[int] = 14): 26 | self.expiry = expiry 27 | self.connection = sqlite3.connect(path or get_cache_root() / "cache.sqlite") 28 | self.connection.row_factory = sqlite3.Row 29 | 30 | self.connection.execute("CREATE TABLE IF NOT EXISTS queries (query, response, query_date);") 31 | self.cleanup() 32 | 33 | def select(self, query: str) -> dict[str, Any]: 34 | """Retrieve data from the cache database. 35 | 36 | Args: 37 | query: Url string used as key. 38 | 39 | Returns: 40 | Empty dict or select results. 41 | """ 42 | if self.expiry: 43 | expiry = datetime.now(tz=timezone.utc).astimezone().date() - timedelta(days=self.expiry) 44 | cursor = self.connection.execute( 45 | "SELECT * FROM queries WHERE query = ? and query_date > ?;", 46 | (query, expiry.isoformat()), 47 | ) 48 | else: 49 | cursor = self.connection.execute("SELECT * FROM queries WHERE query = ?;", (query,)) 50 | if results := cursor.fetchone(): 51 | return json.loads(results["response"]) 52 | return {} 53 | 54 | def insert(self, query: str, response: dict[str, Any]) -> None: 55 | """Insert data into the cache database. 56 | 57 | Args: 58 | query: Url string used as key. 59 | response: Response dict from url. 60 | """ 61 | self.connection.execute( 62 | "INSERT INTO queries (query, response, query_date) VALUES (?, ?, ?);", 63 | ( 64 | query, 65 | json.dumps(response), 66 | datetime.now(tz=timezone.utc).astimezone().date().isoformat(), 67 | ), 68 | ) 69 | self.connection.commit() 70 | 71 | def delete(self, query: str) -> None: 72 | """Remove entry from the cache with the provided url. 73 | 74 | Args: 75 | query: Url string used as key. 76 | """ 77 | self.connection.execute("DELETE FROM queries WHERE query = ?;", (query,)) 78 | self.connection.commit() 79 | 80 | def cleanup(self) -> None: 81 | """Remove all expired entries from the cache database.""" 82 | if not self.expiry: 83 | return 84 | expiry = datetime.now(tz=timezone.utc).astimezone().date() - timedelta(days=self.expiry) 85 | self.connection.execute("DELETE FROM queries WHERE query_date < ?;", (expiry.isoformat(),)) 86 | self.connection.commit() 87 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Testing 2 | 3 | These tests use the Simyan requests caching for mocking tests, so tests will run quickly and not require credentials. 4 | 5 | If your code adds a new URL to the cache, set the `COMICVINE__API_KEY` environment variable before running the test, and 6 | it will be populated in the `tests/cache.sqlite` database. 7 | 8 | At any point you should be able to delete the database, set any credentials, and run the full test suite to repopulate 9 | it *(though some results might be different if any of the data has changed at Comic Vine)*. 10 | -------------------------------------------------------------------------------- /tests/__init__.py: -------------------------------------------------------------------------------- 1 | """Tests for Simyan.""" 2 | -------------------------------------------------------------------------------- /tests/cache.sqlite: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Metron-Project/Simyan/92050acb36eace59419a98a86f74c87f55f53034/tests/cache.sqlite -------------------------------------------------------------------------------- /tests/characters_test.py: -------------------------------------------------------------------------------- 1 | """The Characters test module. 2 | 3 | This module contains tests for Character and BasicCharacter objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.character import BasicCharacter 13 | 14 | 15 | def test_get_character(session: Comicvine) -> None: 16 | """Test the get_character function with a valid id.""" 17 | result = session.get_character(character_id=40431) 18 | assert result is not None 19 | assert result.id == 40431 20 | 21 | assert len(result.creators) == 2 22 | assert len(result.deaths) == 2 23 | assert len(result.enemies) == 150 24 | assert len(result.enemy_teams) == 25 25 | assert len(result.friendly_teams) == 17 26 | assert len(result.friends) == 233 27 | assert len(result.issues) == 1714 28 | assert len(result.powers) == 28 29 | assert len(result.story_arcs) == 0 30 | assert len(result.teams) == 21 31 | assert len(result.volumes) == 1 32 | 33 | 34 | def test_get_character_fail(session: Comicvine) -> None: 35 | """Test the get_character function with an invalid id.""" 36 | with pytest.raises(ServiceError): 37 | session.get_character(character_id=-1) 38 | 39 | 40 | def test_list_characters(session: Comicvine) -> None: 41 | """Test the list_characters function with a valid search.""" 42 | search_results = session.list_characters({"filter": "name:Kyle Rayner"}) 43 | assert len(search_results) != 0 44 | result = next(x for x in search_results if x.id == 40431) 45 | assert result is not None 46 | 47 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/character/4005-40431/" 48 | assert result.date_added == datetime(2008, 6, 6, 11, 27, 42) 49 | assert result.date_of_birth is None 50 | assert result.first_issue.id == 38445 51 | assert result.gender == 1 52 | assert result.issue_count == 1714 53 | assert result.name == "Kyle Rayner" 54 | assert result.origin.id == 4 55 | assert result.publisher.id == 10 56 | assert result.real_name == "Kyle Rayner" 57 | assert str(result.site_url) == "https://comicvine.gamespot.com/kyle-rayner/4005-40431/" 58 | 59 | 60 | def test_list_characters_empty(session: Comicvine) -> None: 61 | """Test the list_characters function with an invalid search.""" 62 | results = session.list_characters({"filter": "name:INVALID"}) 63 | assert len(results) == 0 64 | 65 | 66 | def test_list_characters_max_results(session: Comicvine) -> None: 67 | """Test the list_characters function with max_results.""" 68 | results = session.list_characters(max_results=10) 69 | assert len(results) == 10 70 | 71 | 72 | def test_search_character(session: Comicvine) -> None: 73 | """Test the search function for a list of Characters.""" 74 | results = session.search(resource=ComicvineResource.CHARACTER, query="Kyle Rayner") 75 | assert all(isinstance(x, BasicCharacter) for x in results) 76 | -------------------------------------------------------------------------------- /tests/concepts_test.py: -------------------------------------------------------------------------------- 1 | """The Concepts test module. 2 | 3 | This module contains tests for Concept and BasicConcept objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.concept import BasicConcept 13 | 14 | 15 | def test_get_concept(session: Comicvine) -> None: 16 | """Test the get_concept function with a valid id.""" 17 | result = session.get_concept(concept_id=41148) 18 | assert result is not None 19 | assert result.id == 41148 20 | 21 | assert len(result.issues) == 2589 22 | assert len(result.volumes) == 1 23 | 24 | 25 | def test_get_concept_fail(session: Comicvine) -> None: 26 | """Test the get_concept function with an invalid id.""" 27 | with pytest.raises(ServiceError): 28 | session.get_concept(concept_id=-1) 29 | 30 | 31 | def test_list_concepts(session: Comicvine) -> None: 32 | """Test the list_concepts function with a valid search.""" 33 | search_results = session.list_concepts({"filter": "name:Green Lantern"}) 34 | assert len(search_results) != 0 35 | result = next(x for x in search_results if x.id == 41148) 36 | assert result is not None 37 | 38 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/concept/4015-41148/" 39 | assert result.date_added == datetime(2008, 6, 6, 11, 27, 52) 40 | assert result.first_issue.id == 144069 41 | assert result.issue_count == 2589 42 | assert result.name == "Green Lantern" 43 | assert str(result.site_url) == "https://comicvine.gamespot.com/green-lantern/4015-41148/" 44 | assert result.start_year == 1940 45 | 46 | 47 | def test_list_concepts_empty(session: Comicvine) -> None: 48 | """Test the list_concepts function with an invalid search.""" 49 | results = session.list_concepts({"filter": "name:INVALID"}) 50 | assert len(results) == 0 51 | 52 | 53 | def test_list_concepts_max_results(session: Comicvine) -> None: 54 | """Test the list_concepts function with max_results.""" 55 | results = session.list_concepts(max_results=10) 56 | assert len(results) == 10 57 | 58 | 59 | def test_search_concept(session: Comicvine) -> None: 60 | """Test the search function for a list of Concepts.""" 61 | results = session.search(resource=ComicvineResource.CONCEPT, query="earth") 62 | assert all(isinstance(x, BasicConcept) for x in results) 63 | -------------------------------------------------------------------------------- /tests/conftest.py: -------------------------------------------------------------------------------- 1 | """The Conftest module. 2 | 3 | This module contains pytest fixtures. 4 | """ 5 | 6 | import os 7 | from pathlib import Path 8 | 9 | import pytest 10 | 11 | from simyan.comicvine import Comicvine 12 | from simyan.sqlite_cache import SQLiteCache 13 | 14 | 15 | @pytest.fixture(scope="session") 16 | def comicvine_api_key() -> str: 17 | """Set the Comicvine API key fixture.""" 18 | return os.getenv("COMICVINE__API_KEY", default="IGNORED") 19 | 20 | 21 | @pytest.fixture(scope="session") 22 | def session(comicvine_api_key: str) -> Comicvine: 23 | """Set the Simyan session fixture.""" 24 | return Comicvine( 25 | api_key=comicvine_api_key, cache=SQLiteCache(path=Path("tests/cache.sqlite"), expiry=None) 26 | ) 27 | -------------------------------------------------------------------------------- /tests/creators_test.py: -------------------------------------------------------------------------------- 1 | """The Creators test module. 2 | 3 | This module contains tests for Creator and BasicCreator objects. 4 | """ 5 | 6 | from datetime import date, datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.creator import BasicCreator 13 | 14 | 15 | def test_get_creator(session: Comicvine) -> None: 16 | """Test the get_creator function with a valid id.""" 17 | result = session.get_creator(creator_id=40439) 18 | assert result is not None 19 | assert result.id == 40439 20 | 21 | assert len(result.characters) == 309 22 | assert len(result.issues) == 1608 23 | assert len(result.story_arcs) == 23 24 | assert len(result.volumes) == 595 25 | 26 | 27 | def test_get_creator_fail(session: Comicvine) -> None: 28 | """Test the get_creator function with an invalid id.""" 29 | with pytest.raises(ServiceError): 30 | session.get_creator(creator_id=-1) 31 | 32 | 33 | def test_list_creators(session: Comicvine) -> None: 34 | """Test the list_creators function with a valid search.""" 35 | search_results = session.list_creators({"filter": "name:Geoff Johns"}) 36 | assert len(search_results) != 0 37 | result = next(x for x in search_results if x.id == 40439) 38 | assert result is not None 39 | 40 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/person/4040-40439/" 41 | assert result.country == "United States" 42 | assert result.date_added == datetime(2008, 6, 6, 11, 28, 14) 43 | assert result.date_of_birth == date(1973, 1, 25) 44 | assert result.date_of_death is None 45 | assert result.email is None 46 | assert result.gender == 1 47 | assert result.hometown == "Detroit, MI" 48 | assert result.issue_count is None 49 | assert result.name == "Geoff Johns" 50 | assert str(result.site_url) == "https://comicvine.gamespot.com/geoff-johns/4040-40439/" 51 | assert str(result.website) == "http://www.geoffjohns.com/" 52 | 53 | 54 | def test_list_creators_empty(session: Comicvine) -> None: 55 | """Test the list_creators function with an invalid search.""" 56 | results = session.list_creators({"filter": "name:INVALID"}) 57 | assert len(results) == 0 58 | 59 | 60 | def test_list_creators_max_results(session: Comicvine) -> None: 61 | """Test the list_creators function with max_results.""" 62 | results = session.list_creators(max_results=10) 63 | assert len(results) == 10 64 | 65 | 66 | def test_search_creator(session: Comicvine) -> None: 67 | """Test the search function for a list of Creators.""" 68 | results = session.search(resource=ComicvineResource.CREATOR, query="Geoff") 69 | assert all(isinstance(x, BasicCreator) for x in results) 70 | -------------------------------------------------------------------------------- /tests/exceptions_test.py: -------------------------------------------------------------------------------- 1 | """The Exceptions test module. 2 | 3 | This module contains tests for Exceptions. 4 | """ 5 | 6 | import pytest 7 | 8 | from simyan.comicvine import Comicvine 9 | from simyan.exceptions import AuthenticationError, ServiceError 10 | 11 | 12 | def test_unauthorized() -> None: 13 | """Test generating an AuthenticationError.""" 14 | session = Comicvine(api_key="Invalid", cache=None) 15 | with pytest.raises(AuthenticationError): 16 | session.get_publisher(publisher_id=1) 17 | 18 | 19 | def test_not_found(session: Comicvine) -> None: 20 | """Test a 404 Not Found raises a ServiceError.""" 21 | with pytest.raises(ServiceError): 22 | session._get_request(endpoint="/invalid") # noqa: SLF001 23 | 24 | 25 | def test_timeout(comicvine_api_key: str) -> None: 26 | """Test a TimeoutError for slow responses.""" 27 | session = Comicvine(api_key=comicvine_api_key, timeout=1, cache=None) 28 | with pytest.raises(ServiceError): 29 | session.get_publisher(publisher_id=1) 30 | -------------------------------------------------------------------------------- /tests/issues_test.py: -------------------------------------------------------------------------------- 1 | """The Issues test module. 2 | 3 | This module contains tests for Issue and BasicIssue objects. 4 | """ 5 | 6 | from datetime import date, datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.issue import BasicIssue 13 | 14 | 15 | def test_get_issue(session: Comicvine) -> None: 16 | """Test the get_issue function with a valid id.""" 17 | result = session.get_issue(issue_id=111265) 18 | assert result is not None 19 | assert result.id == 111265 20 | 21 | assert len(result.characters) == 7 22 | assert len(result.concepts) == 1 23 | assert len(result.creators) == 10 24 | assert len(result.deaths) == 0 25 | assert len(result.first_appearance_characters) == 0 26 | assert len(result.first_appearance_concepts) == 0 27 | assert len(result.first_appearance_locations) == 0 28 | assert len(result.first_appearance_objects) == 0 29 | assert len(result.first_appearance_story_arcs) == 0 30 | assert len(result.first_appearance_teams) == 0 31 | assert len(result.locations) == 4 32 | assert len(result.objects) == 1 33 | assert len(result.story_arcs) == 1 34 | assert len(result.teams) == 2 35 | assert len(result.teams_disbanded) == 0 36 | 37 | 38 | def test_get_issue_fail(session: Comicvine) -> None: 39 | """Test the get_issue function with an invalid id.""" 40 | with pytest.raises(ServiceError): 41 | session.get_issue(issue_id=-1) 42 | 43 | 44 | def test_list_issues(session: Comicvine) -> None: 45 | """Test the list_issues function with a valid search.""" 46 | search_results = session.list_issues({"filter": "volume:18216,issue_number:1"}) 47 | assert len(search_results) != 0 48 | result = next(x for x in search_results if x.id == 111265) 49 | assert result is not None 50 | 51 | assert len(result.associated_images) == 1 52 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/issue/4000-111265/" 53 | assert result.cover_date == date(2005, 7, 1) 54 | assert result.date_added == datetime(2008, 6, 6, 11, 21, 45) 55 | assert result.name == "Airborne" 56 | assert result.number == "1" 57 | assert ( 58 | str(result.site_url) 59 | == "https://comicvine.gamespot.com/green-lantern-1-airborne/4000-111265/" 60 | ) 61 | assert result.store_date == date(2005, 5, 25) 62 | assert result.volume.id == 18216 63 | 64 | 65 | def test_list_issues_empty(session: Comicvine) -> None: 66 | """Test the list_issues function with an invalid search.""" 67 | results = session.list_issues({"filter": "name:INVALID"}) 68 | assert len(results) == 0 69 | 70 | 71 | def test_list_issues_max_results(session: Comicvine) -> None: 72 | """Test the list_issues function with max_results.""" 73 | results = session.list_issues(max_results=10) 74 | assert len(results) == 10 75 | 76 | 77 | def test_search_issue(session: Comicvine) -> None: 78 | """Test the search function for a list of Issues.""" 79 | results = session.search(resource=ComicvineResource.ISSUE, query="Lantern") 80 | assert all(isinstance(x, BasicIssue) for x in results) 81 | -------------------------------------------------------------------------------- /tests/items_test.py: -------------------------------------------------------------------------------- 1 | """The Items test module. 2 | 3 | This module contains tests for Item and BasicItem objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.item import BasicItem 13 | 14 | 15 | def test_get_item(session: Comicvine) -> None: 16 | """Test the get_item function with a valid id.""" 17 | result = session.get_item(item_id=41361) 18 | assert result is not None 19 | assert result.id == 41361 20 | 21 | assert len(result.issues) == 3308 22 | assert len(result.story_arcs) == 454 23 | assert len(result.volumes) == 993 24 | 25 | 26 | def test_get_item_fail(session: Comicvine) -> None: 27 | """Test the get_item function with an invalid id.""" 28 | with pytest.raises(ServiceError): 29 | session.get_item(item_id=-1) 30 | 31 | 32 | def test_list_items(session: Comicvine) -> None: 33 | """Test the list_items function with a valid search query.""" 34 | search_results = session.list_items({"filter": "name:Green Power Ring"}) 35 | assert len(search_results) != 0 36 | result = next(x for x in search_results if x.id == 41361) 37 | assert result is not None 38 | 39 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/object/4055-41361/" 40 | assert result.date_added == datetime(2008, 6, 6, 11, 27, 50) 41 | assert result.first_issue.id == 123898 42 | assert result.issue_count == 3308 43 | assert result.name == "Green Power Ring" 44 | assert str(result.site_url) == "https://comicvine.gamespot.com/green-power-ring/4055-41361/" 45 | assert result.start_year == 1940 46 | 47 | 48 | def test_list_items_empty(session: Comicvine) -> None: 49 | """Test the list_items function with an invalid search query.""" 50 | results = session.list_items({"filter": "name:INVALID"}) 51 | assert len(results) == 0 52 | 53 | 54 | def test_list_items_max_results(session: Comicvine) -> None: 55 | """Test the list_items function with max results.""" 56 | results = session.list_items(max_results=10) 57 | assert len(results) == 10 58 | 59 | 60 | def test_search_item(session: Comicvine) -> None: 61 | """Test the search function for a list of Items.""" 62 | results = session.search(resource=ComicvineResource.ITEM, query="Ring") 63 | assert all(isinstance(x, BasicItem) for x in results) 64 | -------------------------------------------------------------------------------- /tests/locations_test.py: -------------------------------------------------------------------------------- 1 | """The Locations test module. 2 | 3 | This module contains tests for Location and BasicLocation objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.location import BasicLocation 13 | 14 | 15 | def test_get_location(session: Comicvine) -> None: 16 | """Test the get_location function with a valid id.""" 17 | result = session.get_location(location_id=56000) 18 | assert result is not None 19 | assert result.id == 56000 20 | 21 | assert len(result.issues) == 28 22 | assert len(result.story_arcs) == 0 23 | assert len(result.volumes) == 1 24 | 25 | 26 | def test_get_location_fail(session: Comicvine) -> None: 27 | """Test the get_location function with an invalid id.""" 28 | with pytest.raises(ServiceError): 29 | session.get_location(location_id=-1) 30 | 31 | 32 | def test_list_locations(session: Comicvine) -> None: 33 | """Test the list_locations function with a valid search.""" 34 | search_results = session.list_locations({"filter": "name:Odym"}) 35 | assert len(search_results) != 0 36 | result = next(x for x in search_results if x.id == 56000) 37 | assert result is not None 38 | 39 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/location/4020-56000/" 40 | assert result.issue_count == 28 41 | assert result.date_added == datetime(2009, 1, 2, 16, 16, 18) 42 | assert result.first_issue.id == 149271 43 | assert result.name == "Odym" 44 | assert str(result.site_url) == "https://comicvine.gamespot.com/odym/4020-56000/" 45 | 46 | 47 | def test_list_locations_empty(session: Comicvine) -> None: 48 | """Test the list_locations function with an invalid search.""" 49 | results = session.list_locations({"filter": "name:INVALID"}) 50 | assert len(results) == 0 51 | 52 | 53 | def test_list_locations_max_results(session: Comicvine) -> None: 54 | """Test the list_locations function with max_results.""" 55 | results = session.list_locations(max_results=10) 56 | assert len(results) == 10 57 | 58 | 59 | def test_search_location(session: Comicvine) -> None: 60 | """Test the search function for a list of Locations.""" 61 | results = session.search(resource=ComicvineResource.LOCATION, query="Earth") 62 | assert all(isinstance(x, BasicLocation) for x in results) 63 | -------------------------------------------------------------------------------- /tests/origins_test.py: -------------------------------------------------------------------------------- 1 | """The Origins test module. 2 | 3 | This module contains tests for Origin and BasicOrigin objects. 4 | """ 5 | 6 | import pytest 7 | 8 | from simyan.comicvine import Comicvine, ComicvineResource 9 | from simyan.exceptions import ServiceError 10 | from simyan.schemas.origin import BasicOrigin 11 | 12 | 13 | def test_get_origin(session: Comicvine) -> None: 14 | """Test the get_origin function with a valid id.""" 15 | result = session.get_origin(origin_id=1) 16 | assert result is not None 17 | assert result.id == 1 18 | 19 | assert result.character_set is None 20 | assert len(result.characters) == 4399 21 | assert len(result.profiles) == 0 22 | 23 | 24 | def test_get_origin_fail(session: Comicvine) -> None: 25 | """Test the get_origin function with an invalid id.""" 26 | with pytest.raises(ServiceError): 27 | session.get_origin(origin_id=-1) 28 | 29 | 30 | def test_list_origins(session: Comicvine) -> None: 31 | """Test the list_origins function with a valid search query.""" 32 | search_results = session.list_origins({"filter": "name:Mutant"}) 33 | assert len(search_results) != 0 34 | result = next(x for x in search_results if x.id == 1) 35 | assert result is not None 36 | 37 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/origin/4030-1/" 38 | assert result.name == "Mutant" 39 | assert str(result.site_url) == "https://comicvine.gamespot.com/mutant/4030-1/" 40 | 41 | 42 | def test_list_origins_empty(session: Comicvine) -> None: 43 | """Test the list_origins function with an invalid search query.""" 44 | results = session.list_origins({"filter": "name:INVALID"}) 45 | assert len(results) == 0 46 | 47 | 48 | def test_list_origins_max_results(session: Comicvine) -> None: 49 | """Test the list_origins function with max results.""" 50 | results = session.list_origins(max_results=3) 51 | assert len(results) == 3 52 | 53 | 54 | def test_search_origin(session: Comicvine) -> None: 55 | """Test the search function for a list of Origins.""" 56 | results = session.search(resource=ComicvineResource.ORIGIN, query="Mutant") 57 | assert all(isinstance(x, BasicOrigin) for x in results) 58 | -------------------------------------------------------------------------------- /tests/powers_test.py: -------------------------------------------------------------------------------- 1 | """The Powers test module. 2 | 3 | This module contains tests for Power and BasicPower objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.power import BasicPower 13 | 14 | 15 | def test_get_power(session: Comicvine) -> None: 16 | """Test the get_power function with a valid id.""" 17 | result = session.get_power(power_id=1) 18 | assert result is not None 19 | assert result.id == 1 20 | 21 | assert len(result.characters) == 8310 22 | 23 | 24 | def test_get_power_fail(session: Comicvine) -> None: 25 | """Test the get_power function with an invalid id.""" 26 | with pytest.raises(ServiceError): 27 | session.get_power(power_id=-1) 28 | 29 | 30 | def test_list_powers(session: Comicvine) -> None: 31 | """Test the list_powers function with a valid search query.""" 32 | search_results = session.list_powers({"filter": "name:Flight"}) 33 | assert len(search_results) != 0 34 | result = next(x for x in search_results if x.id == 1) 35 | assert result is not None 36 | 37 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/power/4035-1/" 38 | assert result.date_added == datetime(2008, 6, 6, 11, 28, 15) 39 | assert result.name == "Flight" 40 | assert ( 41 | str(result.site_url) 42 | == "https://comicvine.gamespot.com/characters/?wikiSlug=flight&wikiTypeId=4035&wikiId=1&powers%5B%5D=1" 43 | ) 44 | 45 | 46 | def test_list_powers_empty(session: Comicvine) -> None: 47 | """Test the list_powers function with an invalid search query.""" 48 | results = session.list_powers({"filter": "name:INVALID"}) 49 | assert len(results) == 0 50 | 51 | 52 | def test_list_powers_max_results(session: Comicvine) -> None: 53 | """Test the list_powers function with max results.""" 54 | results = session.list_powers(max_results=10) 55 | assert len(results) == 10 56 | 57 | 58 | def test_search_power(session: Comicvine) -> None: 59 | """Test the search function for a list of Powers.""" 60 | results = session.search(resource=ComicvineResource.POWER, query="Flight") 61 | assert all(isinstance(x, BasicPower) for x in results) 62 | -------------------------------------------------------------------------------- /tests/publishers_test.py: -------------------------------------------------------------------------------- 1 | """The Publishers test module. 2 | 3 | This module contains tests for Publisher and BasicPublisher objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.publisher import BasicPublisher 13 | 14 | 15 | def test_get_publisher(session: Comicvine) -> None: 16 | """Test the get_publisher function with a valid id.""" 17 | result = session.get_publisher(publisher_id=10) 18 | assert result is not None 19 | assert result.id == 10 20 | 21 | assert len(result.characters) == 24149 22 | assert len(result.story_arcs) == 895 23 | assert len(result.teams) == 1869 24 | assert len(result.volumes) == 9416 25 | 26 | 27 | def test_get_publisher_fail(session: Comicvine) -> None: 28 | """Test the get_publisher function with an invalid publisher_id.""" 29 | with pytest.raises(ServiceError): 30 | session.get_publisher(publisher_id=-1) 31 | 32 | 33 | def test_list_publishers(session: Comicvine) -> None: 34 | """Test the list_publishers function with a valid search.""" 35 | search_results = session.list_publishers({"filter": "name:DC Comics"}) 36 | assert len(search_results) != 0 37 | result = next(x for x in search_results if x.id == 10) 38 | assert result is not None 39 | 40 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/publisher/4010-10/" 41 | assert result.date_added == datetime(2008, 6, 6, 11, 8) 42 | assert result.location_address == "4000 Warner Blvd" 43 | assert result.location_city == "Burbank" 44 | assert result.location_state == "California" 45 | assert result.name == "DC Comics" 46 | assert str(result.site_url) == "https://comicvine.gamespot.com/dc-comics/4010-10/" 47 | 48 | 49 | def test_list_publishers_empty(session: Comicvine) -> None: 50 | """Test the list_publishers function with an invalid search.""" 51 | results = session.list_publishers({"filter": "name:INVALID"}) 52 | assert len(results) == 0 53 | 54 | 55 | def test_list_publishers_max_results(session: Comicvine) -> None: 56 | """Test the list_publishers function with max_results.""" 57 | results = session.list_publishers(max_results=10) 58 | assert len(results) == 10 59 | 60 | 61 | def test_search_publisher(session: Comicvine) -> None: 62 | """Test the search function for a list of Publishers.""" 63 | results = session.search(resource=ComicvineResource.PUBLISHER, query="DC") 64 | assert all(isinstance(x, BasicPublisher) for x in results) 65 | -------------------------------------------------------------------------------- /tests/story_arcs_test.py: -------------------------------------------------------------------------------- 1 | """The Story Arcs test module. 2 | 3 | This module contains tests for StoryArc and BasicStoryArc objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.story_arc import BasicStoryArc 13 | 14 | 15 | def test_get_story_arc(session: Comicvine) -> None: 16 | """Test the get_story_arc function with a valid id.""" 17 | result = session.get_story_arc(story_arc_id=55766) 18 | assert result is not None 19 | assert result.id == 55766 20 | 21 | assert len(result.issues) == 86 22 | 23 | 24 | def test_get_story_arc_fail(session: Comicvine) -> None: 25 | """Test the get_story_arc function with an invalid id.""" 26 | with pytest.raises(ServiceError): 27 | session.get_story_arc(story_arc_id=-1) 28 | 29 | 30 | def test_list_story_arcs(session: Comicvine) -> None: 31 | """Test the list_story_arcs function with a valid search.""" 32 | results = session.list_story_arcs({"filter": "name:Blackest Night"}) 33 | assert len(results) != 0 34 | result = next(x for x in results if x.id == 55766) 35 | assert result is not None 36 | 37 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/story_arc/4045-55766/" 38 | assert result.date_added == datetime(2008, 12, 6, 21, 29, 2) 39 | assert result.first_issue.id == 155207 40 | assert result.issue_count == 0 41 | assert result.name == '"Green Lantern" Blackest Night' 42 | assert result.publisher.id == 10 43 | assert ( 44 | str(result.site_url) 45 | == "https://comicvine.gamespot.com/green-lantern-blackest-night/4045-55766/" 46 | ) 47 | 48 | 49 | def test_list_story_arcs_empty(session: Comicvine) -> None: 50 | """Test the list_story_arcs function with an invalid search.""" 51 | results = session.list_story_arcs({"filter": "name:INVALID"}) 52 | assert len(results) == 0 53 | 54 | 55 | def test_list_story_arcs_max_results(session: Comicvine) -> None: 56 | """Test the list_story_arcs function with max_results.""" 57 | results = session.list_story_arcs(max_results=10) 58 | assert len(results) == 10 59 | 60 | 61 | def test_search_story_arc(session: Comicvine) -> None: 62 | """Test the search endpoint for a list of Story Arcs.""" 63 | results = session.search(resource=ComicvineResource.STORY_ARC, query="Blackest Night") 64 | assert all(isinstance(x, BasicStoryArc) for x in results) 65 | -------------------------------------------------------------------------------- /tests/teams_test.py: -------------------------------------------------------------------------------- 1 | """The Teams test module. 2 | 3 | This module contains tests for Team and BasicTeam objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.team import BasicTeam 13 | 14 | 15 | def test_get_team(session: Comicvine) -> None: 16 | """Test the get_team function with a valid id.""" 17 | result = session.get_team(team_id=50163) 18 | assert result is not None 19 | assert result.id == 50163 20 | 21 | assert len(result.enemies) == 5 22 | assert len(result.friends) == 10 23 | assert len(result.issues) == 120 24 | assert len(result.issues_disbanded_in) == 1 25 | assert len(result.members) == 18 26 | assert len(result.story_arcs) == 0 27 | assert len(result.volumes) == 65 28 | 29 | 30 | def test_get_team_fail(session: Comicvine) -> None: 31 | """Test the get_team function with an invalid id.""" 32 | with pytest.raises(ServiceError): 33 | session.get_team(team_id=-1) 34 | 35 | 36 | def test_list_teams(session: Comicvine) -> None: 37 | """Test the list_teams function with a valid search.""" 38 | search_results = session.list_teams({"filter": "name:Blue Lantern Corps"}) 39 | assert len(search_results) != 0 40 | result = next(x for x in search_results if x.id == 50163) 41 | assert result is not None 42 | 43 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/team/4060-50163/" 44 | assert result.issue_count == 0 45 | assert result.member_count == 18 46 | assert result.date_added == datetime(2008, 6, 6, 11, 27, 45) 47 | assert result.first_issue.id == 119950 48 | assert result.name == "Blue Lantern Corps" 49 | assert result.publisher.id == 10 50 | assert str(result.site_url) == "https://comicvine.gamespot.com/blue-lantern-corps/4060-50163/" 51 | 52 | 53 | def test_list_teams_empty(session: Comicvine) -> None: 54 | """Test the list_teams function with an invalid search.""" 55 | results = session.list_teams({"filter": "name:INVALID"}) 56 | assert len(results) == 0 57 | 58 | 59 | def test_list_teams_max_results(session: Comicvine) -> None: 60 | """Test the list_teams function with max_results.""" 61 | results = session.list_teams(max_results=10) 62 | assert len(results) == 10 63 | 64 | 65 | def test_search_team(session: Comicvine) -> None: 66 | """Test the search endpoint for a list of Teams.""" 67 | results = session.search(resource=ComicvineResource.TEAM, query="Lantern") 68 | assert all(isinstance(x, BasicTeam) for x in results) 69 | -------------------------------------------------------------------------------- /tests/volumes_test.py: -------------------------------------------------------------------------------- 1 | """The Volumes test module. 2 | 3 | This module contains tests for Volume and BasicVolume objects. 4 | """ 5 | 6 | from datetime import datetime 7 | 8 | import pytest 9 | 10 | from simyan.comicvine import Comicvine, ComicvineResource 11 | from simyan.exceptions import ServiceError 12 | from simyan.schemas.volume import BasicVolume 13 | 14 | 15 | def test_get_volume(session: Comicvine) -> None: 16 | """Test the get_volume function with a valid id.""" 17 | result = session.get_volume(volume_id=18216) 18 | assert result is not None 19 | assert result.id == 18216 20 | 21 | assert len(result.characters) == 368 22 | assert len(result.concepts) == 19 23 | assert len(result.creators) == 95 24 | assert len(result.issues) == 67 25 | assert len(result.locations) == 48 26 | assert len(result.objects) == 368 27 | 28 | 29 | def test_get_volume_fail(session: Comicvine) -> None: 30 | """Test the get_volume function with an invalid id.""" 31 | with pytest.raises(ServiceError): 32 | session.get_volume(volume_id=-1) 33 | 34 | 35 | def test_list_volumes(session: Comicvine) -> None: 36 | """Test the list_volumes function with a valid search.""" 37 | search_results = session.list_volumes({"filter": "name:Green Lantern"}) 38 | assert len(search_results) != 0 39 | result = next(x for x in search_results if x.id == 18216) 40 | assert result is not None 41 | 42 | assert str(result.api_url) == "https://comicvine.gamespot.com/api/volume/4050-18216/" 43 | assert result.date_added == datetime(2008, 6, 6, 11, 8, 33) 44 | assert result.first_issue.id == 111265 45 | assert result.issue_count == 67 46 | assert result.last_issue.id == 278617 47 | assert result.name == "Green Lantern" 48 | assert result.publisher.id == 10 49 | assert str(result.site_url) == "https://comicvine.gamespot.com/green-lantern/4050-18216/" 50 | assert result.start_year == 2005 51 | 52 | 53 | def test_list_volumes_empty(session: Comicvine) -> None: 54 | """Test the list_volumes function with an invalid search.""" 55 | results = session.list_volumes({"filter": "name:INVALID"}) 56 | assert len(results) == 0 57 | 58 | 59 | def test_list_volumes_max_results(session: Comicvine) -> None: 60 | """Test the list_volumes function with max_results.""" 61 | results = session.list_volumes(max_results=10) 62 | assert len(results) == 10 63 | 64 | 65 | def test_search_volume(session: Comicvine) -> None: 66 | """Test the search function for a list of Volumes.""" 67 | results = session.search(resource=ComicvineResource.VOLUME, query="Lantern") 68 | assert all(isinstance(x, BasicVolume) for x in results) 69 | --------------------------------------------------------------------------------