Giter Site home page Giter Site logo

twot's Introduction

twot - The Twitter Bot API

PyPI GitHub

About

This is a Python package that provides an easy-to-use interface to Twitter using Selenium to emulate actions that a Twitter user might make, such as liking, following, and tweeting. In addition, it provides a Tweet Search implementation that uses Twitter's Advanced Search to scrape for tweets.

Getting Started

Prerequisites

To use this package, you will need:

  • Python 3.7+
  • Selenium 4.0+
  • Chrome Browser
  • Twitter Account

Installation

  1. pip install twot

Usage

  1. Import TwitterAPI class, create an instance and login:
from twot.classes import TwitterAPI

api = TwitterAPI('my_username', 'my_password')
api.login()
  1. Use the TwitterAPI instance to interact with Twitter:
# Tweet something
api.post_tweet('Hello World!')

# Like a tweet
api.like_tweet('https://twitter.com/twitter/status/1234567890')

# Quote retweet a tweet
api.quote_retweet('https://twitter.com/twitter/status/1234567890', 'Foo bar')
  1. Scrape for tweets:
# First five options are required for every search
OPTIONS = {
    "limit": 500,
    "replies": False,
    "only-replies": False,
    "links": True,
    "only-links": False,
    "from": ['BarackObama']
}
# Links to the last 500 tweets from Obama
obama_tweets = api.search(OPTIONS)

Features

You must have a Twitter account to use all features (including search). Class methods return the results of their actions. For example, methods that post a tweet return a link to the new tweet. Likeing and following return whether that tweet/account is now liked/followed or unliked/unfollowed (true/false).

    Methods
    -------
    status()
        Prints general info about the class state
    login()
        Uses `username` and `password` to login to Twitter
    logout()
        Logs out from Twitter
    post_tweet(message)
        Posts a tweet to users timeline
    reply_to_tweet(tweet_id, message)
        Posts a reply to the specified tweet
    like_tweet(tweet_id)
        Likes/Unlikes the tweet
    retweet(tweet_id)
        Retweets/Unretweets the tweet
    quote_retweet(tweet_id, message)
        Quote retweets the tweet with the specified message
    follow(user_handle)
        Follows the user with the specified handle
    unfollow(user_handle)
        Unfollows the user with the specified handle
    search(options)
        Searches for tweets using Advanced Search
    quit()
        Ends the browser session

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

twot's People

Contributors

gpl27 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

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.