コード例 #1
0
ファイル: libmesh.py プロジェクト: donyab/dnevnik
    def Open(self):
        ps = self._ps
        params = {
            "userId": self._user_id,
            "profileId": self._profile_id,
            "authToken": self._auth_token
        }

        r = my_get_post(ps.get,
                        "https://uchebnik.mos.ru/authenticate",
                        params=params)
        uchebnik_ref = r.request.url
        opts = {"auth_token": self._auth_token}
        r = my_get_post(ps.post,
                        "https://uchebnik.mos.ru/api/sessions",
                        json=opts,
                        headers={
                            "referer": uchebnik_ref,
                            "Accept": "application/json; charset=UTF-8"
                        })
        ps.cookies['auth_token'] = self._auth_token

        r = my_get_post(ps.get,
                        "https://uchebnik.mos.ru/api/users/" +
                        str(self._user_id),
                        headers={"referer": uchebnik_ref})
        pdb.set_trace()
        pass
コード例 #2
0
ファイル: pguauth.py プロジェクト: Otken/dnevnik
    def ForceAuthenticate(self):
        try:
            ps = self._ps
            r = my_get_post(ps.get, "https://www.mos.ru")
            #print(r)
            #print("cookies:")
            #print_dict(r.cookies)
            ps.cookies.update(r.cookies)
            r = my_get_post(
                ps.get,
                "https://www.mos.ru/api/oauth20/v1/frontend/json/ru/process/enter"
            )
            ps.cookies.update(r.cookies)
            r = my_get_post(ps.get, r.headers['Location'])
            ps.cookies.update(r.cookies)
            r = my_get_post(ps.get, r.headers['Location'])
            ps.cookies.update(r.cookies)
            r = my_get_post(ps.get, r.headers['Location'])

            login_data = {
                'j_username': self._cfg.login,
                'j_password': self._cfg.password,
                'accessType': 'alias'
            }

            r = my_get_post(ps.post,
                            "https://oauth20.mos.ru/sps/j_security_check",
                            data=login_data)

            self.token = self._ps.cookies['Ltpatoken2']

            self._ps.cookies.update(r.cookies)
            r = my_get_post(self._ps.get, r.headers['Location'])  # wsauth
            self._ps.cookies.update(r.cookies)
            r = my_get_post(self._ps.get,
                            r.headers['Location'])  # result?code=XXX
            self.mostoken = self._ps.cookies['mos_oauth20_token']

            with open("cookies/sudirtokenexp", "w") as t:
                t.write(self._ps.cookies['sudirtokenexp'])
            with open("cookies/JSESSIONID", "w") as t:
                t.write(self._ps.cookies['JSESSIONID'])
            with open("cookies/OAUTH20-PHPSESSID", "w") as t:
                t.write(self._ps.cookies['OAUTH20-PHPSESSID'])
            with open("cookies/mos_oauth20_token", "w") as t:
                t.write(self.mostoken)
            with open("cookies/Ltpatoken2", "w") as t:
                t.write(self.token)

#            print_dict(self._ps.cookies)
#            pdb.set_trace()

#print("mostoken : " ,self.mostoken)

            self.Authenticated = self.mostoken != ""
            #print("Authenticated:", self.Authenticated)
        except:
            self.Authenticated = False

        return self.Authenticated
コード例 #3
0
ファイル: dnevnik.py プロジェクト: Otken/dnevnik
    def GetHomework(self, year_id, student_id, begin_date, end_date):
        ps = self._ps

        params = {
            "academic_year_id": year_id,
            "begin_date": begin_date,
            "end_date": end_date,
            "pid": self._pid,
            "student_profile_id": student_id
        }

        r = my_get_post(ps.get,
                        f"https://dnevnik.mos.ru/core/api/student_homeworks",
                        headers=self._sh,
                        params=params)

        j = json.loads(r.text)

        for h in j:
            cr = parse(h['homework_entry']['created_at'])
            dt_assigned = parse(
                h['homework_entry']['homework']['date_assigned_on'])
            if cr > dt_assigned + datetime.timedelta(days=2):
                h['fair'] = False
            else:
                h['fair'] = True
        return j

        pass
コード例 #4
0
    def SelectProfile(self, p):
        """ Select profile """
        """ POST https://www.mos.ru/pgu/ru/application/dogm/journal/ """
        ps = self._ps
        params = {
            "ajaxAction": "get_token",
            "ajaxModule": "DogmJournal",
            "data[login]": p.login,
            "data[pass]": p.password,
            "data[system]": p.system
        }
        ps.cookies["elk_token"] = "null" + "|" + self._pgu_mos_ru_token
        ps.cookies["elk_id"] = ""
        print("cookies:")
        print_dict(ps.cookies)
        print("params:")
        print_dict(params)
        ps.headers.update(
            {'referer': "https://www.mos.ru/pgu/ru/application/dogm/journal/"})

        r = my_get_post(ps.post,
                        "https://pgu.mos.ru/ru/application/dogm/journal/",
                        data=params)
        print("Diary auth token:")
        print(r.text)
        pass
        """ https://dnevnik.mos.ru/lms/api/sessions """
コード例 #5
0
ファイル: libmesh.py プロジェクト: donyab/dnevnik
    def DownloadComposedDocument(self, id):
        ps = self._ps
        params = {}
        pdb.set_trace()
        r = my_get_post(
            ps.get,
            "https://uchebnik.mos.ru/api/subjects?with_controllable_items=true",
            headers={"Accept": "application/vnd.api.v1+json"})
        #r=my_get_post(ps.get, "https://uchebnik.mos.ru/cms/api/composed_documents/"+str(id), params=params)

        pass
コード例 #6
0
ファイル: dnevnik.py プロジェクト: Otken/dnevnik
    def ListStudents(self):
        ps = self._ps
        headers = {
            "referer": "https://dnevnik.mos.ru/desktop",
            "Accept": "application/json",
            "Profile-Id": self._pid
        }

        r = my_get_post(
            ps.get,
            f"https://dnevnik.mos.ru/acl/api/users?ids={self._ids}&pid={self._pid}",
            headers=headers)

        j = json.loads(r.text)
        result = []
        r = my_get_post(
            ps.get,
            "https://dnevnik.mos.ru/core/api/student_profiles?pid={self._pid}",
            headers=headers)
        j = json.loads(r.text)
        return j
コード例 #7
0
ファイル: dnevnik.py プロジェクト: Otken/dnevnik
    def OpenDiary(self, student_id):
        ps = self._ps

        self._sh = {
            "referer":
            f"https://dnevnik.mos.ru/manage/student_journal/{student_id}",
            "Accept": "application/vnd.api.v3+json",
            "Auth-Token": self._auth_token,
            "Profile-Id": self._pid
        }

        r = my_get_post(
            ps.get,
            f"https://dnevnik.mos.ru/manage/student_journal/{student_id}")
        r = my_get_post(
            ps.post,
            f"https://dnevnik.mos.ru/lms/api/sessions?pid={self._pid}",
            headers=self._sh)
        self._sh["Accept"] = "application/json"
        self.LoadGroups(student_id)
        self.LoadSchedule(student_id)
        return
コード例 #8
0
ファイル: dnevnik.py プロジェクト: Otken/dnevnik
    def SelectAcademicYear(self, year_id):
        ps = self._ps
        year_id = str(year_id)

        ps.headers["Auth-Token"] = self._auth_token
        ps.cookies["authtype"] = "1"
        ps.cookies["aid"] = year_id
        ps.cookies["auth_token"] = self._auth_token
        ps.cookies["is_auth"] = "true"
        ps.cookies["profile_id"] = self._pid
        r = my_get_post(ps.get,
                        "https://dnevnik.mos.ru/desktop",
                        headers={"referer": self.dnevnik_top_referer})

        opts = {"auth_token": self._auth_token}
        r = my_get_post(
            ps.post,
            f"https://dnevnik.mos.ru/lms/api/sessions?pid={self._profile['profiles'][0]['id']}",
            json=opts,
            headers={"referer": "https://dnevnik.mos.ru/desktop"})

        pass
コード例 #9
0
ファイル: dnevnik.py プロジェクト: Otken/dnevnik
 def LoadGroups(self, student_id):
     ps = self._ps
     params = {
         "academic_year_id": "6",
         "pid": self._pid,
         "with_archived_groups": "true",
         "with_groups": "true"
     }
     r = my_get_post(
         ps.get,
         f"https://dnevnik.mos.ru/core/api/student_profiles/{student_id}",
         headers=self._sh,
         params=params)
     self.groups = json.loads(r.text)['groups']
     pass
コード例 #10
0
ファイル: dnevnik.py プロジェクト: Otken/dnevnik
    def LoadSchedule(self, student_id):
        ps = self._ps
        gs = []
        for g in self.groups:
            gs.append(str(g['id']))
        params = {"group_ids": ','.join(gs), "pid": self._pid}
        r = my_get_post(ps.get,
                        f"https://dnevnik.mos.ru/jersey/api/groups",
                        headers=self._sh,
                        params=params)
        self.schedule = json.loads(r.text)

        self.sched_dict = {}
        for s in self.schedule:
            self.sched_dict[s['id']] = s
        pass
コード例 #11
0
    def Authenticate(self):
        try:
            ps = self._ps
            r = my_get_post(ps.get, "https://www.mos.ru")
            #print(r)
            #print("cookies:")
            #print_dict(r.cookies)
            ps.cookies.update(r.cookies)
            r = my_get_post(
                ps.get,
                "https://www.mos.ru/api/oauth20/v1/frontend/json/ru/process/enter"
            )
            ps.cookies.update(r.cookies)
            r = my_get_post(ps.get, r.headers['Location'])
            ps.cookies.update(r.cookies)
            r = my_get_post(ps.get, r.headers['Location'])
            ps.cookies.update(r.cookies)
            r = my_get_post(ps.get, r.headers['Location'])

            login_data = {
                'j_username': self._cfg.login,
                'j_password': self._cfg.password,
                'accessType': 'alias'
            }

            r = my_get_post(ps.post,
                            "https://oauth20.mos.ru/sps/j_security_check",
                            data=login_data)

            self.token = self._ps.cookies['Ltpatoken2']
            self._ps.cookies.update(r.cookies)
            r = my_get_post(self._ps.get, r.headers['Location'])  # wsauth
            self._ps.cookies.update(r.cookies)
            r = my_get_post(self._ps.get,
                            r.headers['Location'])  # result?code=XXX
            self.mostoken = self._ps.cookies['mos_oauth20_token']
            #print("mostoken : " ,self.mostoken)

            self.Authenticated = self.mostoken != ""
            #print("Authenticated:", self.Authenticated)
        except:
            self.Authenticated = False

        return self.Authenticated
コード例 #12
0
ファイル: dnevnik.py プロジェクト: Otken/dnevnik
    def GetMarks(self, student_id, created_from, created_to):
        ps = self._ps

        params = {
            "created_at_from": created_from,
            "created_at_to": created_to,
            "page": "1",
            "per_page": "50",
            "pid": self._pid,
            "student_profile_id": student_id
        }
        r = my_get_post(ps.get,
                        "https://dnevnik.mos.ru/core/api/marks",
                        params=params,
                        headers=self._sh)
        j = json.loads(r.text)

        return j
コード例 #13
0
ファイル: dnevnik.py プロジェクト: Otken/dnevnik
    def Authenticate(self):
        """ authentication to PGU """
        if not self._auth.Authenticated:
            self._auth.Authenticate()

        self._ps = self._auth._ps
        ps = self._ps
        #        pdb.set_trace()
        ps.cookies["mos_id"] = "CllGxlmW7RAJKzw/DJfJAgA="

        milisecs = calendar.timegm(time.gmtime()) * 1000 + random.randint(
            0, 999) + 1
        r = my_get_post(
            ps.get, "https://my.mos.ru/static/xdm/index.html?nocache=" +
            str(milisecs) +
            "&xdm_e=https%3A%2F%2Fwww.mos.ru&xdm_c=default1&xdm_p=1")
        ps.cookies.update(r.cookies)
        r = my_get_post(ps.get, r.headers['Location'])
        ps.cookies.update(r.cookies)
        r = my_get_post(ps.get, r.headers['Location'])
        ps.cookies.update(r.cookies)
        r = my_get_post(ps.get, r.headers['Location'])
        ps.cookies.update(r.cookies)

        # system_id: mos.ru
        r = my_get_post(
            ps.get,
            "https://www.mos.ru/api/oauth20/v1/frontend/json/ru/options")
        opts = json.loads(r.text)

        # надо: nonce signature timestamp
        #print("token request cookies:")
        #print_dict(ps.cookies)
        token_data = {
            "system_id": opts["elk"]["system_id"],
            "nonce": opts["elk"]["nonce"],
            "timestamp": opts["elk"]["timestamp"],
            "signature": opts["elk"]["signature"]
        }
        ps.cookies["mos_user_segment"] = "default"
        r = my_get_post(ps.post, self._data_url + "token", data=token_data)

        self._mos_ru_token = json.loads(r.text)["token"]

        r = my_get_post(ps.get, "https://www.mos.ru/")
        ps.cookies.update(r.cookies)
        ps.cookies["mos_user_segment"] = "default"
        r = my_get_post(
            ps.get,
            "https://www.mos.ru/pgu/ru/application/dogm/journal/?onsite_from=popular",
            headers={"referer": "https://www.mos.ru/"})
        # expect 301 redirect https://www.mos.ru/pgu/ru/application/dogm/journal/?onsite_from=popular
        ps.cookies.update(r.cookies)

        # obtain PHPSESSID
        # 302 redirect to https://oauth20.mos.ru/sps/oauth/oauth20/authorize
        r = my_get_post(ps.get, r.headers['Location'])
        ps.cookies.update(r.cookies)
        # 302 redirect to https://www.mos.ru/pgu/ru/oauth/?code=74...
        r = my_get_post(ps.get, r.headers['Location'])
        ps.cookies.update(r.cookies)
        # 200 redirect to https://www.mos.ru/pgu/ru/services/link/2103/?onsite_from=3532
        r = my_get_post(ps.get, r.headers['Location'])
        ps.cookies.update(r.cookies)

        r = my_get_post(ps.get,
                        "https://www.mos.ru/pgu/ru/application/dogm/journal/")

        self.dnevnik_top_referer = r.headers['Location']

        # 200 redirect to https://www.mos.ru/pgu/ru/services/link/2103/?onsite_from=3532
        r = my_get_post(ps.get, r.headers['Location'])

        # Тут мы в https://dnevnik.mos.ru/?token=64749fb9596a7f2078090a894ab31452
        m = re.search('.*token=(.*)', self.dnevnik_top_referer)
        self._auth_token = m.group(1)

        opts = {"auth_token": self._auth_token}

        r = my_get_post(ps.post,
                        "https://dnevnik.mos.ru/lms/api/sessions",
                        headers={"referer": self.dnevnik_top_referer},
                        json=opts)

        self._profile = json.loads(r.text)
        self._pid = str(self._profile["profiles"][0]["id"])
        self._ids = str(self._profile["profiles"][0]["user_id"])
        self.Authenticated = self._auth_token != ""
        return self.Authenticated