From eeaacfd6da804ee321381f2f8888a2c2a3afc2cd Mon Sep 17 00:00:00 2001 From: gsbmk007 Date: Mon, 18 Dec 2023 21:27:16 +0800 Subject: [PATCH 1/3] Converted JS to python due to package errors --- README.md | 2 +- quizzes.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ topics.py | 41 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 quizzes.py create mode 100644 topics.py diff --git a/README.md b/README.md index 449511e..aa94257 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,4 @@ Requires Node.js >= 8. 1. Clone this repo, cd into it, and run `npm install`. 2. Download your service account (generate private key) from the [Firebase Console](https://console.firebase.google.com) under settings, then save it in the root of this project as `credentials.json`. -3. Run `node quizzes.js` and `node topics.js` +3. Run `node quizzes.py` and `node topics.py` diff --git a/quizzes.py b/quizzes.py new file mode 100644 index 0000000..c5e33a1 --- /dev/null +++ b/quizzes.py @@ -0,0 +1,48 @@ +import firebase_admin +from firebase_admin import credentials, firestore +import yaml +import asyncio + +# Initialize Firebase Admin SDK +cred = credentials.Certificate('./credentials.json') +firebase_admin.initialize_app(cred) +db = firestore.client() + +quizzes = [ + 'angular-basics', + 'flutter-scroll', + 'cf-basics', + 'cf-triggers', + 'firebase-perf', + 'firestore-basics', + 'flutter-basics', + 'flutter-containers', + 'flutter-flex', + 'flutter-gestures', + 'flutter-material', + 'flutter-scroll', + 'js-basics', + 'js-variables', + 'rxjs-basics', + 'ts-basics' +] + +async def update(quiz_id): + with open(f'quizzes/{quiz_id}.yaml', 'r') as file: + yaml_data = yaml.safe_load(file) + + print(yaml_data) + + ref = db.collection('quizzes').document(quiz_id) + + await ref.set(yaml_data, merge=True) + + print('DONE') + +# Loop through quizzes and update Firestore +async def main(): + tasks = [update(quiz) for quiz in quizzes] + await asyncio.gather(*tasks) + +if __name__ == "__main__": + asyncio.run(main()) diff --git a/topics.py b/topics.py new file mode 100644 index 0000000..c5fc87a --- /dev/null +++ b/topics.py @@ -0,0 +1,41 @@ +import firebase_admin +from firebase_admin import credentials, firestore +import yaml +import asyncio + +# Initialize Firebase Admin SDK +cred = credentials.Certificate('./credentials.json') +firebase_admin.initialize_app(cred) +db = firestore.client() + +topics = [ + 'angular', + 'flutter', + 'cf', + 'firebase', + 'firestore', + 'flutter', + 'rxjs', + 'js', + 'ts' +] + +async def update(topic_id): + with open(f'topics/{topic_id}.yaml', 'r') as file: + yaml_data = yaml.safe_load(file) + + print(yaml_data) + + ref = db.collection('topics').document(topic_id) + + await ref.set(yaml_data, merge=True) + + print('DONE') + +# Loop through topics and update Firestore +async def main(): + tasks = [update(topic) for topic in topics] + await asyncio.gather(*tasks) + +if __name__ == "__main__": + asyncio.run(main()) From 2076955a4164e42402f8bc8c0f1fb640f864e118 Mon Sep 17 00:00:00 2001 From: gsbmk007 Date: Mon, 18 Dec 2023 21:28:13 +0800 Subject: [PATCH 2/3] Converted JS to python due to package errors --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index aa94257..9eac747 100644 --- a/README.md +++ b/README.md @@ -9,4 +9,4 @@ Requires Node.js >= 8. 1. Clone this repo, cd into it, and run `npm install`. 2. Download your service account (generate private key) from the [Firebase Console](https://console.firebase.google.com) under settings, then save it in the root of this project as `credentials.json`. -3. Run `node quizzes.py` and `node topics.py` +3. Run `python3 quizzes.py` and `python3 topics.py` From f78c496cf5585e6fb940c6dc7dd22e8ae2403b8e Mon Sep 17 00:00:00 2001 From: gsbmk007 Date: Mon, 18 Dec 2023 21:29:32 +0800 Subject: [PATCH 3/3] Converted JS to python due to package errors --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9eac747..311e7a6 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,6 @@ This repo allows you to populate your database with quiz questions for [Flutter Requires Node.js >= 8. -1. Clone this repo, cd into it, and run `npm install`. +1. Clone this repo, cd into it. 2. Download your service account (generate private key) from the [Firebase Console](https://console.firebase.google.com) under settings, then save it in the root of this project as `credentials.json`. -3. Run `python3 quizzes.py` and `python3 topics.py` +2. Run `python3 quizzes.py` and `python3 topics.py`