[ ENH ] Add Export Function
hentai-chan opened this issue · 1 comments
Issue Description
Is your feature request related to a problem? Please describe.
Implement a function that stores data as a JSON file to disk for processing in other languages.
Describe the solution you'd like
from hentai import Hentai
popular_loli = Hentai.search_all_by_query('tag:loli')
# dest should default to CWD
# keyword arguments narrow down the properties to store
# Hentai.All should save all properties bound to a Hentai object
Hentai.export(popular_loli, dest='./target/path/filename.json', options=[Hentai.ID, Hentai.UploadDate])
This function should also work with collections coming from
search_by_query
get_homepage
browse_homepage
- any
Hentai
object
Describe alternatives you've considered
If there is an easier way to specify which properties to include (like Hentai.ID
, etc.), go for it. Either way, this function should be able to to influence the result of the outcome in order to reduce the final file size, but also to make it easier to inspect the data later on by dismissing unnecessary information upfront.
Sample Input
Example 1
>>> from hentai import Hentai
>>> doujin = Hentai(177013)
>>> # save doujin.json to disk
>>> doujin.export()
Example 2
>>> from hentai import Hentai
>>> doujin = Hentai(177013)
>>> # save doujin.json to disk
>>> doujin.export(options=[Hentai.ID, Hentai.UploadDate, Hentai.NumFavorites])
Sample Output
Example 1
{'id': 177013, 'media_id': '987560', 'title': {'english': '[ShindoLA] METAMORPHOSIS (Complete) [English]', ...
Example 2
{'id': 177013, 'upload_date': '2016-10-18 14:28:49', 'num_favorites': 44548}
Lists of doujins coming from search_by_query
or get_homepage
should export the information using the same format wrapped around a list, e.g.
doujins = Hentai.get_homepage()
Hentai.export(doujins, options=[Hentai.ID, Hentai.UploadDate, Hentai.NumFavorites])
[
{
'id': 177013,
'upload_date': "2016-10-18 14:28:49",
'num_favorites': 44548
},
{
'id': 269582,
'upload_date': "2019-04-20 14:54:07",
'num_favorites': 6163
},
...
]
Additional context
See also the current contributing guidelines and the project's wiki. Don't forget to add a unit test to the test suite at hentai/test_hentai
once everything is said and done.
Update for October 1, 2020: Implemented feature, will be pushed to remote dev-branch
once it's covered by the test suite.