51 lines
1.8 KiB
Python
Executable File
51 lines
1.8 KiB
Python
Executable File
import html
|
|
import time
|
|
|
|
from reeere.ai import add_reply_link, check_gen, generate_response
|
|
from reeere.board import find_most_recent_thread, get_threads, get_sub_forums, get_thread_texts
|
|
from reeere.post import post_data
|
|
from reeere.settings import *
|
|
|
|
|
|
def main():
|
|
sub_forums = get_sub_forums()
|
|
|
|
for sub_forum in sub_forums:
|
|
print('=================================')
|
|
print(sub_forum['title'], '-->', sub_forum['link'])
|
|
sub_forum_link = sub_forum["link"]
|
|
posts = get_threads(sub_forum_link)
|
|
most_recent_thread, most_recent_reply = find_most_recent_thread(posts, required_posts=False)
|
|
|
|
if most_recent_thread:
|
|
print(f'Generating response to post {most_recent_reply["id"]}:')
|
|
print(html.unescape(most_recent_reply['text']))
|
|
print('\n====')
|
|
context = get_thread_texts(most_recent_thread)
|
|
|
|
our_reply = False
|
|
for i in range(10):
|
|
gen = add_reply_link(generate_response(context), most_recent_reply["id"])
|
|
reply_is_good = check_gen(gen)
|
|
if not reply_is_good:
|
|
print('AI generated shit:', gen)
|
|
else:
|
|
our_reply = gen
|
|
break
|
|
if not our_reply:
|
|
print('Failed to generate a reply, AI model was shit.')
|
|
continue
|
|
print('\nOur reply:')
|
|
print(our_reply)
|
|
print('\n====\nPosting:')
|
|
time.sleep(30)
|
|
r = post_data(our_reply, most_recent_thread['id'], sub_forum['link'])
|
|
print(r.status_code, r.text)
|
|
else:
|
|
print(f"No threads found in sub-forum {sub_forum_link}")
|
|
print('=================================')
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|