Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

working? #25

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3ae7bae
Minor/add config sample (#1)
MChambers1992 Jan 5, 2018
f81fa30
Major/refactor into methods and pep8 (#2)
MChambers1992 Jan 8, 2018
3bcebde
[MinorVersion] Delete obsolete config sample file
MChambers1992 Jan 8, 2018
222456e
[MinorVersion] Add logic to check tweet dates for retweets in main lo…
MChambers1992 Jan 9, 2018
ff5cdef
[MinorVersion] Update config sample, add additional logic to like twe…
MChambers1992 Jan 9, 2018
afc7054
[MinorVersion] Fix readme to be more accurate
MChambers1992 Jan 9, 2018
8b0b394
[MinorVersion] Improve filtering to reduce redundant requests to Twit…
MChambers1992 Jan 12, 2018
25b8626
[MinorVersion] Add hashtag count filtering (#6)
MChambers1992 Jan 19, 2018
3b95d08
[MajorVersion] Add basic follower management (#7)
MChambers1992 May 25, 2018
da51870
[MinorVersion] Small logic change around follower management (#8)
MChambers1992 Nov 30, 2018
ae9e4d3
[MajorVersion] File organization and module split (#9)
MChambers1992 Nov 30, 2018
b220325
[MinorVersion] Add support for multiple action days (#10)
MChambers1992 Jan 6, 2019
58955d9
[PatchVersion] Fix misc bugs (#11)
MChambers1992 Jan 18, 2019
2f6b96e
[MinorVersion] Add option to aggressively remove non-followers (#12)
MChambers1992 Feb 8, 2019
30d01c9
[NoVersion] Update link to config example (#13)
May 21, 2019
ba510fe
[NoVersion] Update README.md (#14)
May 21, 2019
35c8801
[MinorVersion] Add ability to block tweets with multiple urls (#15)
MChambers1992 May 21, 2019
e2e5b80
[MinorVersion] Regex Improvements, Filter Logic fix (#16)
MChambers1992 Jan 10, 2020
4e54e82
[MinorVersion] Improve filtering & file separation (#17)
MChambers1992 Jan 20, 2020
70aff00
[Minor] Refactoring & new additional features (#18)
MChambers1992 Mar 3, 2023
8f96c07
[Minor] Fix requirements (#19)
MChambers1992 Mar 3, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 113 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,113 @@
config
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/

# Translations
*.mo
*.pot

# Django stuff:
*.log
.static_storage/
.media/
local_settings.py

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/

# Config Files
config.json

#
last_id_hashtag_*

# VSCode
**/.vscode/**
52 changes: 37 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
Python Retweet Bot
Retweet Bot
==================

![alt text](https://img.shields.io/badge/python-3.5-green.svg "Python3.5")
![alt text](https://img.shields.io/badge/python-3.6-green.svg "Python3.6")

This script retweets all Tweets containing your search term. To limit Twitter requests a savepoint file marks Tweets found before. It's Twitter API v1.1 ready.
This script retweets certain tweets with a specific search query and can use parameters defined in the config file to perform additional actions. To limit Twitter requests it uses a savepoint for each configured query objects, search query id and marks the last tweet it retweeted.

Dependecies:
It's Twitter API v1.1 ready.

Requirements:
-------------
* Tweepy
You need Python 3.4 or later to run mypy. You can have multiple Python versions (2.x and 3.x) installed on the same system without problems.

To download Python 3.4 on Linux, OS X and Windows, packages are available at

```pip install tweepy```
http://www.python.org/getit/

* Or alternatively
Dependencies:
-------------
Install the dependencies like this:

```pip install -r requirements.txt```
```pip install -r requirements.txt```

How to start:
Quick start:
-------------

* Define your hashtag or search query in the config file
* Define the number of Retweets at a time (This avoids overloading -Limit is 180 RT/ 15 mins)
* Add your Twitter app credentials in the config file
* (Tune some other options if you like)
To start create a copy of ```config.SAMPLE.json``` and rename to ```config.json```, then follow the steps below.
* In ```config.json``` define your ```query_objects``` in the config file. See https://git.io/fjsGR for an example
* In ```config.json``` define your ```twitter_keys``` to the config file. Find these at https://apps.twitter.com/

If Python is installed correctly and your ```config.json``` file is setup, you can run the bot by using:
* $ python retweet.py
* Add this call to your crontab(unix)/task scheduler(windows) (or something similar) to retweet all new tweets regularly


Use as cron job
---------------

Create file at

```/etc/cron.d/retweet-bot```

With the contents

```
30 * * * * [your-user-here] cd ~/retweet-bot/src/ && python3 main.py >> ~/retweet-bot/twitter_bot.txt
```

Please use https://crontab.guru for more infomation on how to set intervals for cron jobs.

Compatibility
-------------

Compatible with Python 3.x ,tested on Python 3.5.
Compatible with Python 3.x, tested on Python 3.6.
59 changes: 59 additions & 0 deletions config/config.SAMPLE.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"general": {
"log_level": "DEBUG"
},
"twitter_keys": {
"screen_name": "DevMicrocosm",
"consumer_key": "",
"consumer_secret": "",
"access_token": "",
"access_token_secret": ""
},
"follower_management": {
"manage_followers": true,
"aggressive_management": false,
"days_to_manage": [0],
"months_to_manage": [13],
"inactivity_period": 14,
"max_unfollows": 300,
"follow_back": true,
"max_follows": 25,
"remove_followers": false
},
"query_objects": [{
"search_query": "#test1",
"tweet_language": "es",
"tweet_limit": 5,
"follow_poster": true,
"user_blacklist": ["", ""],
"word_blacklist": ["RT", "♺"],
"days_to_tweet": [1],
"months_to_tweet": [1, 4, 10],
"favourite_tweets": false,
"max_hashtags": 4,
"max_urls": 1,
"filter_mentions": true,
"filter_media": false,
"require_media": false,
"retweet": false,
"filter_profanity": true
},
{
"search_query": "#test2",
"tweet_language": "en",
"tweet_limit": 10,
"follow_poster": false,
"user_blacklist": ["", ""],
"word_blacklist": ["RT", "♺"],
"days_to_tweet": [2, 4],
"months_to_tweet": [13],
"favourite_tweets": false,
"max_hashtags": 4,
"max_urls": 0,
"filter_mentions": false,
"filter_media": false,
"require_media": false,
"retweet": false,
"filter_profanity": false
}]
}
5 changes: 2 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
tweepy==3.5.0
configparser==3.5.0

better_profanity==0.7.0
tweepy==3.8.0
86 changes: 0 additions & 86 deletions retweet.py

This file was deleted.

19 changes: 19 additions & 0 deletions src/common_methods.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Retweet Bot common methods used in multiple modules

import datetime

def can_perform_action_today(days_to_complete_action):
"""Checks the current day against the day actions should be performed"""

if datetime.datetime.today().weekday() in days_to_complete_action or 7 in days_to_complete_action:
return True

return False

def can_perform_action_this_month(months_to_complete_action):
"""Checks the current month against the month that actions should be performed"""

if datetime.datetime.today().month in months_to_complete_action or 13 in months_to_complete_action:
return True

return False
28 changes: 28 additions & 0 deletions src/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
"""Retweet Bot configuration module. Loads the JSON config file into memory."""

import logging
import json
import os

class Config():
"""Attempts to load and set the defined configuration"""

twitter_keys = {}
follower_management = {}
query_objects = {}
general = {}

def __init__(self):
try:
path = os.path.abspath(os.path.join(os.path.dirname( __file__ ),
'..', "config", "config.json"))
with open(path) as json_data_file:
config_data = json.load(json_data_file)

self.twitter_keys = config_data['twitter_keys']
self.follower_management = config_data['follower_management']
self.query_objects = config_data['query_objects']
self.general = config_data['general']

except Exception as err:
logging.error("Failed to load config. Error: %s", err)
Loading