Created
August 14, 2019 08:26
-
-
Save tristankirkpatrick/ab0e93cc92da705bb630a6051624ae66 to your computer and use it in GitHub Desktop.
This file contains 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
var Twit = require('twit') | |
var twitter = new Twit({ | |
consumer_key: '', | |
consumer_secret: '', | |
access_token: '', | |
access_token_secret: '', | |
timeout_ms: 60 * 1000, // optional HTTP request timeout to apply to all requests. | |
strictSSL: true, // optional - requires SSL certificates to be valid. | |
}) | |
var GoogleSheets = require('google-drive-sheets'); | |
// spreadsheet key is the long id in the sheets URL | |
var mySheet = new GoogleSheets('1BHW2ZpMtEW3AVcJvVxQiquQIBKpTmcjq_oc9omvkPXo'); | |
// Without auth -- read only | |
// IMPORTANT: See note below on how to make a sheet public-readable! | |
// # is worksheet id - IDs start at 1 | |
mySheet.getRows(1, function(err, rowData) { | |
console.log('Pulled in ' + rowData.length + ' rows from Google Sheets'); | |
for (i = 0; i < rowData.length; i++) { | |
var twitterhandle = rowData[i].twitterhandle | |
var specialism = rowData[i].specialism | |
twitter.get('users/show', {screen_name: twitterhandle}, function(err, data, response) { | |
Object.assign(data, {specialism: specialism}); | |
// server app that updates bits of list from twitter, then make it save as a json | |
const mongo = require('mongodb').MongoClient; | |
const url = 'mongodb://192.168.1.150:32771'; | |
mongo.connect(url, (err, client) => { | |
if (err) { | |
console.error(err) | |
return | |
} | |
const db = client.db('twitterteachers') | |
collection = db.collection('teachers') | |
key = {'_id':data.id_str} | |
collection.update(key, data, {upsert:true}) | |
}) | |
}) | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment