-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync-captions.js
More file actions
executable file
·32 lines (27 loc) · 958 Bytes
/
sync-captions.js
File metadata and controls
executable file
·32 lines (27 loc) · 958 Bytes
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
import mongoose from 'mongoose';
import 'dotenv/config';
import Event from './models/eventModel.js';
import Post from './models/post.model.js';
import connectDB from './config/mongoDB.js';
async function syncCaptions() {
await connectDB();
console.log('Connected to DB for caption sync...');
const events = await Event.find({ description: null });
console.log(`Found ${events.length} events with missing descriptions.`);
for (const event of events) {
const post = await Post.findOne({ instagramId: event.instagramId });
if (post && post.caption) {
event.description = post.caption;
await event.save();
console.log(`Synced caption for event: ${event.eventName}`);
} else {
console.log(`No caption found for ${event.eventName} (InstaID: ${event.instagramId})`);
}
}
console.log('Caption sync complete.');
process.exit(0);
}
syncCaptions().catch(err => {
console.error(err);
process.exit(1);
});