Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format-dates #31

Merged
merged 7 commits into from
Sep 12, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Initial work on date format clenaup
  • Loading branch information
bpepple committed Sep 11, 2021
commit 038045b987ff5ecc0e76fed5dd501341a4906f77
19 changes: 15 additions & 4 deletions Simyan/creator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from marshmallow import EXCLUDE, Schema, fields, post_load
from marshmallow.decorators import pre_load

from Simyan.generic_entries import GenericEntrySchema, ImageEntrySchema

Expand All @@ -14,10 +15,10 @@ class CreatorSchema(Schema):
api_url = fields.Url(data_key="api_detail_url")
country = fields.Str()
created_characters = fields.Nested(GenericEntrySchema, many=True)
date_added = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_last_updated = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_of_birth = fields.DateTime(format="%Y-%m-%d %H:%M:%S", data_key="birth", allow_none=True)
date_of_death = fields.DateTime(format="%Y-%m-%d %H:%M:%S", data_key="death", allow_none=True)
date_added = fields.DateTime()
date_last_updated = fields.DateTime()
date_of_birth = fields.DateTime(data_key="birth", allow_none=True)
date_of_death = fields.DateTime(format="%Y-%m-%d %H:%M:%S.%f", data_key="death", allow_none=True)
description = fields.Str()
email = fields.Str(allow_none=True)
gender = fields.Int()
Expand All @@ -35,6 +36,16 @@ class CreatorSchema(Schema):

class Meta:
unknown = EXCLUDE
dateformat = "%Y-%m-%d %H:%M:%S"

@pre_load
def process_input(self, data, **kwargs):
new_data = data

if "death" in new_data and new_data["death"] is not None:
new_data["death"] = new_data["death"]["date"]

return new_data

@post_load
def make_object(self, data, **kwargs) -> Creator:
Expand Down
9 changes: 5 additions & 4 deletions Simyan/creator_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ class CreatorResultSchema(Schema):
aliases = fields.Str(allow_none=True)
api_url = fields.Url(data_key="api_detail_url")
country = fields.Str()
date_added = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_last_updated = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_of_birth = fields.DateTime(format="%Y-%m-%d %H:%M:%S", data_key="birth", allow_none=True)
date_of_death = fields.DateTime(format="%Y-%m-%d %H:%M:%S", data_key="death", allow_none=True)
date_added = fields.DateTime()
date_last_updated = fields.DateTime()
date_of_birth = fields.DateTime(data_key="birth", allow_none=True)
date_of_death = fields.DateTime(data_key="death", allow_none=True)
description = fields.Str()
email = fields.Str(allow_none=True)
gender = fields.Int()
Expand All @@ -32,6 +32,7 @@ class CreatorResultSchema(Schema):

class Meta:
unknown = EXCLUDE
dateformat = "%Y-%m-%d %H:%M:%S"

@post_load
def make_object(self, data, **kwargs) -> CreatorResult:
Expand Down
5 changes: 3 additions & 2 deletions Simyan/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class PublisherSchema(Schema):
aliases = fields.Str(allow_none=True)
api_url = fields.Url(data_key="api_detail_url")
characters = fields.Nested(GenericEntrySchema, many=True)
date_added = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_last_updated = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_added = fields.DateTime()
date_last_updated = fields.DateTime()
description = fields.Str(allow_none=True)
id = fields.Int()
image = fields.Nested(ImageEntrySchema)
Expand All @@ -30,6 +30,7 @@ class PublisherSchema(Schema):

class Meta:
unknown = EXCLUDE
dateformat = "%Y-%m-%d %H:%M:%S"

@post_load
def make_object(self, data, **kwargs) -> Publisher:
Expand Down
5 changes: 3 additions & 2 deletions Simyan/publisher_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def __init__(self, **kwargs):
class PublisherResultSchema(Schema):
aliases = fields.Str(allow_none=True)
api_url = fields.Url(data_key="api_detail_url")
date_added = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_last_updated = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_added = fields.DateTime()
date_last_updated = fields.DateTime()
description = fields.Str(allow_none=True)
id = fields.Int()
image = fields.Nested(ImageEntrySchema)
Expand All @@ -27,6 +27,7 @@ class PublisherResultSchema(Schema):

class Meta:
unknown = EXCLUDE
dateformat = "%Y-%m-%d %H:%M:%S"

@post_load
def make_object(self, data, **kwargs) -> PublisherResult:
Expand Down
5 changes: 3 additions & 2 deletions Simyan/story_arc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def __init__(self, **kwargs):
class StoryArcSchema(Schema):
aliases = fields.Str(allow_none=True)
api_url = fields.Url(data_key="api_detail_url")
date_added = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_last_updated = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_added = fields.DateTime()
date_last_updated = fields.DateTime()
description = fields.Str(allow_none=True)
# Ignoring Episodes
# Ignoring First Episode
Expand All @@ -30,6 +30,7 @@ class StoryArcSchema(Schema):

class Meta:
unknown = EXCLUDE
dateformat = "%Y-%m-%d %H:%M:%S"

@post_load
def make_object(self, data, **kwargs) -> StoryArc:
Expand Down
5 changes: 3 additions & 2 deletions Simyan/story_arc_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def __init__(self, **kwargs):
class StoryArcResultSchema(Schema):
aliases = fields.Str(allow_none=True)
api_url = fields.Url(data_key="api_detail_url")
date_added = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_last_updated = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_added = fields.DateTime()
date_last_updated = fields.DateTime()
description = fields.Str(allow_none=True)
# Ignoring First Episode
first_issue = fields.Nested(IssueEntrySchema, data_key="first_appeared_in_issue")
Expand All @@ -28,6 +28,7 @@ class StoryArcResultSchema(Schema):

class Meta:
unknown = EXCLUDE
dateformat = "%Y-%m-%d %H:%M:%S"

@post_load
def make_object(self, data, **kwargs) -> StoryArcResult:
Expand Down
5 changes: 3 additions & 2 deletions Simyan/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class VolumeSchema(Schema):
characters = fields.Nested(CountEntrySchema, many=True)
concepts = fields.Nested(CountEntrySchema, many=True)
creators = fields.Nested(CountEntrySchema, data_key="people", many=True)
date_added = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_last_updated = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_added = fields.DateTime()
date_last_updated = fields.DateTime()
description = fields.Str(allow_none=True)
first_issue = fields.Nested(IssueEntrySchema)
id = fields.Int()
Expand All @@ -34,6 +34,7 @@ class VolumeSchema(Schema):

class Meta:
unknown = EXCLUDE
dateformat = "%Y-%m-%d %H:%M:%S"

@post_load
def make_object(self, data, **kwargs) -> Volume:
Expand Down
5 changes: 3 additions & 2 deletions Simyan/volume_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def __init__(self, **kwargs):
class VolumeResultSchema(Schema):
aliases = fields.Str(allow_none=True)
api_url = fields.Url(data_key="api_detail_url")
date_added = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_last_updated = fields.DateTime(format="%Y-%m-%d %H:%M:%S")
date_added = fields.DateTime()
date_last_updated = fields.DateTime()
description = fields.Str(allow_none=True)
first_issue = fields.Nested(IssueEntrySchema)
id = fields.Int()
Expand All @@ -29,6 +29,7 @@ class VolumeResultSchema(Schema):

class Meta:
unknown = EXCLUDE
dateformat = "%Y-%m-%d %H:%M:%S"

@post_load
def make_object(self, data, **kwargs) -> VolumeResult:
Expand Down
Binary file modified tests/Simyan-Cache.sqlite
Binary file not shown.
7 changes: 6 additions & 1 deletion tests/test_creators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest

import datetime
from Simyan.exceptions import APIError

COUNTRY = "United States"
Expand Down Expand Up @@ -44,6 +44,11 @@ def test_creator_fail(comicvine):
with pytest.raises(APIError):
comicvine.creator(-1)

def test_creator_with_dob(comicvine):
kirby = comicvine.creator(5614)
assert kirby.date_of_birth == datetime.datetime(1917, 8, 28, 0, 0)
assert kirby.date_of_death == datetime.datetime(1994, 2, 6, 0, 0)


def test_creator_list(comicvine):
search_results = comicvine.creator_list({"filter": f"name:{NAME}"})
Expand Down