bibanon / py8chan

Python wrapper for the 8chan API, based on BASC-py4chan.
Do What The F*ck You Want To Public License
14 stars 7 forks source link

embed & minor fixes, resolves #1 #26

Closed KebabLord closed 11 months ago

KebabLord commented 11 months ago

EMBED Method

Added embed property to post, None if no embed. Used regex to parse the url.

>>> post.embed_url
'https://www.youtube.com/watch?v=dQw4w9WgXcQ'

Embed key on api only contained embed's url and the thumbnail url. Api didn't provide any data about the thumbnail (size,width etc) and there wasn't much useful data besides that so i didn't create class for embed, and didn't use the File class to create an thumbnail object either.

FIXES

Accessing the session like this:

    def file_request(self):
        return self._thread._board._requests_session.get(self.file_url)

Was throwing this error:

py8chan/file.py:120:15: E1101: Instance of 'File' has no '_thread' member (no-member)

So replaced with self._post._thread instead.

Replacing <p with \n like this: https://github.com/bibanon/py8chan/blob/bc498f3da434538676172e4b6f4413a0b105639d/py8chan/util.py#L26 was adding a newline beginning to texts:

>>> p1.text_comment
'\nthe thread comment'
>>> p2.text_comment
'\n>>104493\nembed reply'
>>> p3.text_comment
'\nnow another post with an image'

Used .strip() to get rid of that.