Optimized code
This commit is contained in:
5 files changed
+55
-36
No files matched your search
@@ -35,7 +35,6 @@
|
|||||||
5. 计算百分制 `GPA`
|
5. 计算百分制 `GPA`
|
||||||
6. 对于没有分数仅有级别的成绩,例如”及格、良好、优秀“,可以强制显示数字分数。
|
6. 对于没有分数仅有级别的成绩,例如”及格、良好、优秀“,可以强制显示数字分数。
|
||||||
7. 显示未公布成绩的课程,即已选课但尚未出成绩的课程。
|
7. 显示未公布成绩的课程,即已选课但尚未出成绩的课程。
|
||||||
8. 显示异常的课程,即已出成绩但用户未选课的课程。
|
|
||||||
|
|
||||||
## 使用方法
|
## 使用方法
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[
|
||||||
|
"09975406912bb31cacc59f2573b68768",
|
||||||
|
]
|
||||||
+46
-11
@@ -1,16 +1,51 @@
|
|||||||
|
import os
|
||||||
import requests
|
import requests
|
||||||
|
|
||||||
|
# 定义常量URL
|
||||||
|
AD_URL = "https://raw.githubusercontent.com/NianBroken/ZFCheckScores/main/data/advertise.txt"
|
||||||
|
NO_AD_USERS_LIST_URL = "https://raw.githubusercontent.com/NianBroken/ZFCheckScores/main/data/no_ad_users_list.txt"
|
||||||
|
|
||||||
def advertise():
|
# 定义本地数据存储路径
|
||||||
ad_content = ""
|
FOLDER_PATH = "data"
|
||||||
|
INFO_FILE_PATH = os.path.join(FOLDER_PATH, "info.txt")
|
||||||
|
|
||||||
|
# 从文件中读取当前用户
|
||||||
|
try:
|
||||||
|
with open(INFO_FILE_PATH, "r") as info_file:
|
||||||
|
CURRENT_USER = info_file.read().strip()
|
||||||
|
except Exception:
|
||||||
|
CURRENT_USER = "None"
|
||||||
|
|
||||||
|
|
||||||
|
# 发送HTTP GET请求获取指定URL的内容
|
||||||
|
def fetch_content(url):
|
||||||
try:
|
try:
|
||||||
ad_url = "https://raw.githubusercontent.com/NianBroken/ZFCheckScores/main/data/advertise.txt"
|
response = requests.get(url)
|
||||||
# 发送HTTP GET请求获取内容
|
return response.text if response.status_code == 200 else None
|
||||||
response = requests.get(ad_url)
|
|
||||||
# 检查请求是否成功
|
|
||||||
if response.status_code == 200:
|
|
||||||
# 输出内容
|
|
||||||
ad_content = f"{response.text}\n------"
|
|
||||||
return ad_content
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return ad_content
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
# 获取免广告用户列表
|
||||||
|
def get_no_ad_users_list():
|
||||||
|
try:
|
||||||
|
return fetch_content(NO_AD_USERS_LIST_URL) or []
|
||||||
|
except Exception:
|
||||||
|
return []
|
||||||
|
|
||||||
|
|
||||||
|
# 获取广告内容
|
||||||
|
def get_advertise():
|
||||||
|
try:
|
||||||
|
# 获取免广告用户列表
|
||||||
|
no_ad_users_list = get_no_ad_users_list()
|
||||||
|
|
||||||
|
# 如果当前用户不在免广告用户列表中,获取广告内容
|
||||||
|
if CURRENT_USER not in no_ad_users_list:
|
||||||
|
ad_content = fetch_content(AD_URL)
|
||||||
|
return ad_content
|
||||||
|
# 当前用户在免广告用户列表中,不推送广告
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
except Exception:
|
||||||
|
return None
|
||||||
Loaded 3 of 5 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user