Compare commits

...

2 Commits

1 changed files with 12 additions and 10 deletions

View File

@ -4,6 +4,8 @@ import sqlite3
from random import expovariate from random import expovariate
import typing import typing
import aiohttp import aiohttp
from utils import http_session_factory
async def make_sentence(cfg): async def make_sentence(cfg):
# set default # set default
@ -81,8 +83,8 @@ async def make_sentence(cfg):
# using aiohttp # using aiohttp
post = None post = None
while post is None: async with http_session_factory() as session:
async with aiohttp.ClientSession() as session: while post is None:
async with session.post( async with session.post(
"https://api.textsynth.com/v1/engines/{}/completions".format(cfg["textsynth_engine_id"]), "https://api.textsynth.com/v1/engines/{}/completions".format(cfg["textsynth_engine_id"]),
headers={ headers={
@ -103,14 +105,14 @@ async def make_sentence(cfg):
continue continue
post: str = data["text"] post: str = data["text"]
# check wether the post only consists of mentions # check wether the post only consists of mentions
# split by words # split by words
words = post.split() words = post.split()
# check if all words are mentions # check if all words are mentions
if all(word.startswith("@") for word in words): if all(word.startswith("@") for word in words):
# generate a new sentence # generate a new sentence
post = None post = None
continue continue
db.close() db.close()