コード例 #1
0
    def getClips(self,
                 auth: TwitchAuth,
                 user_id: int = 0,
                 clip_id: str = "",
                 game_id: int = 0) -> List[TwitchClip]:
        uri = f"{self.apiUri}/clips"
        if user_id != 0:
            uri = f"{uri}?broadcaster_id={user_id}"
        elif clip_id != "":
            uri = f"{uri}?id={clip_id}"
        elif game_id != 0:
            uri = f"{uri}?game_id={game_id}"
        else:
            Logger().error(
                f"Clips was requested but was given invalid parameters, returning empty object."
            )
            return ""

        res = get(uri, headers=self.__header__(auth))
        clips = list()
        if res.status_code != 200:
            Logger().error(
                f"Clips request returnd a bad status_code. Code: {res.status_code}, Error: {res.text}"
            )
            return clips
        else:
            json = loads(res.content)
            for i in json["data"]:
                clips.append(TwitchClip(i))

        return clips
コード例 #2
0
 def getUser(self, auth: TwitchAuth, username: str) -> None:
     uri = f"{self.apiUri}/users?login={username}"
     res = get(uri, headers=self.__header__(auth))
     if res.status_code != 200:
         Logger().error(
             f"Failed to get user information. StatusCode: {res.status_code}, Error: {res.text}"
         )
     else:
         json = loads(res.content)
         if len(json["data"]) == 1:
             user = TwitchUser(json["data"][0])
         else:
             Logger().error(f"Did not get a usable object.")
             user = TwitchUser({})
         return user
コード例 #3
0
    def getStreams(self,
                   auth: TwitchAuth,
                   game_id: int = 0,
                   user_id: int = 0,
                   user_login: str = "") -> None:
        uri = f"{self.apiUri}/streams"
        if game_id != 0:
            uri = f"{uri}?game_id={game_id}"
        elif user_id != 0:
            uri = f"{uri}?user_id={user_id}"
        elif user_login != "":
            uri = f"{uri}?user_login={user_login}"
        else:
            pass

        res = get(uri, headers=self.__header__(auth))
        streams = list()
        if res.status_code != 200:
            Logger().error(
                f"Streams request returned a bad status_code. Code: {res.status_code}, Error: {res.test}"
            )
            return streams
        else:
            json = loads(res.content)
            if len(json["data"]) == 0:
                streams.append(TwitchStream())
            for i in json["data"]:
                streams.append(TwitchStream(i))

        return streams
コード例 #4
0
ファイル: rss.py プロジェクト: jtom38/newsbot
 def __init__(self, url: str, siteName: str) -> None:
     self.logger = Logger(__class__)
     self.url: str = url
     self.siteName: str = siteName
     self.content: RequestSiteContent = RequestContent(url=url)
     self.content.getPageDetails()
     # self.rssHelper: IRssContent = rssHelper
     pass
コード例 #5
0
 def __init__(self) -> None:
     self.uri:str = ""
     self.logger = Logger(__class__)
     
     self.outputDiscord: bool = False
     self.hooks = List[DiscordWebHooks] = list()
     
     self.sourceEnabled: bool = False
     self.links: List[Sources] = list()
     pass
コード例 #6
0
    def __init__(self) -> None:
        self.logger = Logger(__class__)
        self.uri = "https://reddit.com/r/aww/top.json"
        self.siteName = "Reddit"
        self.links: List[Sources] = list()
        self.hooks: List[DiscordWebHooks] = list()
        self.sourceEnabled: bool = False
        self.outputDiscord: bool = False

        self.checkEnv(self.siteName)
コード例 #7
0
 def __init__(self) -> None:
     self.logger = Logger(__class__)
     self.uri = "https://twitch.tv/"
     self.siteName: str = "Twitch"
     self.links: List[Sources] = list()
     self.hooks: List[DiscordWebHooks] = list()
     self.sourceEnabled: bool = False
     self.outputDiscord: bool = False
     self.checkEnv(self.siteName)
     pass
コード例 #8
0
ファイル: pso2.py プロジェクト: jtom38/newsbot
 def __init__(self) -> None:
     self.logger = Logger(__class__)
     self.uri: str = "https://pso2.com/news"
     self.siteName: str = "Phantasy Star Online 2"
     self.authorName: str = f"{self.siteName} Offical Site"
     self.links = list()
     self.hooks = list()
     self.sourceEnabled: bool = False
     self.outputDiscord: bool = False
     self.checkEnv(self.siteName)
     pass
コード例 #9
0
 def __init__(self) -> None:
     self.logger = Logger(__class__)
     self.uri = "https://pokemongohub.net/rss"
     self.siteName: str = "Pokemon Go Hub"
     self.authorName: str = "Pokemon Go Hub"
     self.links = list()
     self.hooks = list()
     self.sourceEnabled: bool = False
     self.outputDiscord: bool = False
     self.checkEnv(self.siteName)
     pass
コード例 #10
0
ファイル: rss.py プロジェクト: jtom38/newsbot
 def __init__(self) -> None:
     self.logger = Logger(__class__)
     self.uri = "https://example.net/"
     self.siteName: str = "RSS"
     self.feedName: str = ""
     self.RssHelper: IRssContent = IRssContent()
     self.links: List[Sources] = list()
     self.hooks: List[DiscordWebHooks] = list()
     self.sourceEnabled: bool = False
     self.outputDiscord: bool = False
     self.checkEnv(self.siteName)
     pass
コード例 #11
0
 def __init__(self) -> None:
     self.logger = Logger(__class__)
     self.uri = "https://www.instagram.com/"
     self.baseUri = self.uri
     self.siteName: str = "Instagram"
     self.links: List[Sources] = list()
     self.hooks: List[DiscordWebHooks] = list()
     self.sourceEnabled: bool = False
     self.outputDiscord: bool = False
     self.currentLink: Sources = Sources()
     self.checkEnv(self.siteName)
     pass
コード例 #12
0
ファイル: ffxiv.py プロジェクト: jtom38/newsbot
 def __init__(self) -> None:
     self.logger = Logger(__class__)
     self.uri: str = "https://na.finalfantasyxiv.com/lodestone/news/"
     self.baseUri: str = "https://na.finalfantasyxiv.com"
     self.siteName: str = "Final Fantasy XIV"
     self.authorName: str = "Final Fantasy XIV Offical Site"
     self.links = list()
     self.hooks = list()
     self.sourceEnabled: bool = False
     self.outputDiscord: bool = False
     self.checkEnv(self.siteName)
     pass
コード例 #13
0
ファイル: youtube.py プロジェクト: jtom38/newsbot
    def __init__(self):
        self.logger= Logger(__class__)
        self.uri: str = "https://youtube.com"
        self.siteName: str = "Youtube"
        self.feedBase: str = "https://www.youtube.com/feeds/videos.xml?channel_id="

        self.links: List[Sources] = list()
        self.hooks: List[DiscordWebHooks] = list()

        self.sourceEnabled: bool = False
        self.outputDiscord: bool = False

        self.checkEnv(self.siteName)
        pass
コード例 #14
0
 def searchForUser(self, auth: TwitchAuth, username: str = "") -> None:
     if username == "":
         Logger().error(
             f"Request to search for user was requested but no user was given."
         )
     else:
         uri: str = f"{self.apiUri}/search/channels?query={username}"
         header = self.__header__(auth)
         res = get(uri, headers=header)
         if res.status_code != 200:
             Logger().error(
                 f"Attempted to pull user information but failed. status_code: {res.status_code}, output: {res.text}"
             )
         else:
             l = list()
             j = loads(res.content)
             for i in j["data"]:
                 # Convert the Json date to an object
                 stream = TwitchChannel(i)
                 # Get the game details
                 # stream.game_data = self.getGame(auth,stream.game_id)
                 # video = self.getVideos(auth=auth, user_id=stream.id)
                 l.append(stream)
             return l
コード例 #15
0
    def getGame(self, auth: TwitchAuth, game_id: int) -> TwitchGameData:
        uri = f"{self.apiUri}/games?id={game_id}"
        headers = self.__header__(auth)
        res = get(uri, headers=headers)

        if res.status_code != 200:
            Logger().error(
                f"Attempted to get Twich Game data but failed on game_id: {game_id}. output: {res.text}"
            )
            return TwitchGameData()
        else:
            j = loads(res.content)
            if len(j["data"]) != 0:
                game = TwitchGameData(j["data"][0])
            else:
                game = TwitchGameData()
            return game
コード例 #16
0
    def auth(self) -> TwitchAuth:
        """
        https://dev.twitch.tv/docs/authentication/getting-tokens-oauth#oauth-client-credentials-flow
        """
        client_id = str(getenv("NEWSBOT_TWITCH_CLIENT_ID"))
        client_secret = str(getenv("NEWSBOT_TWITCH_CLIENT_SECRET"))
        scopes = "user:read:email"
        uri = f"https://id.twitch.tv/oauth2/token?client_id={client_id}&client_secret={client_secret}&grant_type=client_credentials&scopes={scopes}"

        res = post(uri)
        if res.status_code != 200:
            Logger().error(res.text)
            return TwitchAuth()
        else:
            token = loads(res.content)
            o = TwitchAuth(
                access_token=token["access_token"],
                expires_in=token["expires_in"],
                token_type=token["token_type"],
                client_id=client_id,
            )
            return o
コード例 #17
0
    def getVideos(self,
                  auth: TwitchAuth,
                  id: int = 0,
                  user_id: int = 0,
                  game_id: int = 0) -> List[TwitchVideo]:
        uri = f"{self.apiUri}/videos"
        if id != 0:
            uri = f"{uri}?id={id}"
        elif user_id != 0:
            uri = f"{uri}?user_id={user_id}"
        elif game_id != 0:
            uri = f"{uri}?game_id={game_id}"

        res = get(uri, headers=self.__header__(auth))
        videos = list()
        if res.status_code != 200:
            Logger().error(f"Failed to request videos")
            return videos
        else:
            json = loads(res.content)
            for i in json["data"]:
                videos.append(TwitchVideo(i))
            return videos
コード例 #18
0
ファイル: discord.py プロジェクト: jtom38/newsbot
 def __init__(self) -> None:
     self.logger = Logger(__class__)
     self.table = DiscordQueue()
     self.tempMessage: DiscordWebhook = DiscordWebhook("placeholder")
     pass
コード例 #19
0
 def __init__(self, source: ISources):
     self.logger = Logger(__class__)
     self.source: ISources = source
     self.enabled: bool = False
     pass
コード例 #20
0
ファイル: requestContent.py プロジェクト: jtom38/newsbot
 def __init__(self, url: str = "") -> None:
     self.url = url
     self.logger = Logger(__class__)
     pass
コード例 #21
0
 def __init__(self) -> None:
     self.logger = Logger(__class__)
     self.uri: str = ""
     self.driver = self.driverStart()
     pass