-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
103 lines (95 loc) · 2.59 KB
/
index.php
File metadata and controls
103 lines (95 loc) · 2.59 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
require(__DIR__.'/config.php');
if (!in_array(PHP_SAPI, $C["allowsapi"])) {
exit("No permission");
}
require(__DIR__.'/curl.php');
$post = array(
"uid" => $C["uid"],
"pwd" => $C["pwd"]
);
$res = cURL($C["url1"], $post, $C["cookiepath"]);
if ($res === false) {
exit("fetch fail\n");
}
$post = array(
"arg01" => $C["year"],
"arg02" => $C["semester"]
);
$res = cURL($C["url2"], $post, $C["cookiepath"]);
if ($res === false) {
exit("fetch fail\n");
}
$res = html_entity_decode($res);
$data = @file_get_contents($C["datapath"]);
if ($data === false) {
$data = [];
} else {
$data = json_decode($data, true);
}
$message = "";
if (preg_match_all("/<td align=left>([^<]+)<\/td><td>([^<]+)<\/td><td>([^<]+)<\/td><td>([^<]+)<\/td><td>([^<]+)<\/td><td>([^<]+)<\/td><td>([^<]+)/", $res, $m)) {
foreach ($m[0] as $key => $value) {
$class = trim($m[1][$key], " \t\n\r\0\x0B\xC2\xA0");
$score = (double)(trim($m[7][$key], " \t\n\r\0\x0B\xC2\xA0"));
if (!isset($data[$class])) {
$data[$class] = $score;
} else if ($data[$class] != $score) {
echo $class." update to ".$score."\n";
$data[$class] = $score;
if ($score == 0) {
$message .= $class." 的成績已取消公布\n";
} else {
$message .= $class." 的成績已公布\n";
}
} else {
echo $class." is ".$score."\n";
}
}
} else {
echo "match fail 1\n";
}
if (preg_match("/操行成績:(.*?) 總平均:(.*?) 班名次\/班人數:(.*?)\/.*? 班名次百分比:(.*?)%/", $res, $m)) {
$name = ["", "操行成績", "總平均", "班名次", "班名次百分比"];
for ($i=1; $i <= 4; $i++) {
$class = $name[$i];
$score = (double)($m[$i]);
if (!isset($data[$class])) {
$data[$class] = $score;
} else if ($data[$class] != $score) {
echo $class." update to ".$score."\n";
$data[$class] = $score;
if ($score == 0) {
$message .= $class." 已取消公布\n";
} else {
$message .= $class." 已公布\n";
}
} else {
echo $class." is ".$score."\n";
}
}
} else {
echo "match fail 2\n";
}
file_put_contents($C["datapath"], json_encode($data, 256));
if ($message != "") {
$message .= "\n本訊息是程式自動發送,由 https://github.com/Xi-Plus/NKUST-Score 驅動";
echo $message."\n";
if ($C['sendFB']) {
echo "send to FB\n";
$post = array(
"message" => $message,
"access_token" => $C['FBtoken']
);
$res = cURL($C['FBAPI']."me/feed", $post);
}
if ($C['sendTG']) {
echo "send to TG\n";
$post = array(
"chat_id" => $C['TGchatid'],
"text" => $message,
"disable_web_page_preview" => '1'
);
$res = cURL($C['TGAPI']."sendMessage", $post);
}
}