From 3223c0721adfc9c75a5436b402adfb75113bed92 Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sat, 18 Jul 2020 04:42:19 +0400 Subject: [PATCH] Fixed OP's post property. Handled situation when comment and/or subject doesn't exists. --- scrapthechan/parsers/dvach.py | 9 +++++++-- scrapthechan/parsers/fourchan.py | 10 ++++++---- scrapthechan/parsers/lainchan.py | 9 +++++++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/scrapthechan/parsers/dvach.py b/scrapthechan/parsers/dvach.py index 4e5e6e2..e4378fd 100644 --- a/scrapthechan/parsers/dvach.py +++ b/scrapthechan/parsers/dvach.py @@ -24,8 +24,13 @@ class DvachParser(Parser): return "2ch.hk" @property - def op(self) -> str: - return f"{self._op_post['subject']}\n{self._op_post['comment']}" + def op(self) -> Optional[str]: + op = "" + if 'sub' in self._op_post: + op = f"{self._op_post['subject']}\n" + if 'com' in self._op_post: + op += self._op_post['comment'] + return op if not op == "" else None def _parse_post(self, post) -> Optional[List[FileInfo]]: if not 'files' in post: return None diff --git a/scrapthechan/parsers/fourchan.py b/scrapthechan/parsers/fourchan.py index ee4d386..179bd81 100644 --- a/scrapthechan/parsers/fourchan.py +++ b/scrapthechan/parsers/fourchan.py @@ -24,11 +24,13 @@ class FourChanParser(Parser): return "4chan.org" @property - def op(self) -> str: + def op(self) -> Optional[str]: + op = "" if 'sub' in self._op_post: - return f"{self._op_post['sub']}\n{self._op_post['com']}" - else: - return self._op_post['com'] + op = f"{self._op_post['sub']}\n" + if 'com' in self._op_post: + op += self._op_post['com'] + return op if not op == "" else None def _parse_post(self, post: dict) -> List[FileInfo]: if not 'tim' in post: return None diff --git a/scrapthechan/parsers/lainchan.py b/scrapthechan/parsers/lainchan.py index 3d05fd8..cb251b4 100644 --- a/scrapthechan/parsers/lainchan.py +++ b/scrapthechan/parsers/lainchan.py @@ -25,6 +25,15 @@ class LainchanParser(Parser): @property def imageboard(self) -> str: return "lainchan.org" + + @property + def op(self) -> Optional[str]: + op = "" + if 'sub' in self._op_post: + op = f"{self._op_post['sub']}\n" + if 'com' in self._op_post: + op += self._op_post['com'] + return op if not op == "" else None def _parse_post(self, post) -> List[FileInfo]: if not 'tim' in post: return None