Giter VIP home page Giter VIP logo

twitter-bot's Introduction

Welcome to Twitter Bot ๐Ÿ‘‹

Version License: ISC Twitter: PiyushSthr

A bot that generates images from Quotes Api and posts it to Twitter.

Demo Post

alt text

Install

git clone https://github.com/PiyushSuthar/twitter-bot.git
cd twitter-bot
npm install

Usage

node index.js

Automation

We will deploy this bot on Heroku, and make it work at a given time everyday. There are 2 ways of doing it.

  1. Using Heroku's own scheduler, (But we'll have to provide our credit card info)
  2. Using my own Lifehack/Jugaad.

Doing it with Heroku's own scheduler is easy, you can follow their Documentation. I'll show you how to do it without it.

First of all we'll install ExpressJs. Yes, we will use this one here in our bot.

npm i express

Open the index.js file and put all the code in a function.

request("https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json",{json : true}, async(err,res,body)=>{
    ...
})

To

function functionName(){
    request("https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json",{json : true}, async(err,res,body)=>{
        ...
    })
}

now require express module in the index.js file.

const express = require("express")
const app = express();

var port = process.env.PORT || 8000;

Now basically what our idea is when we will visit a specific path on the domain, this will trigger the function. So this is how we can do it.

Make sure to make the path very difficult. What I did was, I went ot a random password generaor and generated some and pasted over here.

app.get("/EXvAjMfjhPwqnk7D/vVL7xTXwPr6gkeVJ",(req,res)=>{
    funcionName();//calling the function
    res.send("I'm tweeting!")//Giving a response back.
})
app.listen(port,()=>console.log(`We are listening on port ${port}`))

Now just add a script in package.json

"start": "node index.js",

That's it now deploy it on heroku through Heroku Cli.

Author

๐Ÿ‘ค Piyush Suthar

Show your support

Give a โญ๏ธ if this project helped you!


This README was generated with โค๏ธ by readme-md-generator

twitter-bot's People

Contributors

dependabot[bot] avatar piyushsuthar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

todokku

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.