Skip to content

get_bookmarks from User#87

Open
encars28 wants to merge 3 commits into
wendytg:masterfrom
encars28:get_bookmarks
Open

get_bookmarks from User#87
encars28 wants to merge 3 commits into
wendytg:masterfrom
encars28:get_bookmarks

Conversation

@encars28

Copy link
Copy Markdown
Contributor

This should fix #86

The problem was that when a series banner was passed to get_work_from_banner instead of a work, this condition is never true:
elif a.attrs["href"].startswith("/works"):

This means that the workid is never initialized and there's an UnboundLocalError when we try to create a Work object.
We can fix it by checking if the banner is the banner of a series or a work, so the get_work_from_banner is only called when we have a work and it doesn't raise that error.

This doesn't fix the problem completely, because mistery works and external works still raise an error.
The external works problem can be fixed by changing the sintaxis of the condition that sets the workid, so that it is true for any string with "works/" in it, instead of strings that start with "/works".
The mistery works problem can be fixed by checking the h4 tag before calling get_work_from_banner. This way, it skips the mistery works.

This function returns a Series or a Work depending on the banner you pass.
Instead of calling get_work_from_banner now _load_bookmarks calls get_work_or_series_from_banner, so the bookmarks can be now a Work or a Series and the function doesn't cause errors when a series is passed instead of a work
Changed the get_work_from_banner function so it doesn't raise an error when we pass the banner of a external work
@whitevegagabriel

Copy link
Copy Markdown

Can confirm this fixed it for me. Also fixes the error where some works either no longer exist or are Mystery.

@michaelkeenan

Copy link
Copy Markdown

Thanks for solving this encars28!

I'm using it locally and I get "NameError: name 'get_work_or_series_from_banner' is not defined". I've fixed it by changing this:

from .common import get_work_from_banner

to:

from .common import get_work_from_banner, get_work_or_series_from_banner

JuszieDragon added a commit to JuszieDragon/ao3_api that referenced this pull request Mar 2, 2024
Added the changes from [this PR](wendytg#87) by encars28 in the [original repo](https://github.com/ArmindoFlores/ao3_api)
mcmanustfj added a commit to mcmanustfj/ao3_api that referenced this pull request Dec 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

User.get_bookmarks() raises a error because some bookmarks are Series and not Works

3 participants