forked from Nockiro/Duolingo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
learnsession.py
50 lines (38 loc) · 1.68 KB
/
learnsession.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import json
from duorequest import DuoRequest
from lschallenge import DuolingoLearnSessionChallenge
from collections import namedtuple
import datetime
import time
__DEBUG__ = False
learn_session_data_url = "https://www.duolingo.com/2017-06-30/sessions"
class DuolingoLearnSession(object):
def __init__(self, session, jsonResponseData):
self.session = session
self.learn_session_data = jsonResponseData
self.learn_session_metadata = self.learn_session_data["metadata"]
self.learn_session_challenge_list = self.learn_session_data["challenges"]
self.learn_session_id = self.learn_session_metadata['id']
self.current_language = self.learn_session_metadata["language_string"]
def fetch(session, data):
""" Set Debug to false to get real server data """
if not __DEBUG__:
learnRequest = DuoRequest.do_request(learn_session_data_url, session, data)
print(learnRequest)
jsonResponseData = learnRequest.json()
else:
jsonResponseData = __sampleData__
return DuolingoLearnSession(session, jsonResponseData)
def get_challenge(self, index):
challenge = DuolingoLearnSessionChallenge(
self.learn_session_challenge_list[index])
return challenge
def get_challenge_list(self):
return self.learn_session_challenge_list
def get_sessionid(self):
return self.learn_session_id
def get_learnsession_data(self):
return self.learn_session_data
def end_session(self, data):
request = DuoRequest.do_request(learn_session_data_url + "/" + self.get_sessionid(), self.session, data, "PUT")
return request