forked from nolan/titlebot-ng-ng
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
import yaml
|
|
import re
|
|
import asyncio
|
|
import sqlite3
|
|
from nio import AsyncClient, LoginResponse, RoomSendResponse, RoomMessageText, SyncResponse
|
|
import time
|
|
from post import Post
|
|
from room import Room
|
|
|
|
async def main():
|
|
room = Room()
|
|
|
|
# Login to Matrix
|
|
if not await room.login_to_matrix():
|
|
print("Failed to login")
|
|
return
|
|
|
|
|
|
# await room.alert_post("SCRAPER LOGGED IN")
|
|
|
|
# Initial sync
|
|
await room.client.sync(timeout=3000)
|
|
|
|
try:
|
|
while True:
|
|
# Get last run timestamp
|
|
room.get_last_run()
|
|
if room.last_run:
|
|
print(f"Last run for this room was at UNIX timestamp {room.last_run}")
|
|
|
|
# Scrape and write to database
|
|
await room.get_convos()
|
|
room.write_to_db()
|
|
# Ack newly recorded suggestions with a ✅ reaction
|
|
await room.acknowledge_new_suggestions()
|
|
room.update_last_run()
|
|
print(f"Stored {len(room.posts)} suggestions in database.")
|
|
await asyncio.sleep(0.5)
|
|
finally:
|
|
# Close connection
|
|
await room.close()
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main()) |