Skip to content

Instantly share code, notes, and snippets.

@ernestkamara
Created March 10, 2020 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ernestkamara/203557ec0e3879c21c0a373b6ceaff3e to your computer and use it in GitHub Desktop.
Save ernestkamara/203557ec0e3879c21c0a373b6ceaff3e to your computer and use it in GitHub Desktop.
Cloud Functions Demo
// 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