Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: firebase folder for ichack24 demograph #16

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions firebase/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FB_API_KEY=
FB_AUTH_DOMAIN=
FB_PROJECT_ID=
FB_STORAGE_BUCKET=
FB_MESSAGING_SENDER_ID=
FB_APP_ID=
FB_MEASUREMENT_ID=
4 changes: 4 additions & 0 deletions firebase/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.output

.env*
!.env.template
49 changes: 49 additions & 0 deletions firebase/demographicsICHack24.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { initializeApp } from "firebase/app";
import { collection, getDocs, getFirestore, query } from "firebase/firestore";
import fs from 'fs';
import dotEnv from 'dotenv';

dotEnv.config();

// TODO: Replace the following with your app's Firebase project configuration
// See: https://support.google.com/firebase/answer/7015592
const firebaseConfig = {
apiKey: process.env.FB_API_KEY,
authDomain: process.env.FB_AUTH_DOMAIN,
projectId: process.env.FB_PROJECT_ID,
storageBucket: process.env.FB_STORAGE_BUCKET,
messagingSenderId: process.env.FB_MESSAGING_SENDER_ID,
appId: process.env.FB_APP_ID,
measurementId: process.env.FB_MEASUREMENT_ID
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);


// Initialize Cloud Firestore and get a reference to the service
const db = getFirestore(app);

const demographQuery = query(collection(db, 'demographics'))
const snapshot = await getDocs(demographQuery)

const data = [];
snapshot.forEach(doc => {
data.push(doc.data());
})
const allKeys = Array.from(new Set(data.flatMap(elem => Object.keys(elem))));


function toCSV(list, keys) {
const fields = []
for (const item of list) {
fields.push(keys.map(key => item[key]).join(','))
}
return fields.join("\n")
}
const csvFormat = allKeys.join(',') + "\n" + toCSV(data, allKeys) + "\n";

fs.mkdirSync('./.output', { recursive: true });
fs.writeFileSync('./.output/demographicsICHack24.csv', csvFormat);

process.exit(0);
9 changes: 9 additions & 0 deletions firebase/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"name": "@docsoc-tools/firebase",
"version": "1.0.0",
"type": "module",
"dependencies": {
"dotenv": "^16.4.5",
"firebase": "^10.14.1"
}
}
Loading