Skip to content

Instantly share code, notes, and snippets.

@igorbrigadir
Last active March 30, 2024 09:35
Show Gist options
  • Save igorbrigadir/5343a81f160a06913a169253e91d64c6 to your computer and use it in GitHub Desktop.
Save igorbrigadir/5343a81f160a06913a169253e91d64c6 to your computer and use it in GitHub Desktop.
Twitter Mutuals CSV with twarc
#!/bin/bash
# run this like ./mutuals.sh screen_name
# Get all the accounts you follow
twarc2 followers "$1" "$1_followers.jsonl"
# Get all the accounts that follow you
twarc2 following "$1" "$1_following.jsonl"
# Get mutuals ids
mutuals_ids=`comm -1 -2 <(sort <(twarc2 flatten "$1_following.jsonl" | jq '.id')) <(sort <(twarc2 flatten "$1_followers.jsonl" | jq '.id'))`
# Filter on ids and output as CSV
twarc2 flatten "$1_following.jsonl" | jq --arg ids "$mutuals_ids" 'select([.id] | inside($ids|split(" ")))' -c > "$1_mutuals.jsonl"
twarc2 csv --input-data-type users "$1_mutuals.jsonl" "$1_mutuals.csv"
#!/bin/bash
# Install latest twarc and plugins
pip3 install --upgrade twarc twarc-csv pandas>=1.2.3
# Configure twarc with tokens
twarc2 configure
# Install jq
# https://stedolan.github.io/jq/download/
sudo apt-get install jq
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment