mirror of
https://github.com/hpware/news-analyze.git
synced 2025-06-24 00:01:03 +08:00
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:
parent
0e26a23261
commit
81012f5061
1
.gitignore
vendored
1
.gitignore
vendored
@ -32,3 +32,4 @@ __pycache__
|
|||||||
|
|
||||||
*.sql
|
*.sql
|
||||||
!database/*.sql
|
!database/*.sql
|
||||||
|
_dt_*.py
|
||||||
|
@ -48,7 +48,11 @@ const sendChatData = (event?: KeyboardEvent) => {
|
|||||||
}, 3000);
|
}, 3000);
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async () => {
|
const stopChatGenerate = () => {
|
||||||
|
aiGenerating.value = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*onMounted(async () => {
|
||||||
console.log(cookieChatId);
|
console.log(cookieChatId);
|
||||||
if (cookieChatId) {
|
if (cookieChatId) {
|
||||||
} else {
|
} else {
|
||||||
@ -63,7 +67,7 @@ onMounted(async () => {
|
|||||||
);
|
);
|
||||||
cookieChatId.value = checkUserChatId.value;
|
cookieChatId.value = checkUserChatId.value;
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
/*const {
|
/*const {
|
||||||
data: getData,
|
data: getData,
|
||||||
@ -136,7 +140,7 @@ onMounted(async () => {
|
|||||||
</button>
|
</button>
|
||||||
<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"
|
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
|
v-else
|
||||||
>
|
>
|
||||||
<Square class="w-5 h-5" />
|
<Square class="w-5 h-5" />
|
||||||
|
@ -5,34 +5,34 @@ const { t } = useI18n();
|
|||||||
const allowed = ref(false);
|
const allowed = ref(false);
|
||||||
const error = ref(false);
|
const error = ref(false);
|
||||||
const errorMsg = ref("");
|
const errorMsg = ref("");
|
||||||
|
const emit = defineEmits(["windowopener", "error", "loadValue"]);
|
||||||
|
|
||||||
onMounted(async () => {
|
try {
|
||||||
// Check Cookie
|
// 喔 我沒有加 await :( 難怪有問題
|
||||||
try {
|
const { data, error: sendError } = await useFetch("/api/user/checkcookie");
|
||||||
const { data, error: sendError } = useFetch("/api/user/checkcookie");
|
if (sendError.value) {
|
||||||
if (sendError) {
|
|
||||||
error.value = true;
|
error.value = true;
|
||||||
}
|
}
|
||||||
if (false) {
|
if (true) {
|
||||||
allowed.value = true;
|
allowed.value = true;
|
||||||
} else {
|
} else {
|
||||||
allowed.value = false;
|
allowed.value = false;
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
error.value = true;
|
error.value = true;
|
||||||
errorMsg.value = e.message;
|
errorMsg.value = e.message;
|
||||||
}
|
}
|
||||||
});
|
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<div
|
<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"
|
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">
|
<div v-if="!allowed && !error" class="m-2">
|
||||||
{{ t("error") }}
|
{{ t("error") }}
|
||||||
</div>
|
</div>
|
||||||
<div v-if="error" class="m-2">
|
<div v-if="error" class="m-2">
|
||||||
<span>{{ errorMsg ? errorMsg : t("systemerror") }}</span>
|
<span>{{ errorMsg ? errorMsg : "" }} {{ t("systemerror") }}</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<slot></slot>
|
<slot></slot>
|
||||||
|
@ -10,12 +10,21 @@ import dotenv
|
|||||||
import os
|
import os
|
||||||
import gzip
|
import gzip
|
||||||
import io
|
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
|
# Load environment variables from .env file
|
||||||
dotenv.load_dotenv()
|
dotenv.load_dotenv()
|
||||||
|
|
||||||
headers = {
|
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',
|
'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': '*',
|
||||||
'Accept-Language': 'zh-TW,zh;q=0.9,en-US;q=0.8,en;q=0.7',
|
'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:
|
try:
|
||||||
|
url = "https://today.line.me/tw/v2/article/" + args.slug
|
||||||
req = Request(url, headers=headers)
|
req = Request(url, headers=headers)
|
||||||
response = urlopen(req)
|
response = urlopen(req)
|
||||||
if response.info().get('Content-Encoding') == 'gzip':
|
if response.info().get('Content-Encoding') == 'gzip':
|
||||||
|
20
server/api/news/get/lt/[slug].ts
Normal file
20
server/api/news/get/lt/[slug].ts
Normal 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 });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
@ -1,23 +1,45 @@
|
|||||||
// This should be hooked up to a database soon.
|
// This should be hooked up to a database soon.
|
||||||
import postgres from "~/server/components/postgres";
|
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) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const loginCookie = getCookie(event, "session");
|
const loginCookie = getCookie(event, "session");
|
||||||
const lastCheckCookie = getCookie(event, "last_check");
|
const lastCheckCookie = getCookie(event, "last_check");
|
||||||
|
const nowDate = new Date().toLocaleString();
|
||||||
|
console.log(nowDate);
|
||||||
if (!lastCheckCookie && loginCookie) {
|
if (!lastCheckCookie && loginCookie) {
|
||||||
deleteCookie(event, "session");
|
deleteCookie(event, "session");
|
||||||
deleteCookie(event, "lastCheckCookie");
|
setCookie(event, "lastCheckCookie", nowDate, {
|
||||||
return {
|
|
||||||
auth: false,
|
|
||||||
user: null,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const checkDate = new Date().toLocaleString();
|
|
||||||
console.log(checkDate);
|
|
||||||
setCookie(event, "lastCheckCookie", checkDate, {
|
|
||||||
httpOnly: true,
|
httpOnly: true,
|
||||||
secure: process.env.NODE_ENV === "production",
|
secure: process.env.NODE_ENV === "production",
|
||||||
path: "/",
|
path: "/",
|
||||||
});
|
});
|
||||||
|
return {
|
||||||
|
auth: false,
|
||||||
|
user: null,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
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 {
|
return {
|
||||||
auth: true,
|
auth: true,
|
||||||
user: "testing",
|
user: "testing",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user