GithubHelp home page GithubHelp logo

twitter_guard's Introduction

twitter_guard

Introduction

A Python package for defending against harassment on Twitter.

Supported Python Versions

Python 3.9+

Installation

Install directly from github

#if you are using python3.9, for example
python3.9 -m pip install --user git+https://github.com/corruptbear/twitter_guard

Configuration

To use the package, create apifree.yaml, white_list.yaml and block_list.yaml in the folder where your own script resides.

touch apifree.yaml && touch white_list.yaml && touch block_list.yaml

apifree.yaml

Before first time use, set latest_cursor field as "".

filtering_rule: your_custom_filtering_rule
latest_cursor: "" 
login:
  email: your_actual_stuff_here
  password: your_actual_stuff_here
  phonenumber: your_actual_stuff_here
  screenname: your_actual_stuff_here

put known friends in white_list.yaml line by line

id1_of_your_friend: name1_of_your_friend
id2_of_your_friend: name2_of_your_friend

put known friends in block_list.yaml line by line

id1_of_your_enemy: name1_of_your_enemy
id2_of_your_enemy: name2_of_your_enemy

Quick Examples

check the notification tab and block bad users.

import os
from twitter_guard.apifree_bot import TwitterBot

#specify the paths of configs and cookies
pwd = os.path.dirname(os.path.realpath(__file__))
COOKIE_PATH = os.path.join(pwd, "sl_cookies.pkl")
#COOKIE_PATH = os.path.join(pwd,'twitter.com_cookies.txt')#alternatively using Netscape cookie file
CONFIG_PATH = os.path.join(pwd, "apifree.yaml")#optional, if the cookie is not valid, then you will need the credentials in the config file
WHITE_LIST_PATH = os.path.join(pwd, "white_list.yaml")#optional
BLOCK_LIST_PATH = os.path.join(pwd, "block_list.yaml")#optional

#create the bot
bot = TwitterBot(
    cookie_path=COOKIE_PATH,#absolutely mandatory
    config_path=CONFIG_PATH,
    white_list_path=WHITE_LIST_PATH,
    block_list_path=BLOCK_LIST_PATH,
)

try:
    # use a small query to test the validity of cookies
    bot.get_badge_count()
except:
	#in order to refresh cookies, you have to supply valid credentials in the config
    bot.refresh_cookies()

#examing recent interactions, and block users according to the filtering_rule defined in apifree.yaml
bot.check_notifications(block=True)

filtering rule

logic expression describing bad accounts

  • logic operators: not and or
  • arithmatic operators: + - * /
  • comparison operators: > < >= <= == !=
  • keywords: followers_count following_count tweet_count media_count favourites_count days

Example

"(followers_count <= 5 and following_count <= 5) or (days <= 180)"
"(followers_count <= 10 and following_count <= 10) or (days <= 360) or ((followers_count/(tweet_count + 1) > 20) and tweet_count < 100)"

twitter_guard's People

Contributors

corruptbear avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 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.