Skip to content

Commit 97db57e

Browse files
committed
refactoring to make it more modular
1 parent 55de4de commit 97db57e

14 files changed

+77
-95
lines changed

__pycache__/keys.cpython-312.pyc

346 Bytes
Binary file not shown.
618 Bytes
Binary file not shown.
File renamed without changes.
File renamed without changes.

schedule-daily-post-from-file.py

Lines changed: 0 additions & 39 deletions
This file was deleted.

src/__init__.py

Whitespace-only changes.
1.37 KB
Binary file not shown.
1.94 KB
Binary file not shown.

src/functions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import tweepy
2+
import datetime
3+
import sys
4+
sys.path.append('../config') # Adds the config directory to the path
5+
import keys # Now we can import keys
6+
7+
def initialize_tweepy():
8+
client = tweepy.Client(keys.bearer_token, keys.api_key, keys.api_secret, keys.access_token, keys.access_token_secret)
9+
auth = tweepy.OAuthHandler(keys.api_key, keys.api_secret, keys.access_token, keys.access_token_secret)
10+
api = tweepy.API(auth)
11+
return client, api
12+
13+
def get_formatted_date():
14+
current_date = datetime.date.today()
15+
return current_date.strftime("%B %d, %Y")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
import os
3+
import random
4+
import schedule
5+
import time
6+
7+
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'config'))
8+
import keys
9+
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
10+
from functions import initialize_tweepy, get_formatted_date
11+
12+
def send_post():
13+
client, _ = initialize_tweepy()
14+
15+
with open(os.path.join(os.path.dirname(__file__), '..', 'data', 'tweets.txt'), 'r') as file:
16+
lines = file.readlines()
17+
tweet_text = random.choice(lines).strip()
18+
client.create_tweet(text=f"{tweet_text}")
19+
20+
print("Tweet posted successfully")
21+
22+
schedule.every().day.at("09:00").do(send_post)
23+
24+
while True:
25+
schedule.run_pending()
26+
time.sleep(60)

0 commit comments

Comments
 (0)