コード例 #1
0
    def __init__(
        self,
        auth_mgr: AuthenticationManager,
        language: XboxLiveLanguage = DefaultXboxLiveLanguages.United_States,
    ):
        self._auth_mgr = auth_mgr
        self.session = Session(auth_mgr)
        self._language = language

        self.cqs = CQSProvider(self)
        self.lists = ListsProvider(self)
        self.profile = ProfileProvider(self)
        self.achievements = AchievementsProvider(self)
        self.usersearch = UserSearchProvider(self)
        self.gameclips = GameclipProvider(self)
        self.people = PeopleProvider(self)
        self.presence = PresenceProvider(self)
        self.message = MessageProvider(self)
        self.userstats = UserStatsProvider(self)
        self.screenshots = ScreenshotsProvider(self)
        self.titlehub = TitlehubProvider(self)
        self.account = AccountProvider(self)
        self.catalog = CatalogProvider(self)
        self.smartglass = SmartglassProvider(self)
        self.clubs = ClubsProvider(self)
コード例 #2
0
    def __init__(self, email, password):
        self.auth_mgr = AuthenticationManager()

        # set data for auth manager
        self.auth_mgr.email_address = email
        self.auth_mgr.password = password

        # authentication
        self.auth_mgr.authenticate(do_refresh=True)

        # set the new info to a xbl client
        self.xbl_client = XboxLiveClient(self.auth_mgr.userinfo.userhash,
                                         self.auth_mgr.xsts_token.jwt,
                                         self.auth_mgr.userinfo.xuid)
        # not currently used but could be useful later
        self.profile_provider = ProfileProvider(self.xbl_client)
        self.people_provider = PeopleProvider(self.xbl_client)
コード例 #3
0
    def __init__(self, email, password, x_auth_key):
        self.x_auth_key = x_auth_key
        self.url = 'http://xapi.us/v2'
        self.client = Client(api_key=x_auth_key)

        # use the microsoft api to get the xuid info without using requests
        self.auth_mgr = AuthenticationManager()

        # set data for auth manager
        self.auth_mgr.email_address = email
        self.auth_mgr.password = password

        # authentication
        self.auth_mgr.authenticate(do_refresh=True)

        # set the new info to a xbl client
        self.xbl_client = XboxLiveClient(self.auth_mgr.userinfo.userhash,
                                         self.auth_mgr.xsts_token.jwt,
                                         self.auth_mgr.userinfo.xuid)
        self.profile_provider = ProfileProvider(self.xbl_client)
        self.people_provider = PeopleProvider(self.xbl_client)
コード例 #4
0
    def __init__(self, userhash, auth_token, xuid, language=XboxLiveLanguage.United_States):
        """
        Provide various Web API from Xbox Live

        Args:
            userhash (str): Userhash obtained by authentication with Xbox Live Server
            auth_token (str): Authentication Token (XSTS), obtained by authentication with Xbox Live Server
            xuid (str/int): Xbox User Identification of your Xbox Live Account
            language (str): Member of :class:`XboxLiveLanguage`
        """
        authorization_header = {'Authorization': 'XBL3.0 x=%s;%s' % (userhash, auth_token)}

        self._session = requests.session()
        self._session.headers.update(authorization_header)  # Set authorization header for whole session

        if isinstance(xuid, str):
            self._xuid = int(xuid)
        elif isinstance(xuid, int):
            self._xuid = xuid
        else:
            raise ValueError("Xuid was passed in wrong format, neither int nor string")

        self._lang = language

        self.eds = EDSProvider(self)
        self.cqs = CQSProvider(self)
        self.lists = ListsProvider(self)
        self.profile = ProfileProvider(self)
        self.achievements = AchievementsProvider(self)
        self.usersearch = UserSearchProvider(self)
        self.gameclips = GameclipProvider(self)
        self.people = PeopleProvider(self)
        self.presence = PresenceProvider(self)
        self.message = MessageProvider(self)
        self.userstats = UserStatsProvider(self)
        self.screenshots = ScreenshotsProvider(self)
        self.titlehub = TitlehubProvider(self)
        self.fetch = FetchProvider(self)
コード例 #5
0
class MicrosoftBot:
    def __init__(self, email, password):
        self.auth_mgr = AuthenticationManager()

        # set data for auth manager
        self.auth_mgr.email_address = email
        self.auth_mgr.password = password

        # authentication
        self.auth_mgr.authenticate(do_refresh=True)

        # set the new info to a xbl client
        self.xbl_client = XboxLiveClient(self.auth_mgr.userinfo.userhash,
                                         self.auth_mgr.xsts_token.jwt,
                                         self.auth_mgr.userinfo.xuid)
        # not currently used but could be useful later
        self.profile_provider = ProfileProvider(self.xbl_client)
        self.people_provider = PeopleProvider(self.xbl_client)

    # sends message to list of multiple users
    def send_message(self, message, users):
        response = self.xbl_client.message.send_message(message,
                                                        gamertags=users)

        return response

    # create a function that gets xuids
    def get_xuid(self, gamertag):
        profile = self.profile_provider.get_profile_by_gamertag(
            gamertag).json()
        try:
            xuid = profile['profileUsers'][0]['id']
        except KeyError:
            # this means the gamertag wasn't found
            return

        return xuid

    # create a function to convert xuids back to gamertags
    def get_gamertag(self, xuid):
        profile = self.profile_provider.get_profile_by_xuid(xuid).json()
        try:
            settings = profile['profileUsers'][0]['settings']
        except KeyError:
            time.sleep(61)
            return None
        info_dict = {pair['id']: pair['value'] for pair in settings}
        gamertag = info_dict['Gamertag']

        return gamertag

    # create a method to get the user's friends (use xuids to save time and maximize integration)
    def get_friends(self, gamertag):
        xuid = self.get_xuid(gamertag)
        response_json = self.people_provider.get_friends_by_xuid(xuid).json()

        try:
            friends_raw = response_json['people']
        except KeyError:
            print(f"{gamertag} is a certified loner")
            friends_raw = []
            # this often means that the api is blocking us
            time.sleep(180)

        xuids = {info['xuid'] for info in friends_raw}

        return xuids