Skip to content

Commit

Permalink
Updated code => better logging mechanisms
Browse files Browse the repository at this point in the history
  • Loading branch information
Maye Edwin committed May 29, 2021
1 parent dbe03b4 commit 67735c2
Show file tree
Hide file tree
Showing 3 changed files with 455 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
node_modules/
bot/node_modules/
bot/config.js
Docs.md
31 changes: 13 additions & 18 deletions bot/bot.js
Original file line number Diff line number Diff line change
@@ -1,40 +1,35 @@
// Our Twitter library
const Twit = require("twit");

// We need to include our configuration file
// We need to include our configuration file...
const twit = new Twit(require("./config.js"));

// This is the URL of a search for the latest tweets on the '#MeetMaye' hashtag.
// This is the URL of a search for the latest tweets on the '#MeetMaye' hashtag...
const mediaArtsSearch = { q: "#MeetMaye", count: 100, result_type: "recent" };

// This function finds the latest tweet with the MeetMaye hashtag and retweets.
const retweetLatest = () => {
twit.get("search/tweets", mediaArtsSearch, (error, data) => {
// log out any errors and responses
console.log(error, data);
// If our search request to the server had no errors...
if (!error) {
// ...then we grab the ID of the tweet we want to retweetwit...
let retweetId = data.statuses[0].id_str;
// ...and then we tell Twitter we want to retweet it!
if (error) {
// However, if our original search request had an error, we want to print it out here...
console.log(error.message);
} else {
// Grab the ID of the tweet we want to retweetwit...
const retweetId = data.statuses[0].id_str;
// Tell Twitter we want to retweet it...
twit.post("statuses/retweet/" + retweetId, {}, (error, response) => {
if (response) {
console.log(
"Success! Check your bot, it should have retweeted something."
);
console.log("Success! Your bot has retweeted something.");
}
// If there was an error with our Twitter call, we print it out here.
// If there was an error with our Twitter call, we print it out here...
if (error) {
console.log("There was an error with Twitter:", error);
console.log(error.message);
}
});
}
// However, if our original search request had an error, we want to print it out here.
else {
console.log("There was an error with your hashtag search:", error);
}
});
}
};

// Try to retweet something as soon as we run the program...
retweetLatest();
Expand Down
Loading

0 comments on commit 67735c2

Please sign in to comment.