Skip to content

Instantly share code, notes, and snippets.

View slaughtr's full-sized avatar

Dallas slaughtr

  • PNW
View GitHub Profile
@slaughtr
slaughtr / twitter.js
Last active December 13, 2019 20:29
Twitter JS Scraper
const fetch = require('node-fetch');
const cheerio = require('cheerio');
const getTweets = async username => {
const req = await fetch(`https://twitter.com/${username}`);
const page = await req.text();
const $ = cheerio.load(page, {xmlMode: true});
const actualTweets = [];
const tweetHTML = $('.tweet-text').toArray();

Keybase proof

I hereby claim:

  • I am slaughtr on github.
  • I am slaughtr (https://keybase.io/slaughtr) on keybase.
  • I have a public key ASAiAKcK3e9FF20mD_8CwhJBPrEz7apKVc2iiP-7DX3_DAo

To claim this, I am signing this object:

// I cannot absolutely guarantee I got everything completely correct, but I'm 95% sure I got at least 95% of it correct
// -----------------
// --- PROMISES
// -----------------
// Callback hell:
doSomething(params, (err, data) => {
if (err) console.error(err)
else {
@slaughtr
slaughtr / helpfulasyncaws.js
Last active April 25, 2018 20:51
Helpful async/await for AWS
// get a JSON file from S3 and immediately parse the JSON to a JS object
const testObj = JSON.parse(await s3.getObject({ Bucket: 'test', Key: test }).promise().then(res => res.Body.toString()));
// get all keys from an S3 listObjectV2 as an array (assuming no pagination of results)
const keysArr = (await s3.listObjectsV2({Bucket: 'test', Prefix: 'test'}).promise().then(res => res.Contents)).map(item => item.Key);