Skip to content

Instantly share code, notes, and snippets.

@nekofar
Created September 26, 2019 09:35
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nekofar/c0512962b30d61b77a42b76f49fde817 to your computer and use it in GitHub Desktop.
Save nekofar/c0512962b30d61b77a42b76f49fde817 to your computer and use it in GitHub Desktop.
Create a Twitter list of following who suspected to be dangerous (AKA Naamn).
package main
import (
"log"
"regexp"
"github.com/dghubble/go-twitter/twitter"
"github.com/dghubble/oauth1"
)
func main() {
// Twitter screen name
ownerScreenName := ""
// Twitter consumer and token keys
consumerKey := ""
consumerSecret := ""
accessToken := ""
accessSecret := ""
// Create config and token using keys
config := oauth1.NewConfig(consumerKey, consumerSecret)
token := oauth1.NewToken(accessToken, accessSecret)
// Authorize requests using OAuth1
httpClient := config.Client(oauth1.NoContext, token)
// Create Twitter client
client := twitter.NewClient(httpClient)
// Create a Twitter list for dangerous users if not exist
list, _, _ := client.Lists.Show(&twitter.ListsShowParams{Slug: "dangerous", OwnerScreenName: ownerScreenName})
if list.ID == 0 {
_, _, err := client.Lists.Create("Dangerous", &twitter.ListsCreateParams{})
if err != nil {
log.Fatal(err)
}
}
// List of following users
var users []twitter.User
var cursor int64 = -1
// Loop through following to fetch recent fifteen hundred
for i := 0; i < 15; i++ {
if cursor == 0 {
break
}
// Fetch the list of following
following, _, err := client.Friends.List(&twitter.FriendListParams{Count: 100, Cursor: cursor})
if err != nil {
log.Fatal(err)
}
// Merge to the list of users
users = append(users, following.Users...)
cursor = following.NextCursor
}
// Loop through the list of users, and add those you suspected
// to be dangerous, to a twitter list for manual review
for _, user := range users {
// Make sure user registered between 2018-2020
matched, _ := regexp.MatchString("201[89]", user.CreatedAt)
if !matched || user.FollowersCount < 1000 {
continue
}
// Make sure number of following are more than half of followers
if user.FriendsCount/user.FollowersCount*100 < 50 {
continue
}
// Add user to the list of dangerous people
_, err := client.Lists.MembersCreate(&twitter.ListsMembersCreateParams{ListID: list.ID, UserID: user.ID})
if err != nil {
log.Fatal(err)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment