Skip to content

Commit

Permalink
Export sharing posts script (#5140)
Browse files Browse the repository at this point in the history
  • Loading branch information
gewfy authored Apr 10, 2024
2 parents 9598724 + f4d66b2 commit 6aa17a2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions functions/scripts/exportSharingPostsByExerciseId.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import admin from 'firebase-admin';

const {GOOGLE_APPLICATION_CREDENTIALS} = process.env;

if (!GOOGLE_APPLICATION_CREDENTIALS) {
console.error(
'GOOGLE_APPLICATION_CREDENTIALS env pointing to service-account.json is required',
);
process.exit(1);
}

admin.initializeApp();
const firestore = admin.firestore();

(async () => {
const postsCollection = firestore.collection('posts');
const snapshot = await postsCollection
.where('exerciseId', '==', '1a53e633-6916-4fea-a072-977c4b215288')
.get();

const posts = snapshot.docs
.map(doc => doc.data())
.filter(({approved}) => approved);

posts.forEach(({text}) => {
console.log(`"${text.replace(/[\r\n]/g, ' ')}"`);
});

console.log(`Posts: ${posts.length}`);
})();

0 comments on commit 6aa17a2

Please sign in to comment.