Skip to main content

twitter-santa

Why?

This Def Con talk was the motivation behind creating this project. In short, a guy built a bot to retweet twitter contests and won a lot of random stuff. He's never released the source code, so I decided that implementing a bot like this would be a great way to spend weekends. Consequently, I built a more general version of the bot discussed in the talk; you can configure the bot and use it for different purposes than retweeting contests (RT to make donations, for instance).

Why twitter-santa? Well, it's Christmas soon, you can get yourself a present:) However, to be serious, I encourage you to use this bot for educational purposes only. I'm more interested in the interface design of this bot, so if you have any ideas on how we can improve it, let me know.

Basics

Before we get started, you need to know that this bot uses Python >= 3 only.

This bot contains a small number of command line arguments that you can pass in. Here is the complete list of them:

  • -a or --agents (file containing user agents to be used while making HTTP requests to Twitter)
  • -i or --invalidate (erase all saved sessions; this includes cookies or any other data saved from previous web requests)
  • -c or --config (file containing the configurations for the bot; if not provided, we will used the default configurations in the config directory)
  • -e or --executor-count (specifies how many executors - explained below - we need to launch)

Speaking of interface design, I would define three important abstractions here:

  • Searchers (primary responsibility is to search for the desired tweets and pass them along to handlers)

  • Handlers (responsible for filtering out and parsing tweets to determine appropriate actions that should be applied to those tweets. When finished, pass the actions to executors)

  • Actions (many tweets request different actions to participate in a contest - retweet, like, follow, comment, etc. You can also customize it and add yours)

  • Executors (receive a list of actions from handlers and execute them. Plain and simple)

Let's dive into the configuration of those objects. Here's a sample JSON file:

{
    "searchers": [{
        "count": 1,
        "search-queries": ["rt to win", "#contest"],
        "scan-time": 560,
        "month-diff": 1,
        "request-delay": 5,
        "error-delay": 5,
        "empty-request-delay": 20,
        "error-tries": 5,
        "empty-tries": 5
    },{
        "count": 2,
        "search-queries": ["rt to donate", "#donation", "RT", "donation"],
        "scan-time": 560,
        "month-diff": 1,
        "tweet-limit": 500
    }],

    "handlers": [{
        "count": 5,
        "keywords": ["win", "winner", "lucky"],
        "avoid-usernames": ["bot", "bot spotter", "bot spotting"]
    },{
        "count": 2,
        "keywords": ["charity", "donate", "donation"],
        "avoid-usernames": ["bot", "bot spotter", "bot spotting"]
    }],

    "executors": [{
      "count": 2,
      "request-delay": 5
    }]
}

Searchers:

  • count (defines how many searchers with the same configuration we need to create. Optional)

  • search-queries (an array of strings that should be used for searching tweets. Required)

  • scan-time (specifies for how long this searcher should be scrapping Twitter. Optional)

  • month-diff (defines the "expiration date" for tweets in terms of months. For instance, if 1 is specified, then we would only accept tweets that have been tweeted within last month. Optional)

  • request-delay (specifies for how long this searcher should wait before making an HTTP request. Optional)

  • error-delay (specifies for how long this searcher should wait before retrying an HTTP request after an error has occurred. Optional)

  • empty-request-delay (specifies for how long this searcher should wait before making another HTTP request after getting an empty list of tweets. Optional)

  • error-tries (specifies how many error tries are allowed before terminating the bot. Optional)

  • empty-tries (specifies how many "empty" tries are allowed before terminating the current searcher. Optional)

  • pictures-only (true/false values. Should every tweet contain an image? Optional)

  • verified-accounts-only (true/false values. Should we search for tweets from verified accounts only? Optional)

Handlers:

  • count (defines how many handlers with the same configuration we need to create. Optional)

  • keywords (an array of strings that every tweet should contain in order to be processed. Required)

  • avoid-usernames (an array of usernames that we should avoid - bot spotters as an example. Optional)

  • avoid-keywords (an array of usernames that we should avoid - bot spotters as an example. Optional)

Mostly all of the optional configuration fields have a default value. You can look at the source code for more information.

Pic

Disclaimer

This bot has been written only for educational purposes. I hold no liability for what you do with this bot or what happens to you by using this bot. Abusing this bot may result in a permanent ban from Twitter (your account or IP address).

Metadata

Release files for twitter-santa 2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for twitter-santa 2.3
File Size Uploaded Provenance Actions
twitter-santa-2.3.tar.gz 14.3 kB Without provenance Details for twitter-santa-2.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for twitter-santa 2.3
File Interpreter ABI Platform Actions
twitter_santa-2.3-py2.py3-none-any.whl Python 2, Python 3 none any Details for twitter_santa-2.3-py2.py3-none-any.whl

Total release size: 29.0 kB

Release files / twitter-santa-2.3.tar.gz

Download URL twitter-santa-2.3.tar.gz
Size 14.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0abbdcbfbf926093724349f5ffe6ef85919ea8401ee4bcf7d316427c0209d47d
BLAKE2b-256 checksum
How to use checksums
7b54f4f8b52a1e8054e79aec9773c9f0b0b500313d21431bf61b569fdb8132bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15rc1

Release files / twitter_santa-2.3-py2.py3-none-any.whl

Download URL twitter_santa-2.3-py2.py3-none-any.whl
Size 14.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
8df2b343186c12c44bad6d880f9eff56775ee6fbb78ee13d14dfe0c570b65657
BLAKE2b-256 checksum
How to use checksums
269a4885eabea8c1ff18071a729b1edc3500235a2e85a1f8754aec3bb052e582
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.4.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/2.7.15rc1

Security for twitter-santa 2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page