add markov bullshit
This commit is contained in:
parent
225e81fded
commit
4d6647bd6b
3 changed files with 30 additions and 3 deletions
28
delojza.py
28
delojza.py
|
@ -8,6 +8,7 @@ import sys
|
|||
from glob import glob
|
||||
|
||||
import filetype
|
||||
import markovify
|
||||
import requests
|
||||
import youtube_dl
|
||||
from telegram import MessageEntity
|
||||
|
@ -21,6 +22,17 @@ logging.basicConfig(level=logging.INFO,
|
|||
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
|
||||
logger = logging.getLogger("kunsax")
|
||||
|
||||
markov: markovify.NewlineText
|
||||
|
||||
|
||||
def add_to_corpus(text):
|
||||
global markov
|
||||
text = text.lower()
|
||||
new_sentence = markovify.NewlineText(text)
|
||||
markov = markovify.combine([markov, new_sentence])
|
||||
with open("initial.txt", 'a') as f:
|
||||
f.write(text + '\n')
|
||||
|
||||
|
||||
def datestr(date):
|
||||
return date.strftime("%Y-%m-%d@%H%M")
|
||||
|
@ -178,15 +190,19 @@ def handle_rest(bot, update):
|
|||
handle([url], update.message, download_raw, filename=filename)
|
||||
|
||||
|
||||
def handle_text(bot, update):
|
||||
add_to_corpus(update.message.text)
|
||||
|
||||
|
||||
def start(bot, update):
|
||||
update.message.reply_text('WOOP WOOP')
|
||||
update.message.reply_text(markov.make_sentence())
|
||||
|
||||
|
||||
def error(bot, update, error):
|
||||
logger.error(error)
|
||||
if "Timed out" in str(error):
|
||||
if update is not None:
|
||||
update.message.reply_text("Mmmm, I like it.")
|
||||
update.message.reply_text(markov.make_sentence(tries=100) or "Mmmm, I like it...")
|
||||
handle_rest(bot, update)
|
||||
else:
|
||||
if update is not None:
|
||||
|
@ -194,6 +210,13 @@ def error(bot, update, error):
|
|||
|
||||
|
||||
def main():
|
||||
global markov
|
||||
|
||||
with open("initial.txt") as f:
|
||||
text = f.read()
|
||||
markov = markovify.NewlineText(text.lower())
|
||||
print(markov.make_sentence())
|
||||
|
||||
updater = Updater("***REMOVED***")
|
||||
|
||||
dp = updater.dispatcher
|
||||
|
@ -208,6 +231,7 @@ def main():
|
|||
Filters.photo | Filters.video | Filters.video_note | Filters.audio | Filters.voice | Filters.document,
|
||||
handle_rest))
|
||||
dp.add_handler(MessageHandler(Filters.entity(MessageEntity.HASHTAG), handle_hashtag))
|
||||
dp.add_handler(MessageHandler(Filters.text, handle_text))
|
||||
|
||||
updater.start_polling()
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
python-telegram-bot
|
||||
youtube-dl
|
||||
requests
|
||||
filetype
|
||||
filetype
|
||||
markovify
|
|
@ -12,9 +12,11 @@ cryptography==2.3.1 # via python-telegram-bot
|
|||
filetype==1.0.1
|
||||
future==0.16.0 # via python-telegram-bot
|
||||
idna==2.7 # via cryptography, requests
|
||||
markovify==0.7.1
|
||||
pycparser==2.19 # via cffi
|
||||
python-telegram-bot==11.1.0
|
||||
requests==2.19.1
|
||||
six==1.11.0 # via cryptography
|
||||
unidecode==1.0.22 # via markovify
|
||||
urllib3==1.23 # via requests
|
||||
youtube-dl==2018.9.26
|
||||
|
|
Loading…
Reference in a new issue