Skip to content
This repository has been archived by the owner on Dec 24, 2024. It is now read-only.

Commit

Permalink
0.9.8
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukasa0220 authored Mar 6, 2023
1 parent 97a4bf5 commit 66183f4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 17 deletions.
5 changes: 4 additions & 1 deletion extrack.gs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ function cheerio($, className, option, val) {
function parse(html, start, end) {
return Parser.data(html).from(start).to(end).iterate(); // 配列
}
function parse_one(html, start, end) {
return Parser.data(html).from(start).to(end).build(); //単体
}

// 1つに統合
function conbine(title, component, eventtype, courseid, eventlink, description, eventtime, subject) {
return `<h2><font color="darkorange">Kadai-Calendar </font><font color="#9acd32">Ver${VERSION}</font></h2><br>` +
`<h4><font color="#9acd32">★</font> <font color="#ff8c00">${event_link(component, eventlink)}</font></h4><br>` +
      `<h4><font color="#9acd32">★</font> <font color="#ff8c00">${event_link(component, eventlink)}</font></h4><br>` +
`<b><font color="#add8e6">============================</font></b><br>` +
`<font color="#9acd32">■</font>${event_type(eventtype)}${time_change(eventtime)}<br>` +
`<font color="#9acd32">■</font>時間割名:<font color="#ff8c00"><a href="https://kadai-moodle.kagawa-u.ac.jp/course/view.php?id=${courseid}">${subject}</a></font><br>` +
Expand Down
8 changes: 5 additions & 3 deletions login_after.html
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,12 @@ <h1 class="h2 card-header text-center">Kadai-Calendar<div id="version"></div></h
// カレンダー更新の処理結果
function update_calendar_result(n){
const inResponse = document.getElementById('inResponse');
if (n[0] == -1) {
if (n[0] === -1) {
inResponse.innerHTML = `<div id="error" class="loginerrors mt-3"><div class="alert alert-danger" role="alert" data-aria-autofocus="true"><center>すでに登録が解除されています ページを更新してください</center></div></div>`;
} else if (n[0] == false) {
} else if (n[0] === false) {
inResponse.innerHTML = `<div id="error" class="loginerrors mt-3"><div class="alert alert-danger" role="alert" data-aria-autofocus="true"><center>アクセスエラー:Moodleにアクセスできません</center></div></div>`;
} else if (n[0] === 0) {
inResponse.innerHTML = `<center><div class="mt-3 alert-success">追加するイベントはありません。</div></center>`;
} else {
inResponse.innerHTML = `<center><div class="mt-3 alert-success">${n[0]}個のイベントを追加しました。</div></center>`;
// document.getElementById('inCalendar').innerHTML = `<iframe src="https://calendar.google.com/calendar/embed?src=${n[1]}&ctz=Asia%2FTokyo" style="border: 0" width="800" height="600" frameborder="0" scrolling="no"></iframe>`;
Expand All @@ -91,7 +93,7 @@ <h1 class="h2 card-header text-center">Kadai-Calendar<div id="version"></div></h
// ログアウトの処理結果
function logout_result(n) {
const inResponse = document.getElementById('inResponse');
if (n == -1) {
if (n === -1) {
inResponse.innerHTML = `<div id="error" class="loginerrors mt-3"><div class="alert alert-danger" role="alert" data-aria-autofocus="true"><center>すでに登録が解除されています ページを更新してください</center></div></div>`;
} else {
inResponse.innerHTML = `<center><div class="mt-3 alert-success">登録を解除しました ページを更新してください</div></center>`;
Expand Down
2 changes: 1 addition & 1 deletion login_before.html
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ <h1 class="h2 card-header text-center">Kadai-Calendar<div id="version"></div></h
// ログイン処理結果
function login_result(n){
const inResponse = document.getElementById('inResponse');
if (n == -1) {
if (n === -1) {
inResponse.innerHTML = '<div id="error" class="loginerrors mt-3"><div class="alert alert-danger" role="alert" data-aria-autofocus="true"><center>すでに登録が完了しています ページを更新してください</center></div></div>';
} else if (n) {
inResponse.innerHTML = '<center><div class="mt-3 alert-success">登録されました ページを更新してください</div></center>';
Expand Down
7 changes: 2 additions & 5 deletions main.gs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function main (username, password) {

// extrack.gsで取得した直近イベントのHTML文字列をパースしてID、タイトル、期限、科目、URL(共通部分は除去)を抜き出す
const eventsObj = extrack(eventHtml);
if (eventsObj == null) {return -1;}
if (eventsObj == null) {return 0;}

// calendar.gsの処理
const addEventNumber = calendar(eventsObj);
Expand All @@ -16,10 +16,7 @@ function main (username, password) {
function auto_update_main() {
const userProperties = PropertiesService.getUserProperties();
const add = main(userProperties.getProperty('username'), userProperties.getProperty('password'));
if (add == -1) {
Logger.log(0);
}
else if (add == false) {
if (add === false) {
Logger.log("アクセスエラー");
} else {
Logger.log(add);
Expand Down
37 changes: 32 additions & 5 deletions moodle.gs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ class CookieUtil {

// moodleへのログイン処理
function moodle_login(username, password) {
let response, cookies, data, $, headers, payload, options, moodleSession;
let response, cookies, data, $, headers, payload, options, moodleSession, sesskey;

// ログインページを開く(GET) <200>
headers = {
'user-agent': USER_AGENT,
}
options = {
'method': 'get',
'headers': headers,
'muteHttpExceptions': true,
"validateHttpsCertificates" : false,
"followRedirects" : false,
'validateHttpsCertificates' : false,
'followRedirects' : false,
}
try {
response = UrlFetchApp.fetch(LOGIN_URL, options);
Expand Down Expand Up @@ -64,6 +65,7 @@ function moodle_login(username, password) {
'method': 'post',
'headers': headers,
'payload': payload,
'validateHttpsCertificates' : false,
'followRedirects': false,
}
response = UrlFetchApp.fetch(LOGIN_URL, options);
Expand Down Expand Up @@ -92,13 +94,38 @@ function moodle_login(username, password) {
options = {
'method': 'get',
'headers': headers,
'validateHttpsCertificates' : false,
'followRedirects': false,
}
response = UrlFetchApp.fetch(CALENDAR_URL, options);

// 得られたレスポンスが、カレンダーのソースか[class=".eventlist"]で判断、ある場合はその入れ子であるHTMLソースを返す
 // 得られたレスポンスが、カレンダーのソースか[class=".eventlist"]で判断、ある場合はその入れ子であるHTMLソースを返す
data = response.getContentText("UTF-8");
$ = Cheerio.load(data);

// ログアウトkeyを取得
sesskey = parse_one(data, '"sesskey":"', '",');

Utilities.sleep(300);

// ログアウトする <303>
headers = {
'cookie': moodleSession,
'user-agent': USER_AGENT,
}
payload = {
'sesskey': sesskey,
}
options = {
'method': 'get',
'headers': headers,
'payload': payload,
'validateHttpsCertificates' : false,
'followRedirects' : false,
}
response = UrlFetchApp.fetch(LOGOUT_URL, options);

if ($('.eventlist').html()) {return $('.eventlist').html();}
Logger.log("失敗[003]");
Logger.log("取得失敗");
return false;
}
5 changes: 3 additions & 2 deletions property.gs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
// Parser : 1Mc8BthYthXx6CoIz90-JiSzSafVnT6U3t0z_W3hLTAX5ek4w0G_EIrNw

// バージョン
const VERSION = '0.9.6';
const VERSION = '0.9.8';

// MoodleのURL
const LOGIN_URL = 'https://kadai-moodle.kagawa-u.ac.jp/login/index.php';
const CALENDAR_URL = 'https://kadai-moodle.kagawa-u.ac.jp/calendar/view.php?view=upcoming&course=1';
const LOGOUT_URL = 'https://kadai-moodle.kagawa-u.ac.jp/login/logout.php';

// ブラウザにからアクセスしているかのように偽装(一応マクロ対策)
// ブラウザにからアクセスしているかのように偽装(一応マクロ対策)→追記:できないっぽい
const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36 Edg/110.0.1587.56';

0 comments on commit 66183f4

Please sign in to comment.