예제 #1
0
파일: tables.py 프로젝트: jtom38/newsbot
 def add(self) -> None:
     s = database.newSession()
     try:
         s.add(self)
         s.commit()
     except FailedToAddToDatabase as e:
         print(f"Failed to add '{self.message}' to 'Logs'. {e}")
     finally:
         s.close()
예제 #2
0
파일: tables.py 프로젝트: jtom38/newsbot
 def remove(self) -> None:
     s = database.newSession()
     try:
         for d in s.query(Icons).filter(Icons.site == self.site):
             s.delete(d)
         s.commit()
     except Exception as e:
         print(f"{e}")
     finally:
         s.close()
예제 #3
0
파일: tables.py 프로젝트: jtom38/newsbot
    def add(self) -> None:
        s = database.newSession()

        try:
            s.add(self)
            s.commit()
        except FailedToAddToDatabase as e:
            print(f"Failed to add {self.site} to Icons table! {e}")
        finally:
            s.close()
예제 #4
0
파일: tables.py 프로젝트: jtom38/newsbot
 def clearTable(self) -> None:
     s = database.newSession()
     try:
         for d in s.query(Icons):
             s.delete(d)
         s.commit()
     except Exception as e:
         print(f"{e}")
     finally:
         s.close()
예제 #5
0
파일: tables.py 프로젝트: jtom38/newsbot
 def findAllByName(self) -> List:
     s = database.newSession()
     l = list()
     try:
         for res in s.query(Icons).filter(Icons.site.contains(self.site)):
             l.append(res)
     except Exception as e:
         pass
     finally:
         s.close()
         return l
예제 #6
0
파일: tables.py 프로젝트: jtom38/newsbot
 def remove(self) -> None:
     s = database.newSession()
     try:
         for d in s.query(DiscordQueue).filter(
                 DiscordQueue.link == self.link):
             s.delete(d)
         s.commit()
     except Exception as e:
         print(f"{e}")
     finally:
         s.close()
예제 #7
0
파일: tables.py 프로젝트: jtom38/newsbot
 def add(self) -> bool:
     s = database.newSession()
     res: bool = True
     try:
         s.add(self)
         s.commit()
     except FailedToAddToDatabase as e:
         print(f"Failed to add {self.title} to DiscorQueue table! {e}")
         res = False
     finally:
         s.close()
         return res
예제 #8
0
파일: tables.py 프로젝트: jtom38/newsbot
    def __len__(self) -> int:
        s = database.newSession()
        l = list()
        try:
            for res in s.query(DiscordWebHooks):
                l.append(res)
        except Exception as e:
            pass
        finally:
            s.close()

        return len(l)
예제 #9
0
파일: tables.py 프로젝트: jtom38/newsbot
 def findAllByName(self) -> List:
     s = database.newSession()
     hooks = list()
     try:
         for res in s.query(DiscordWebHooks).filter(
                 DiscordWebHooks.name.contains(self.name)):
             hooks.append(res)
     except Exception as e:
         pass
     finally:
         s.close()
         return hooks
예제 #10
0
파일: tables.py 프로젝트: jtom38/newsbot
    def getQueue(self) -> List:
        s = database.newSession()
        queue = list()
        dq = DiscordQueue()
        try:
            for res in s.query(DiscordQueue):
                queue.append(res)
        except Exception as e:
            pass
        finally:
            s.close()

        return queue
예제 #11
0
파일: tables.py 프로젝트: jtom38/newsbot
    def add(self) -> None:
        """
        Adds a single object to the table.

        Returns: None
        """
        s = database.newSession()
        try:
            s.add(self)
            s.commit()
        except FailedToAddToDatabase as e:
            print(f"Failed to add {self.key} to 'settings'. {e}")
        finally:
            s.close()
예제 #12
0
파일: tables.py 프로젝트: jtom38/newsbot
 def add(self) -> None:
     s = database.newSession()
     h = DiscordWebHooks()
     h.key = self.key
     h.name = self.name
     h.enabled = self.enabled
     try:
         s.add(self)
         s.commit()
         # print(f"'{self.name}' was added to the Discord queue")
     except FailedToAddToDatabase as e:
         print(f"Failed to add {self.name} to DiscordWebHook table! {e}")
     finally:
         s.close()
예제 #13
0
파일: tables.py 프로젝트: jtom38/newsbot
    def clearTable(self) -> None:
        """
        Removes all the objects found in the Settings Table.

        Returns: None
        """
        s = database.newSession()
        try:
            for d in s.query(Settings):
                s.delete(d)
            s.commit()
        except Exception as e:
            print(f"{e}")
        finally:
            s.close()
예제 #14
0
파일: tables.py 프로젝트: jtom38/newsbot
    def remove(self) -> None:
        """
        Removes single object based on its ID value.

        Returns: None
        """
        s = database.newSession()
        try:
            for d in s.query(Settings).filter(Settings.id == self.id):
                s.delete(d)
            s.commit()
        except Exception as e:
            Logger().error(
                f"Failed to remove {self.key} from Settings table. {e}")
        finally:
            s.close()
예제 #15
0
파일: tables.py 프로젝트: jtom38/newsbot
 def clearSingle(self) -> bool:
     """
     This will remove a single entry from the table by its ID value.
     """
     s = database.newSession()
     result: bool = False
     try:
         for i in s.query(Sources).filter(Sources.id == self.id):
             s.delete(i)
             s.commit()
             result = True
     except Exception as e:
         print(e)
     finally:
         s.close()
         return result
예제 #16
0
파일: tables.py 프로젝트: jtom38/newsbot
    def __len__(self) -> int:
        """
        Returns the number of rows based off the SiteName value provieded.
        """

        s = database.newSession()
        l = list()
        try:
            for res in s.query(Articles).filter(
                    Articles.siteName == self.siteName):
                l.append(res)
        except Exception as e:
            pass
        finally:
            s.close()

        return len(l)
예제 #17
0
파일: tables.py 프로젝트: jtom38/newsbot
    def __len__(self) -> int:
        """
        Returns the number of rows based off the Key value provided.

        Returns: Int
        """
        s = database.newSession()
        l = list()
        try:
            for res in s.query(Settings).filter(Settings.key == self.key):
                l.append(res)
        except Exception as e:
            pass
        finally:
            s.close()

        return len(l)
예제 #18
0
파일: tables.py 프로젝트: jtom38/newsbot
    def findSingleByKey(self) -> None:
        """
        Searches the database for objects that contain the Key value.
        
        Returns: Settings
        """
        s = database.newSession()
        d = Settings()
        try:
            for d in s.query(Settings).filter(Settings.key.contains(self.key)):
                pass
        except Exception as e:
            pass
        finally:
            s.close()

        return d
예제 #19
0
파일: tables.py 프로젝트: jtom38/newsbot
 def findAllByKey(self) -> List:
     """
     Searches the database for objects that contain the Key value.
     
     Returns: List[Settings]
     """
     s = database.newSession()
     l = list()
     try:
         for res in s.query(Settings).filter(Settings.key.contains(
                 self.key)):
             l.append(res)
     except Exception as e:
         pass
     finally:
         s.close()
         return l
예제 #20
0
파일: tables.py 프로젝트: jtom38/newsbot
    def exists(self) -> bool:
        """
        Check to see if the current record exists.
        """

        s = database.newSession()
        a = Articles()
        try:
            for res in s.query(Articles).filter(Articles.url == self.url):
                a = res
        except Exception as e:
            pass
        finally:
            s.close()

        if self.url == a.url:
            return True
        else:
            return False
예제 #21
0
파일: tables.py 프로젝트: jtom38/newsbot
    def add(self) -> None:
        s = database.newSession()

        a = Articles(siteName=self.siteName,
                     tags=self.tags,
                     title=self.title,
                     url=self.url,
                     pubDate=self.pubDate,
                     video=self.video,
                     videoWidth=self.videoWidth,
                     videoHeight=self.videoHeight,
                     thumbnail=self.thumbnail,
                     description=self.description,
                     authorImage=self.authorImage,
                     authorName=self.authorName)

        try:
            s.add(a)
            s.commit()
        except FailedToAddToDatabase as e:
            print(f"Failed to add {self.title} to the database! {e}")
        finally:
            s.close()