Closed RileyFitz closed 1 year ago
Hey I'm bumping this thread. Is this fork ready to be merged, or would you like to see some changes before it is accepted?
As this Repo stands now, the Items package is broken. The RSBuddy API has been broken for over 6 months now, and I doubt that will change soon.
I'm getting this error:
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
File /usr/lib/python3.10/http/client.py:565, in HTTPResponse._get_chunk_left(self)
564 try:
--> 565 chunk_left = self._read_next_chunk_size()
566 except ValueError:
File /usr/lib/python3.10/http/client.py:532, in HTTPResponse._read_next_chunk_size(self)
531 try:
--> 532 return int(line, 16)
533 except ValueError:
534 # close the connection as protocol synchronisation is
535 # probably lost
ValueError: invalid literal for int() with base 16: b''
During handling of the above exception, another exception occurred:
IncompleteRead Traceback (most recent call last)
File /usr/lib/python3.10/http/client.py:582, in HTTPResponse._read_chunked(self, amt)
581 while True:
--> 582 chunk_left = self._get_chunk_left()
583 if chunk_left is None:
File /usr/lib/python3.10/http/client.py:567, in HTTPResponse._get_chunk_left(self)
566 except ValueError:
--> 567 raise IncompleteRead(b'')
568 if chunk_left == 0:
569 # last chunk: 1*("0") [ chunk-extension ] CRLF
IncompleteRead: IncompleteRead(0 bytes read)
During handling of the above exception, another exception occurred:
IncompleteRead Traceback (most recent call last)
Cell In [5], line 3
1 from OSRSBytes import Items
----> 3 items = Items()
File ~/osrs/.venv/lib/python3.10/site-packages/OSRSBytes/Items.py:84, in Items.__init__(self, api)
82 if self.api == "buddy":
83 req, buylims = self.__getHTTPRequestB()
---> 84 self.itemname = self.__parseResponseByItemName(req, buylims)
85 elif self.api == 'wiki':
86 prices, volumes, mappings = self.__getHTTPRequestW()
File ~/osrs/.venv/lib/python3.10/site-packages/OSRSBytes/Items.py:232, in Items.__parseResponseByItemName(self, req, buylims)
214 def __parseResponseByItemName(self, req, buylims):
215 """parseResponseByItemName method
216
217 The parseResponseByItemName() method is responsible for accepting the
(...)
230 boolval: Returns false on parse error
231 """
--> 232 r = urllib.request.urlopen(req).read()
233 try:
234 parsedJSON = json.loads(r.decode('utf-8'))
File /usr/lib/python3.10/http/client.py:459, in HTTPResponse.read(self, amt)
456 return b""
458 if self.chunked:
--> 459 return self._read_chunked(amt)
461 if amt is not None:
462 if self.length is not None and amt > self.length:
463 # clip the read to the "end of response"
File /usr/lib/python3.10/http/client.py:597, in HTTPResponse._read_chunked(self, amt)
595 return b''.join(value)
596 except IncompleteRead:
--> 597 raise IncompleteRead(b''.join(value))
IncompleteRead: IncompleteRead(144086 bytes read)
This is the exact issue that I am trying to solve actually. The issue you are seeing is because the default API called for the Items class is from RSBuddy, whose API is no longer operational. You can check that API here
To fix this issue, ensure the new wiki API is called when initializing an Items variable, as such:
import OSRSBytes
items = OSRSBytes.Items('wiki')
My changes do allow the broken RSBuddy API to continue to be the default. I could easily change the default API source to the wiki source, but I would want some push on this thread.. ahem
There are a couple of issues that I currently have with this proposed push. I do understand, however, that this is currently a stale issue that needs to be worked on. I'll be writing up something later today to address the issue.
@RileyFitz if you'd like to discuss the changes and work through them with me, feel free to add me on discord @ CFD#7777, otherwise I'll probably start work on a revision by tomorrow.
I sent a friend request on Discord to discuss in further detail. Give me a couple days to look over your comments, and I can submit a new pull request.
Overview
In response to issue in #19, these changes have been made.
OSRS Wiki API
Added the ability to use the OSRS Wiki API's as an alternative. The RSBuddy API has been broken for some time now, and wanted an alternative API so this library could still function.
Added a self.api attribute to be able to distinguish what API is active.
Structured the item json/dict as similarly as possible and testing showed all methods work with both item name and ID.
getName method accepts integers
Update README and versioning
Please let me know if you have questions, or remarks. Cheers