Advertisement
MARSHAL327

Untitled

Sep 12th, 2023 (edited)
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
JSON 3.60 KB | None | 0 0
  1. class SevSU_TimeTable {
  2.     constructor() {
  3.         let credentials = {
  4.             username: "u22-00-019777",
  5.             password: "7NmxsNPC",
  6.             credentialId: ''
  7.         }
  8.  
  9.         let headers = {
  10.             "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.5481.78 Safari/537.36",
  11.             "Accept": "*/*",
  12.             "Accept-Encoding": "gzip, deflate, br",
  13.             "Connection": "keep-alive",
  14.         }
  15.  
  16.         let timetable_auth_url = "https://timetable.sevsu.ru/auth/keycloak/redirect";
  17.  
  18.         axios.get(timetable_auth_url, )
  19.         let response = UrlFetchApp.fetch(timetable_auth_url, {followRedirects: false});
  20.         let auth_page_url = response.getAllHeaders()['Location'];
  21.  
  22.         response = UrlFetchApp.fetch(auth_page_url);
  23.         let auth_cookie = response.getAllHeaders()['Set-Cookie'].join('; ');
  24.  
  25.         const authPage = Cheerio.load(response.getContentText());
  26.         let auth_url = authPage('form').attr('action');
  27.  
  28.         let options = {
  29.             method: 'post',
  30.             headers: {
  31.                 'Cookie': auth_cookie,
  32.             },
  33.             payload: credentials,
  34.             followRedirects: false,
  35.         };
  36.         response = UrlFetchApp.fetch(auth_url, options);
  37.         let timetable_auth_page_url = response.getAllHeaders()['Location'];
  38.  
  39.         options = {
  40.             method: "get",
  41.             headers: headers,
  42.             followRedirects: false,
  43.         }
  44.  
  45.         response = UrlFetchApp.fetch(timetable_auth_page_url, options);
  46.  
  47.         this.cookie = response.getAllHeaders()['Set-Cookie'].join('; ');
  48.         let timetable_url = response.getAllHeaders()['Location'];
  49.  
  50.         options = {
  51.             method: "get",
  52.             headers: {
  53.                 ...headers,
  54.                 "Cookie": this.cookie,
  55.             },
  56.             followRedirects: false,
  57.         }
  58.  
  59.         response = UrlFetchApp.fetch(timetable_url, options);
  60.         const ttPage = Cheerio.load(response.getContentText());
  61.         this.data = JSON.parse(ttPage('div.main').attr('wire:initial-data'));
  62.         this.serverMemo = this.data.serverMemo;
  63.         this.csrf = ttPage('meta[name="csrf-token"]').attr('content');
  64.     }
  65.  
  66.     load_week(week_num){
  67.         let admiss_url = "https://timetable.sevsu.ru/livewire/message/student-rasp"
  68.         let options = {
  69.             method: "post",
  70.             headers: {
  71.                 'Cookie': this.cookie,
  72.                 'X-CSRF-TOKEN': this.csrf,
  73.                 'X-Livewire': true,
  74.                 'Accept': 'text/html, application/xhtml+xml',
  75.                 'Content-Type': 'application/json',
  76.                 'Referer': 'https://timetable.sevsu.ru/timetablestudent#close',
  77.             },
  78.             payload: JSON.stringify({
  79.                 ...this.data,
  80.                 updates: [{
  81.                     "type": "fireEvent",
  82.                     "payload": {
  83.                         "id": (Math.random() + 1).toString(36).substring(8),
  84.                         "event": "selectWeek",
  85.                         "params": [
  86.                             "2023-W" + ('00'+week_num).slice(-2)
  87.                         ]
  88.                     }
  89.                 }]
  90.             }),
  91.         }
  92.         let response = UrlFetchApp.fetch(admiss_url, options);
  93.         this.serverMemo = JSON.parse(response).serverMemo;
  94.         return this.currently_seeking_week_data();
  95.     }
  96.  
  97.     get_current_week(){
  98.         return parseInt(this.serverMemo.data.numbr_week);
  99.     }
  100.  
  101.     currently_seeking_week_data() {
  102.         return this.serverMemo.data.usr_tt;
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement