GithubHelp home page GithubHelp logo

xdevplatform / extract-usernames-from-tweet-replies Goto Github PK

View Code? Open in Web Editor NEW
23.0 5.0 7.0 21 KB

Python script to pull replies to a specific Tweet and extract user mentions

License: Apache License 2.0

Python 100.00%
python twitter twitter-api twitter-api-v2

extract-usernames-from-tweet-replies's Introduction

Retrieve Tweet replies

This Python script pulls all direct replies to a specified Tweet, extracts user mentions from the replies, and returns a list of usernames ordered by most to least frequently mentioned in the replies.

This script uses v2 of the Twitter API, and more specifically:

Additional details on how to run this code, including instructions on how to replace the full-archive search endpoint with the recent search endpoint, are available here.

Requirements

  • Twitter developer account.
  • Developer Project and App with access to the v2 full-archive search endpoint: GET /2/tweets/search/all.

You can read more about getting access to all of the above in Twitter's developer docs.

Authentication & set up

Rename .env_example to .env and add the credentials for your developer App in between the "".

TWITTER_CONSUMER_KEY=""
TWITTER_CONSUMER_SECRET=""
TWITTER_ACCESS_TOKEN=""
TWITTER_ACCESS_TOKEN_SECRET=""
TWITTER_BEARER_TOKEN=""

Don't forget to add .env to your .gitignore file to keep your credentials secure.

You will also need to install the requests and python-dotenv Python modules:

$ pip3 install requests python-dotenv

Running the script

$ python3 replies.py -t <TWEET-ID>
Flags
-t Tweet ID Required ID of the Tweet for which you want to pull data.
-h Help Optional View a list of available flags and a description for each of these.
-s Start time Optional The oldest UTC timestamp from which the replies will be provided. Format: YYYY-MM-DDTHH:mm:ssZ; for example: 2021-12-04T01:30:00Z. If unspecified, will default to returning replies from up to 30 days ago.
-e End time Optional The newest, most recent UTC timestamp to which the replies will be provided. Format: YYYY-MM-DDTHH:mm:ssZ; for example: 2021-12-04T01:30:00Z. If unspecified, will default to [now - 30 seconds].

Run the following command to see a list of available flags:

$ python3 replies.py -h

Output

Returned in the command line interface

  • Ordered dictionary containing: a list of all usernames present in the replies and the number of times each username was mentioned. Note: the username who authored the original Tweet is not included.
  • Number of replies to the Tweet.
  • Number of usernames mentioned in these replies.
  • Total request count made to the Search API to get these replies.

Returned in a new file

  • replies.txt containing a list of Tweet IDs for the replies.

extract-usernames-from-tweet-replies's People

Contributors

andypiper avatar aureliaspecker avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  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.