feat: Update Dockerfile and scripts for improved build process and cron job functionality
This commit is contained in:
parent
db08433a01
commit
ef65994a82
5 changed files with 115 additions and 58 deletions
117
app/index.ts
117
app/index.ts
|
|
@ -1,67 +1,78 @@
|
|||
import { CreateImage } from "./lib/image";
|
||||
import { Login, Upload } from "./lib/instagram";
|
||||
|
||||
console.time("🎉 | Done")
|
||||
console.time("🎉 | Done");
|
||||
|
||||
console.time("🔓 | Instagram login");
|
||||
async function main() {
|
||||
console.time("🔓 | Instagram login");
|
||||
|
||||
await Login()
|
||||
.then((data) => {
|
||||
try {
|
||||
const data = await Login();
|
||||
console.log("✨ | Instagram login successful");
|
||||
console.log(`🤔 | Login as ${data.currentUser.full_name}`);
|
||||
})
|
||||
.catch((error) => {
|
||||
} catch (error) {
|
||||
console.error("❌ | Instagram login failed:", error);
|
||||
})
|
||||
.finally(() => {
|
||||
} finally {
|
||||
console.timeEnd("🔓 | Instagram login");
|
||||
});
|
||||
}
|
||||
|
||||
let YYMMDD = "";
|
||||
|
||||
let YYMMDD = "";
|
||||
// 실행할 때 --today 옵션을 주면 오늘 날짜로 바뀜
|
||||
const args = process.argv.slice(2);
|
||||
if (args.includes("--today")) {
|
||||
console.log("📅 | --today option detected, using today's date");
|
||||
YYMMDD = new Date().toISOString().slice(0, 10).replace(/-/g, "").toString();
|
||||
console.log("📅 | Using today's date:", YYMMDD);
|
||||
}
|
||||
// Tomorrow is 1st of the month
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
YYMMDD = tomorrow.toISOString().slice(0, 10).replace(/-/g, "").toString();
|
||||
|
||||
// 실행할 때 --today 옵션을 주면 오늘 날짜로 바뀜
|
||||
const args = process.argv.slice(2);
|
||||
if (args.includes("--today")) {
|
||||
console.log("📅 | --today option detected, using today's date");
|
||||
YYMMDD = new Date().toISOString().slice(0, 10).replace(/-/g, "").toString();
|
||||
console.log("📅 | Using today's date:", YYMMDD);
|
||||
console.log("📅 | date:", YYMMDD);
|
||||
|
||||
console.log(tomorrow.getDate());
|
||||
if (tomorrow.getDate() === 1) {
|
||||
console.log("📅 | Tomorrow is the 1st of the month, fetching schedule...");
|
||||
console.time("📅 | Create Post Schedule");
|
||||
await CreateImage.PostSchedule();
|
||||
console.timeEnd("📅 | Create Post Schedule");
|
||||
|
||||
console.time("📤 | Upload Post Schedule");
|
||||
await Upload.Post(
|
||||
`./temp/schedule-${new Date().getFullYear()}-${
|
||||
new Date().getMonth() + 1
|
||||
}.png`,
|
||||
`#인천상정중학교 #상정중학교 #학사일정 \n${new Date().getFullYear()}년도 ${
|
||||
new Date().getMonth() + 1
|
||||
}월 학사 일정`
|
||||
);
|
||||
}
|
||||
try {
|
||||
console.time("📷 | Create Post Image");
|
||||
await CreateImage.PostMeal(YYMMDD);
|
||||
console.timeEnd("📷 | Create Post Image");
|
||||
|
||||
console.time("📱 | Create Story Image");
|
||||
await CreateImage.ConvertToStory(`./temp/${YYMMDD}.png`);
|
||||
console.timeEnd("📱 | Create Story Image");
|
||||
|
||||
console.time("📤 | Upload Post");
|
||||
await Upload.Post(
|
||||
`./temp/${YYMMDD}.png`,
|
||||
`#인천상정중학교 #상정중학교 #급식 \n${YYMMDD}일자 급식`
|
||||
);
|
||||
console.timeEnd("📤 | Upload Post");
|
||||
|
||||
console.time("📤 | Upload Story");
|
||||
await Upload.Story(`./temp/${YYMMDD}-story.png`, YYMMDD);
|
||||
console.timeEnd("📤 | Upload Story");
|
||||
} catch (error) {
|
||||
console.error("❌ | Error during image creation or upload:", error);
|
||||
} finally {
|
||||
console.timeEnd("🎉 | Done");
|
||||
}
|
||||
}
|
||||
// Tomorrow is 1st of the month
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
YYMMDD = tomorrow.toISOString().slice(0, 10).replace(/-/g, "").toString();
|
||||
|
||||
console.log("📅 | date:", YYMMDD);
|
||||
|
||||
console.log(tomorrow.getDate());
|
||||
if (tomorrow.getDate() === 1) {
|
||||
console.log("📅 | Tomorrow is the 1st of the month, fetching schedule...");
|
||||
console.time("📅 | Create Post Schedule");
|
||||
await CreateImage.PostSchedule();
|
||||
console.timeEnd("📅 | Create Post Schedule");
|
||||
|
||||
console.time("📤 | Upload Post Schedule");
|
||||
await Upload.Post(`./temp/schedule-${new Date().getFullYear()}-${new Date().getMonth() + 1}.png`, `#인천상정중학교 #상정중학교 #학사일정 \n${new Date().getFullYear()}년도 ${new Date().getMonth() + 1}월 학사 일정`);
|
||||
}
|
||||
try {
|
||||
console.time("📷 | Create Post Image");
|
||||
await CreateImage.PostMeal(YYMMDD);
|
||||
console.timeEnd("📷 | Create Post Image");
|
||||
|
||||
console.time("📱 | Create Story Image");
|
||||
await CreateImage.ConvertToStory(`./temp/${YYMMDD}.png`);
|
||||
console.timeEnd("📱 | Create Story Image");
|
||||
|
||||
console.time("📤 | Upload Post");
|
||||
await Upload.Post(`./temp/${YYMMDD}.png`, `#인천상정중학교 #상정중학교 #급식 \n${YYMMDD}일자 급식`);
|
||||
console.timeEnd("📤 | Upload Post");
|
||||
|
||||
console.time("📤 | Upload Story");
|
||||
await Upload.Story(`./temp/${YYMMDD}-story.png`, YYMMDD);
|
||||
console.timeEnd("📤 | Upload Story");
|
||||
} catch (error) {
|
||||
console.error("❌ | Error during image creation or upload:", error);
|
||||
} finally {
|
||||
console.timeEnd("🎉 | Done");
|
||||
}
|
||||
main();
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
cd /code/app
|
||||
|
||||
bun ./index.ts
|
||||
./run
|
||||
Loading…
Add table
Add a link
Reference in a new issue