Skip to content

Commit ae08e8d

Browse files
committed
Initial Commit
0 parents  commit ae08e8d

File tree

666 files changed

+123097
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

666 files changed

+123097
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.env
2+
yarn.lock

config.js

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
module.exports = {
2+
consumer_key: "your_consumer_key",
3+
consumer_secret: "your_consumer_secret",
4+
access_token: "your_api_access_token",
5+
access_token_secret: "your_api_access_token_secret",
6+
};

main.js

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const Twit = require("twit");
2+
const config = require("./config");
3+
4+
// Instantiate Twit client with your Twitter API keys
5+
const T = new Twit(config);
6+
7+
// Set the hashtag and message
8+
const hashtag = "your hashtag";
9+
const message = "write your message here...";
10+
11+
// Function to scrape users, send messages, and repeat
12+
async function scrapeAndSend() {
13+
try {
14+
// Scrape tweets with the specified hashtag
15+
const { data } = await T.get("search/tweets", {
16+
q: `#${hashtag}`,
17+
count: 20,
18+
});
19+
20+
const users = data.statuses.map((tweet) => ({
21+
id: tweet.user.id_str,
22+
}));
23+
24+
// Send messages to the scraped users with a time delay
25+
for (let i = 0; i < users.length; i++) {
26+
const user = users[i];
27+
try {
28+
await T.post("direct_messages/events/new", {
29+
event: {
30+
type: "message_create",
31+
message_create: {
32+
target: { recipient_id: user.id },
33+
message_data: { text: message },
34+
},
35+
},
36+
});
37+
console.log(`Message sent to user with ID ${user.id}`);
38+
39+
// Delay between sending messages
40+
const delay = 1 * (60 * 1000); // Delay in milliseconds (e.g., 5000 = 5 seconds)
41+
await sleep(delay);
42+
} catch (err) {
43+
console.error(`Error sending message to user with ID ${user.id}:`);
44+
}
45+
}
46+
47+
// Repeat the process after a delay
48+
setTimeout(scrapeAndSend, 60000); // Delay in milliseconds (60 seconds = 60000 milliseconds)
49+
} catch (err) {
50+
console.error("Error retrieving tweets:", err);
51+
}
52+
}
53+
54+
// Utility function for delaying execution
55+
function sleep(ms) {
56+
return new Promise((resolve) => {
57+
setTimeout(resolve, ms);
58+
});
59+
}
60+
61+
// Start the process
62+
scrapeAndSend();

node_modules/.bin/mime

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/sshpk-conv

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/sshpk-sign

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/sshpk-verify

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.bin/uuid

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/.yarn-integrity

+74
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/ajv/.tonic_example.js

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

node_modules/ajv/LICENSE

+22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)