Files
politics-mark/main.py
Anatoly 00b1287ef3
All checks were successful
continuous-integration/drone/push Build is passing
Catch none type sentences
2022-04-03 10:55:20 +03:00

35 lines
763 B
Python

import os
from dotenv import load_dotenv
from telethon.sync import TelegramClient
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()
api_id = os.getenv('API_ID')
api_hash = os.getenv('API_HASH')
entity = os.getenv('ENTITY')
dry_run = args.dry
with open("data/data.txt", "r") as f:
text = f.read()
text_model = markovify.Text(text)
message = ''
for i in range(5):
try:
message = message + text_model.make_sentence()
except:
pass
if (dry_run):
print(message)
else:
with TelegramClient('bot', api_id, api_hash) as client:
client.send_message(entity=entity, message=message)