Created
April 29, 2022 20:40
-
-
Save micuat/c36ec5e485476843748a865157ff349b to your computer and use it in GitHub Desktop.
twitter hashtag+image crawler
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
const fs = require('fs'); | |
require("dotenv").config(); | |
const Twitter = require('twitter'); | |
const twitter = new Twitter({ | |
consumer_key: process.env.TW_CKEY, | |
consumer_secret: process.env.TW_CSECRET, | |
access_token_key: process.env.TW_ATKEY, | |
access_token_secret: process.env.TW_ATSECRET | |
}); | |
let lastId; | |
const fetcher = () => { | |
const params = { q: '#PCD2021', tweet_mode: 'extended', count: 100 }; | |
if(lastId) { | |
params.since_id = lastId; | |
} | |
twitter.get('search/tweets', params, function (error, tweets, response) { | |
if (!error) { | |
// console.log(tweets.statuses.length) | |
for (let i = tweets.statuses.length - 1; i >= 0; i--) { | |
// console.log(tweets.statuses[i]); | |
let event = tweets.statuses[i]; | |
if(event.id == lastId) continue; | |
lastId = event.id; | |
if(/^RT /g.test(event.full_text)) continue; | |
let media = event.entities.media; | |
if (media == undefined) { | |
if (event.extended_entities != undefined) | |
media = event.extended_entities.media; | |
if (media == undefined) | |
continue; | |
} | |
for (let j = 0; j < media.length; j++) { | |
fs.appendFileSync('./images.txt', | |
`${media[j].media_url_https} ${event.user.screen_name} ${event.created_at}\n`); | |
} | |
} | |
} | |
else { | |
console.error(error) | |
} | |
}); | |
} | |
setInterval(fetcher, 60 * 1000); | |
fetcher(); |
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
{ | |
"name": "discord-bot-hydra", | |
"version": "1.0.0", | |
"description": "Choo choo Bot for the coding train!", | |
"main": "index.js", | |
"scripts": { | |
"start": "node index.js", | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"repository": { | |
"type": "git", | |
"url": "git+https://github.com/CodingTrain/Discord-Bot-Choo-Choo" | |
}, | |
"author": "", | |
"license": "ISC", | |
"bugs": { | |
"url": "https://github.com/CodingTrain/Discord-Bot-Choo-Choo/issues" | |
}, | |
"homepage": "https://github.com/CodingTrain/Discord-Bot-Choo-Choo#readme", | |
"dependencies": { | |
"dotenv": "^8.2.0", | |
"twitter": "^1.7.1" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment