Last active
May 6, 2020 16:16
-
-
Save NickFoden/5eff85660508f444d824ac1aadffbaff to your computer and use it in GitHub Desktop.
G Sheet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const functions = require("firebase-functions"); | |
const admin = require("firebase-admin"); | |
const fetch = require("node-fetch"); | |
admin.initializeApp(functions.config().firebase); | |
const firestore = admin.firestore(); | |
// write a function to take the data and return the JSON you want to upload to the database | |
const normalizeData = require("./src/normalizeData"); | |
exports.goGetFinancialSheets = functions.pubsub | |
.schedule("every day 00:01") | |
.onRun(async (context) => { | |
// if not public will need to set up authorization | |
const data = await fetch("https://www.google.com/sheets/about/") | |
//maybe have to .json the data about/").then(res => res.json()) | |
const organizedData = normalizeData(data) | |
// example with firestore collection of financialsheet and a made up id of docId | |
const databaseRef = firestore.collection("financialsheet").doc("docId") | |
//if updating the same document then can use update | |
databaseRef.update({ | |
data: organizedData | |
}) | |
//making a new document each time | |
const databaseRef = firestore.collection("financialsheet").doc() | |
//the document id | |
const key = databaseRef.id | |
// since new document use set | |
// reccomend to also set another key such as date so you can query the documents by something | |
databaseRef.set({ | |
data: organizedData, | |
date: date.now(), | |
key | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment