Made the line_today.py kinda work ig. But I have no idea how can I run

this without issues in prod tho. and the "BlurPageBeforeLogin" thing
works just file, oh and checkCookie is now working (but without the
database part just yet)
This commit is contained in:
吳元皓 2025-05-17 23:31:55 +08:00
parent 0e26a23261
commit 81012f5061
6 changed files with 91 additions and 36 deletions

1
.gitignore vendored
View File

@ -32,3 +32,4 @@ __pycache__
*.sql
!database/*.sql
_dt_*.py

View File

@ -48,7 +48,11 @@ const sendChatData = (event?: KeyboardEvent) => {
}, 3000);
};
onMounted(async () => {
const stopChatGenerate = () => {
aiGenerating.value = false;
};
/*onMounted(async () => {
console.log(cookieChatId);
if (cookieChatId) {
} else {
@ -63,7 +67,7 @@ onMounted(async () => {
);
cookieChatId.value = checkUserChatId.value;
}
});
});*/
onMounted(async () => {
/*const {
data: getData,
@ -136,7 +140,7 @@ onMounted(async () => {
</button>
<button
class="pl-2 pr-2 mr-1 ml-1 bg-black text-white rounded-full hover:bg-gray-700 hover:translate-y-[-4px] transition-all duration-300 disabled:cursor-not-allowed disabled:hover:translate-y-0 disabled:bg-color-500"
@click=""
@click="stopChatGenerate"
v-else
>
<Square class="w-5 h-5" />

View File

@ -5,34 +5,34 @@ const { t } = useI18n();
const allowed = ref(false);
const error = ref(false);
const errorMsg = ref("");
const emit = defineEmits(["windowopener", "error", "loadValue"]);
onMounted(async () => {
// Check Cookie
try {
const { data, error: sendError } = useFetch("/api/user/checkcookie");
if (sendError) {
error.value = true;
}
if (false) {
allowed.value = true;
} else {
allowed.value = false;
}
} catch (e) {
try {
// await :(
const { data, error: sendError } = await useFetch("/api/user/checkcookie");
if (sendError.value) {
error.value = true;
errorMsg.value = e.message;
}
});
if (true) {
allowed.value = true;
} else {
allowed.value = false;
}
} catch (e) {
error.value = true;
errorMsg.value = e.message;
}
</script>
<template>
<div
class="flex flex-col bg-gray-200/50 text-black w-full h-full absolute inset-0 justify-center align-middle text-center z-[20] backdrop-blur-sm"
v-if="!allowed || error"
>
<div v-if="!allowed && !error" class="m-2">
{{ t("error") }}
</div>
<div v-if="error" class="m-2">
<span>{{ errorMsg ? errorMsg : t("systemerror") }}</span>
<span>{{ errorMsg ? errorMsg : "" }} {{ t("systemerror") }}</span>
</div>
</div>
<slot></slot>

View File

@ -10,12 +10,21 @@ import dotenv
import os
import gzip
import io
import argparse
parser = argparse.ArgumentParser(description="A LINE Today Scraper.")
parser.add_argument("-s", "--slug", type=str, help="The article URL like: oqmazXP")
args = parser.parse_args()
if not args.slug:
print("No Slug entered, please use -s oqmazXP as a demo.")
exit(1)
# Load environment variables from .env file
dotenv.load_dotenv()
headers = {
#'User-Agent': 'NewsSceraperBot/1.0 (https://github.com/hpware/news-analyze)',
#'User-Agent': 'NewsSceraperBot/1.0 (https://github.com/hpware/news-analyze) (A little note: If you see this, It means that your website is being scraped by other people, not the user hpware. Please keep that in mind at don't spam issues, I can't fix it.)',
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': '*',
'Accept-Language': 'zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7',
@ -28,9 +37,8 @@ headers = {
}
url = "https://today.line.me/tw/v2/article/oqmazXP"
try:
url = "https://today.line.me/tw/v2/article/" + args.slug
req = Request(url, headers=headers)
response = urlopen(req)
if response.info().get('Content-Encoding') == 'gzip':

View File

@ -0,0 +1,20 @@
export default defineEventHandler(async (event) => {
const slug = getRouterParam(event, "slug");
return new Promise((resolve, reject) => {
const pythonProcess = spawn("python3", ["scraping/hot_articles.py"]);
let dataString = "";
pythonProcess.stdout.on("data", (data) => {
dataString += data.toString();
});
pythonProcess.stderr.on("data", (data) => {
console.error(`Error: ${data}`);
});
pythonProcess.on("close", (code) => {
resolve({ status: "completed", output: dataString });
});
});
});

View File

@ -1,23 +1,45 @@
// This should be hooked up to a database soon.
import postgres from "~/server/components/postgres";
// Parse Date Function
function checkDate(dateString: string) {
const now = new Date();
const parsed = new Date(dateString);
const timer = 60 * 60 * 1;
return now.getTime() - parsed.getTime() > timer;
}
export default defineEventHandler(async (event) => {
const loginCookie = getCookie(event, "session");
const lastCheckCookie = getCookie(event, "last_check");
const nowDate = new Date().toLocaleString();
console.log(nowDate);
if (!lastCheckCookie && loginCookie) {
deleteCookie(event, "session");
deleteCookie(event, "lastCheckCookie");
setCookie(event, "lastCheckCookie", nowDate, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
});
return {
auth: false,
user: null,
};
}
const checkDate = new Date().toLocaleString();
console.log(checkDate);
setCookie(event, "lastCheckCookie", checkDate, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
});
if (!lastCheckCookie) {
setCookie(event, "lastCheckCookie", nowDate, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
});
}
if (checkDate(String(lastCheckCookie))) {
setCookie(event, "lastCheckCookie", nowDate, {
httpOnly: true,
secure: process.env.NODE_ENV === "production",
path: "/",
});
}
return {
auth: true,
user: "testing",