Created
March 10, 2020 22:56
-
-
Save ernestkamara/203557ec0e3879c21c0a373b6ceaff3e to your computer and use it in GitHub Desktop.
Cloud Functions Demo
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
// The function scheduled to run every 12 hours | |
exports.scheduledFunction = functions.pubsub.schedule('every 12 hours').onRun(async (context) => { | |
// retrieve the search results as JSON | |
await serpwow.json(params) | |
.then(result => { | |
// Articles Firestore CollectionReference | |
const articlesRef = admin.firestore().collection('articles'); | |
// Save search results to Firestore | |
const articles = result["news_results"] | |
articles.forEach(article => { | |
const id = article['date_utc'] + article['position'] | |
articlesRef | |
.doc(id) | |
.set(article) | |
.catch(error => { | |
console.log(error); | |
}) | |
}); | |
}) | |
.catch(error => { | |
console.log(error); | |
}); | |
return null; | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment