Skip to content

Instantly share code, notes, and snippets.

@shoaibmehedi7
Created October 13, 2022 19:03
Show Gist options
  • Save shoaibmehedi7/8257878748ec5fef8e00d6e59cbaad0b to your computer and use it in GitHub Desktop.
Save shoaibmehedi7/8257878748ec5fef8e00d6e59cbaad0b to your computer and use it in GitHub Desktop.
const axios = require("axios");
const config = {
method: "get",
headers: {
Authorization: `Bearer AAAAAAAAAAAAAAAAAAAAAFJ0hAEAAAAAXNjzqQw7w%2FJPWGGKViqnkDB%2Bo4U%3DUd44SKeDV31IDrOfzA7OE1Q2PvqdFO3U0i5DD08L4fjMkAI0qN`,
},
};
let startTimeInUTC = new Date("2022-10-10T00:00:00.000Z").getTime();
const utcTime = new Date().getTime();
const endTimeInUTC = new Date(utcTime - 10000).toISOString();
let i = 0;
const interval = setInterval(async () => {
i++;
const temp = new Date(startTimeInUTC + 3600000).toISOString();
console.log(new Date(startTimeInUTC).toISOString(), temp, i);
const url = `https://api.twitter.com/2/tweets/search/recent?tweet.fields=attachments,author_id,created_at,entities,geo,id,in_reply_to_user_id,lang,possibly_sensitive,referenced_tweets,source,text,withheld&max_results=100&start_time=${new Date(
startTimeInUTC
).toISOString()}&query=I%20nominate%20these%20top%20community%20members%20to%20the%20BB%20list&end_time=${temp}`;
console.log(url);
const response = await axios.get(url, config);
const fs = require("fs");
const filename = `${new Date(startTimeInUTC).toISOString()} - ${temp}.json`;
if (fs.existsSync(`./data/${filename}`)) {
console.log("file exists");
startTimeInUTC = new Date(temp).getTime();
return;
}
fs.writeFile(filename, JSON.stringify(response.data), (err) => {
if (err) {
console.log(err);
} else {
console.log("file created");
}
});
if (temp > endTimeInUTC) {
clearInterval(interval);
}
startTimeInUTC = new Date(temp).getTime();
}, 10000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment