Exemplo n.º 1
0
 def checkResponse(self, r, statusCodePass=200, statusCodeFail=0):
     if r == None:
         raise kahootError.kahootError(self.variables.domain +
                                       ' returned nothing')
     if (r.status_code != statusCodePass) and (r.status_code !=
                                               statusCodeFail):
         raise kahootError.kahootError(self.variables.domain +
                                       ' returned http error code ' +
                                       str(r.status_code))
     return r
 def __init__(self, pin, **kwargs):
     if isinstance(pin, int):
         self.pin = pin
     else:
         raise kahootError.kahootError('pin is not an int value')
     self.debugLevel = int(kwargs['debug']) if 'debug' in kwargs else 0 #1 = some, 2 = most
     self.debug = bool(self.debugLevel != 0)
     self.verify = bool(kwargs['verify']) if 'verify' in kwargs else True
     self.timeoutTime = float(kwargs['timeout']) if 'timeout' in kwargs else 2.0
     self.isUser = bool(kwargs['isUser']) if 'isUser' in kwargs else False
     self.name = ''
     self.domain = 'kahoot.it'
     self.httpSession = requests.Session()
     self.headers = {
         'Content-Type': 'application/json;charset=UTF-8',
         'Accept': 'application/json, text/plain, */*',
         'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko',
         'Accept-Language': 'en-US,en;q=0.5',
         'DNT': '1',
         'Referer':'https://'+self.domain
         }
     self.kahootSession = ''
     self.kahootChallenge = ''
     self.clientid = ''
     self.subId = 1
     self.ackId = 1
     self.o = 0
     self.l = 0
     self.tc = 0
     self.ts = 0
     self.connectedClient = False
     self.clientAttempted = False
     self.currentQuestion = 0
 def testSession(self, r):
     try:
         if (r.status_code == 404):
             return False
         data = json.loads(r.text)
         if data['twoFactorAuth'] == False:
             chal_r = self.computeChallenge(data['challenge'])
             if chal_r == False:
                 chal_r = self.send.solveKahootChallenge(data['challenge'])
             if self.variables.debug:
                 print("challenge:", chal_r)
             self.variables.setChallenge(chal_r)
             self.solveChallenge(r.headers['x-kahoot-session-token'])
             return True
         else:
             raise kahootError.kahootError('two factor not implemented')
     except Exception as e:
         raise kahootError.kahootError('receive.testSession error, r: ' +
                                       str(r))
         return False
Exemplo n.º 4
0
 def processResponse(self, r, statusCodePass=200):
     if r.status_code != statusCodePass:
         raise kahootError.kahootError(r.url +
                                       ' returned http error code ' +
                                       str(r.status_code))
     try:
         response = json.loads(r.text)
         for x in response:
             if "successful" in x:
                 if x["successful"] != True:
                     raise kahootError.kahootError(
                         r.url + ' returned an unsuccessful response')
             if ('ext' in x) and ('timesync' in x['ext']):
                 self.variables.setPrevTcl(x['ext']['timesync'])
         return response
     except Exception as e:
         if self.variables.debugLevel > 2:
             print(e)
             print(r.text)
         raise kahootError.kahootError('The response from ' + r.url +
                                       ' was unparseable')
 def id_error(self, dataContent):
     if self.variables.debug:
         print("id: ", dataContent['id'])
         raise kahootError.kahootError('cannot find ID from ' +
                                       self.variables.domain)