Skip to content

Instantly share code, notes, and snippets.

@leblancmeneses
Created December 29, 2017 16:00
Show Gist options
  • Save leblancmeneses/8af7da70d45c96420e6b69b5c40460ca to your computer and use it in GitHub Desktop.
Save leblancmeneses/8af7da70d45c96420e6b69b5c40460ca to your computer and use it in GitHub Desktop.
import * as admin from "firebase-admin";
admin.initializeApp({
credential: admin.credential.cert('./prod-account.json'),
databaseURL: 'https://this-is-in-firebase-console.firebaseio.com'
});
const sequence = async (items, action) => {
for(let i = 0; i < items.length; i++) {
await action(items[i], i);
}
}
const thottleWait = async () => await new Promise(async (r) => setTimeout(r, Math.ceil((60 * 60 * 1000) / 200)));
new Promise(async (resolve, reject) => {
try {
const hashTag = "india";
const tagDocRef = await admin.firestore().collection('hashTags').add({tag: hashTag, removeRetweets: true});
const apiResults = [{
allFieldsInCsv: 'allFieldsInCsv'
}];
await sequence(apiResults, async (tweet, i) => {
await tagDocRef.collection("tweets").add(tweet);
await thottleWait();
});
} catch (err) {
console.error('err: ', err);
}
resolve('done');
console.log('done');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment