Ejemplo n.º 1
0
 def redeem(self, code, platform):
     found, status_code, form_data = self.__get_redemption_form(
         code, platform)
     # the expired message comes from even wanting to redeem
     if not found and form_data == "This SHiFT code has already been redeemed":
         status = Status.REDEEMED
         result = "Already Redeemed"
     elif not found:
         # entered key was invalid
         if status_code == 500:
             return Status.INVALID
         # entered key expired by now
         if "expired" in form_data:
             return Status.EXPIRED
         if "not available" in form_data:
             return Status.INVALID
         # unknown
         _L.error(form_data)
         return Status.UNKNOWN
     else:
         # the key is valid and all.
         status, result = self.__redeem_form(form_data)
     self.last_status = status
     _L.debug("{}: {}".format(Status(status), result))
     return status
Ejemplo n.º 2
0
def parse_keys(game, platform):
    if game not in games:
        _L.error("No known method of retrieving new SHiFT codes "
                 "for the game `{}`".format(game))
        return

    for code in game_funcs[game](game, platform):
        insert(*code)
Ejemplo n.º 3
0
    def __init__(self, user: str = None, pw: str = None):
        from os import path
        self.client = requests.session()
        self.last_status = Status.NONE
        self.cookie_file = path.join(DIRNAME, "data", ".cookies.save")
        # try to load cookies. Query for login data if not present
        if not self.__load_cookie():
            print("First time usage: Login to your SHiFT account...")
            if not user:
                user = input("Username: "******"Password: "******"Login Successful")
            else:
                _L.error("Couldn't login. Are your credentials correct?")
                exit(0)
Ejemplo n.º 4
0
    def redeem(self, code):
        found, status_code, form_data = self.__get_redemption_form(code)
        # the expired message comes from even wanting to redeem
        if not found:
            # entered key was invalid
            if status_code == 500:
                return Status.INVALID
            # entered key expired by now
            if "expired" in form_data:
                return Status.EXPIRED
            # unknown
            _L.error(form_data)
            return Status.UNKNOWN

        # the key is valid and all.
        status, result = self.__redeem_form(form_data)
        self.last_status = status
        _L.debug("{}: {}".format(Status(status), result))
        return status