Added a dry run option
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
16
main.py
16
main.py
@@ -2,15 +2,21 @@ import os
|
|||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from telethon.sync import TelegramClient
|
from telethon.sync import TelegramClient
|
||||||
import markovify
|
import markovify
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument("-d", "--dry", action='store_true', help="Run without sending a message")
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
|
|
||||||
api_id = os.getenv('API_ID')
|
api_id = os.getenv('API_ID')
|
||||||
api_hash = os.getenv('API_HASH')
|
api_hash = os.getenv('API_HASH')
|
||||||
entity = os.getenv('ENTITY')
|
entity = os.getenv('ENTITY')
|
||||||
|
dry_run = args.dry
|
||||||
|
|
||||||
f = open("data/data.txt", "r")
|
with open("data/data.txt", "r") as f:
|
||||||
text = f.read()
|
text = f.read()
|
||||||
|
|
||||||
text_model = markovify.Text(text)
|
text_model = markovify.Text(text)
|
||||||
message = ''
|
message = ''
|
||||||
@@ -18,6 +24,8 @@ message = ''
|
|||||||
for i in range(5):
|
for i in range(5):
|
||||||
message = message + text_model.make_sentence()
|
message = message + text_model.make_sentence()
|
||||||
|
|
||||||
with TelegramClient('bot', api_id, api_hash) as client:
|
if (dry_run):
|
||||||
|
print(message)
|
||||||
|
else:
|
||||||
|
with TelegramClient('bot', api_id, api_hash) as client:
|
||||||
client.send_message(entity=entity, message=message)
|
client.send_message(entity=entity, message=message)
|
||||||
|
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
markovify
|
markovify
|
||||||
telethon
|
telethon
|
||||||
python-dotenv
|
python-dotenv
|
||||||
|
argparse
|
||||||
|
|||||||
Reference in New Issue
Block a user