Skip to content

Commit 9cb9967

Browse files
committed
pushing twitter post bot and scheduler
1 parent ae51e1d commit 9cb9967

File tree

6 files changed

+181
-2
lines changed

6 files changed

+181
-2
lines changed

README.md

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,78 @@
1-
# Twitter-auto-Post-Bot---X.com---Tweepy-python-bot
2-
Twitter auto tweeter, simple bot written in python, can post using file or via code.
1+
<div align="center">
2+
3+
# 🐦 Twitter Auto-Post Bot 🤖
4+
5+
[![Python](https://img.shields.io/badge/python-v3.7+-blue.svg)](https://www.python.org/downloads/release/python-370/)
6+
[![Tweepy](https://img.shields.io/badge/tweepy-v4.10-blue)](http://docs.tweepy.org/en/latest/)
7+
[![Schedule](https://img.shields.io/badge/schedule-v1.1.0-blue)](https://schedule.readthedocs.io/en/stable/)
8+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9+
10+
Automate your Twitter presence with elegance and ease. Crafted for social media enthusiasts, digital marketers, and developers.
11+
</div>
12+
13+
---
14+
15+
## 🌟 About The Project
16+
17+
This Python-based Twitter Auto-Post Bot automates tweeting, Credit to the Tweepy library for making this easy, this project enables scheduled and random tweets, offering a dynamic and engaging Twitter experience.
18+
19+
### 📁 Files Overview
20+
21+
- `schedule-daily-post-from-file.py`: Automates daily tweets, randomly selecting from `tweets.txt`.
22+
- `tweeter-from-code.py`: Immediately tweets a pre-defined message with the current date.
23+
- `tweeter-random-from-file.py`: Instantly posts a random tweet from `tweets.txt`.
24+
- `tweets.txt`: Add your tweets here, one per line. They will be randomly selected and tweeted.
25+
- `requirements.txt`: Lists all necessary Python packages.
26+
27+
### 📁 Upcoming Features
28+
- `Adding Feature to Auto fetch from openAI api and tweet based on a prompt`.
29+
30+
## 🚀 Getting Started
31+
32+
### Prerequisites
33+
34+
- Python 3.x
35+
- Tweepy (Twitter API)
36+
37+
### Installation
38+
39+
1. Clone the repo:
40+
```sh
41+
git clone git@github.com:lewispour/Twitter-auto-Post-Bot---X.com---Tweepy-python-bot.git
42+
```
43+
2. Install Python packages:
44+
```sh
45+
pip install -r requirements.txt
46+
```
47+
48+
### Setup
49+
50+
1. Obtain Twitter API credentials [here](https://developer.twitter.com/apps).
51+
2. update `keys.py` file with your credentials:
52+
```python
53+
bearer_token = "your_bearer_token"
54+
api_key = "your_api_key"
55+
api_secret = "your_api_secret"
56+
access_token = "your_access_token"
57+
access_token_secret = "your_access_token_secret"
58+
```
59+
3. Customize `tweets.txt` with your tweets.
60+
61+
## 🔧 Usage
62+
63+
Run any script using Python:
64+
65+
```bash
66+
python schedule-daily-post-from-file.py
67+
```
68+
69+
## 🤝 Contributing
70+
71+
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are **greatly appreciated**.
72+
73+
## 📝 License
74+
75+
Distributed under the MIT License. See `LICENSE` for more information.
76+
77+
## ✉️ Contact
78+
Project Link: [https://github.com/lewispour/Twitter-auto-Post-Bot---X.com---Tweepy-python-bot](https://github.com/lewispour/Twitter-auto-Post-Bot---X.com---Tweepy-python-bot)

keys.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
bearer_token = "GET_KEY_FROM_developer.twitter.com/apps"
2+
api_key = "GET_KEY_FROM_developer.twitter.com/apps"
3+
api_secret = "GET_KEY_FROM_developer.twitter.com/apps"
4+
access_token = "GET_KEY_FROM_developer.twitter.com/apps"
5+
access_token_secret = "GET_KEY_FROM_developer.twitter.com/apps"

schedule-daily-post-from-file.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import tweepy
2+
import datetime
3+
import random
4+
import keys
5+
import schedule
6+
import time
7+
8+
# Initialize Tweepy
9+
client = tweepy.Client(keys.bearer_token, keys.api_key, keys.api_secret, keys.access_token, keys.access_token_secret)
10+
auth = tweepy.OAuthHandler(keys.api_key, keys.api_secret, keys.access_token, keys.access_token_secret)
11+
api = tweepy.API(auth)
12+
13+
def sendPost():
14+
# Get the current date and time
15+
current_date = datetime.date.today()
16+
17+
# Format the date as a string
18+
formatted_date = current_date.strftime("%B %d, %Y")
19+
20+
# Read lines from the file
21+
with open('tweets.txt', 'r') as file:
22+
lines = file.readlines()
23+
24+
# Choose a random line and remove any leading/trailing whitespace
25+
tweet_text = random.choice(lines).strip()
26+
27+
# Send the tweet
28+
client.create_tweet(text=f"{tweet_text}")
29+
30+
# Print a message to indicate that the request was successful
31+
print("Tweet posted successfully")
32+
33+
# Schedule the job every day at 9 AM
34+
schedule.every().day.at("09:00").do(sendPost)
35+
36+
# Loop to keep the script running
37+
while True:
38+
schedule.run_pending()
39+
time.sleep(60) # Wait for one minute before checking again

tweeter-from-code.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import tweepy
2+
import datetime
3+
import keys
4+
5+
# Initialize Tweepy
6+
client = tweepy.Client(keys.bearer_token, keys.api_key, keys.api_secret, keys.access_token, keys.access_token_secret)
7+
auth = tweepy.OAuthHandler(keys.api_key, keys.api_secret, keys.access_token, keys.access_token_secret)
8+
api = tweepy.API(auth)
9+
10+
# Get the current date and time
11+
current_date = datetime.date.today()
12+
13+
# Format the date as a string
14+
formatted_date = current_date.strftime("%B %d, %Y")
15+
16+
def sendPost():
17+
# Send the tweet
18+
client.create_tweet(text=f"Hello Python 🐍. It is {formatted_date} today!🚀🚀.\nI am a bot 🤖. Meet me on Github https://github.com/lewispour/Twitter-auto-Post-Bot---X.com---Tweepy-python-bot")
19+
20+
# Print a message to indicate that the request was successful
21+
print("Tweet posted successfully")
22+
23+
# Call sendPost to execute it immediately
24+
sendPost()

tweeter-random-from-file.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import tweepy
2+
import datetime
3+
import random
4+
import keys
5+
6+
# Initialize Tweepy
7+
client = tweepy.Client(keys.bearer_token, keys.api_key, keys.api_secret, keys.access_token, keys.access_token_secret)
8+
auth = tweepy.OAuthHandler(keys.api_key, keys.api_secret, keys.access_token, keys.access_token_secret)
9+
api = tweepy.API(auth)
10+
11+
# Get the current date and time
12+
current_date = datetime.date.today()
13+
14+
# Format the date as a string
15+
formatted_date = current_date.strftime("%B %d, %Y")
16+
17+
def sendPost():
18+
# Read lines from the file
19+
with open('tweets.txt', 'r') as file:
20+
lines = file.readlines()
21+
22+
# Choose a random line and remove any leading/trailing whitespace
23+
tweet_text = random.choice(lines).strip()
24+
25+
# Send the tweet
26+
client.create_tweet(text=f"{tweet_text}")
27+
28+
# Print a message to indicate that the request was successful
29+
print("Tweet posted successfully")
30+
31+
# Call sendPost to execute it immediately
32+
sendPost()

tweets.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Here is a tweet
2+
here is a different tweet
3+
tweeet tweeet blah blah

0 commit comments

Comments
 (0)