ArmindoFlores / ao3_api

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

Can't return search total results if > 1000 due to ',' in string #82

Closed Tophattingson closed 1 year ago

Tophattingson commented 1 year ago
Traceback (most recent call last):
  File "C:\Users\achar\Documents\Python\ao3 relationship graph\genshin v2.py", line 107, in <module>
    results = worksforship(relationship)
  File "C:\Users\achar\Documents\Python\ao3 relationship graph\genshin v2.py", line 80, in worksforship
    search.update()
  File "C:\Users\achar\AppData\Local\Programs\Python\Python38\lib\site-packages\AO3\threadable.py", line 13, in new
    return func(*args, **kwargs)
  File "C:\Users\achar\AppData\Local\Programs\Python\Python38\lib\site-packages\AO3\search.py", line 112, in update
    self.total_results = int(maindiv.find("h3", {"class": "heading"}).getText().strip().split(" ")[0])
ValueError: invalid literal for int() with base 10: '4,076'

Solution is to add .replace(',','') to self.total_results or equivalent

EtchJetty commented 1 year ago

Seconding this problem.

nvl-github commented 1 year ago

Thirding this problem! Cannot perform int() on a string with a comma character in it. We see the issue currently on the documented example of the Search class .update() method:

 search = AO3.Search(any_field="Clarke Lexa", word_count=AO3.utils.Constraint(5000, 15000))
>>> search.update()
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    search.update()
  File "C:\Users\nicol\AppData\Local\Programs\Python\Python39-32\lib\site-packages\AO3\threadable.py", line 13, in new
    return func(*args, **kwargs)
  File "C:\Users\nicol\AppData\Local\Programs\Python\Python39-32\lib\site-packages\AO3\search.py", line 112, in update
    self.total_results = int(maindiv.find("h3", {"class": "heading"}).getText().strip().split(" ")[0])
ValueError: invalid literal for int() with base 10: '3,364'
nvl-github commented 1 year ago

I just cloned this repo (Hi! I'm new here hehe!) and think I found the fix for this issue. I'm a bit of a newb to GitHub, but I'll try creating a Pull Request for the fix. If I am unsuccessful and someone else finds this thread and it's still unresolved, the problem seems to be in this line of the Search class update() method: self.total_results = int(maindiv.find("h3", {"class": "heading"}).getText().strip().split(" ")[0]) And it can be fixed with this: self.total_results = int(maindiv.find("h3", {"class": "heading"}).getText().replace(',','').strip().split(" ")[0]) But I am in a country where the thousands delimiter is a comma. I'm not sure if this fix will work for areas where the thousands delimiter is a period. So this might be a better solution: self.total_results = int(maindiv.find("h3", {"class": "heading"}).getText().replace(',','').replace('.','').strip().split(" ")[0])

nvl-github commented 1 year ago

I raised a pull request for this, I just don't know how to assign anyone to review and approve it. @ArmindoFlores many apologies for my newbness. [https://github.com/ArmindoFlores/ao3_api/pull/93]