ArmindoFlores / ao3_api

An unofficial archiveofourown.org (AO3) API for python
MIT License
166 stars 64 forks source link

Searching for a work via title #16

Closed Wrench-wench closed 3 years ago

Wrench-wench commented 3 years ago

When searching for a work via it's title the search results return as something I don't understand. Searching the code doesn't reveal anything about how the results are returned or supposed to be understood.


search_result = AO3.Search(title="The Real Meaning of Idioms")
search_result.update()
print(search_result)

Returns this result in the terminal: <AO3.search.Search object at 0x7f5ab4ea6100>

I did at first think this was due to a title collision, but have tested this will multiple different titles.

ArmindoFlores commented 3 years ago

The correct usage should be

search_result = AO3.Search(title="The Real Meaning of Idioms")
search_result.update()
print(search_result.results)

which gets you this result:

[<Work [The Real Meaning of Idioms]>, <Work [[PODFIC] The Real Meaning of Idioms]>, <Work [Cover for The Real Meaning of Idioms]>]
Wrench-wench commented 3 years ago

Thank you for the response, would you have a suggested way of getting the workID or URL from a title?

ArmindoFlores commented 3 years ago

I don't think there's really a way around searching and selecting one of the results. After you have them, you can use something like search_result.results[0].workid to get the ID of the first one.

Wrench-wench commented 3 years ago

It's close enough to what I need. Cheers!