Compare commits

..

3 commits

Author SHA1 Message Date
bec08bcf48 Clean up imports 2024-01-13 15:01:11 -08:00
8f786b4dfa Make follow-up posts be unlisted 2024-01-13 15:00:05 -08:00
1b1753ae52 Correct user to SclOutage 2024-01-13 14:35:08 -08:00

32
scl.py
View file

@ -1,19 +1,11 @@
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from mastodon import Mastodon
import sqlite3
from typing import List
from typing import Optional
from sqlalchemy import ForeignKey, select
from sqlalchemy import String
from sqlalchemy.orm import DeclarativeBase
from sqlalchemy.orm import Mapped
from sqlalchemy.orm import Session
from sqlalchemy.orm import mapped_column
from sqlalchemy.orm import relationship
import requests
from mastodon import Mastodon
from sqlalchemy import create_engine, select
from sqlalchemy.exc import NoResultFound
from sqlalchemy import create_engine
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
post_datetime_format = "%b %e %l:%M %p"
@ -36,20 +28,16 @@ class SclOutage(Base):
__tablename__ = "scl_outages"
scl_outage_id: Mapped[int] = mapped_column(primary_key=True, unique=True)
outage_user_id: Mapped[str] = mapped_column()
most_recent_post_id: Mapped[str] = mapped_column()
most_recent_post_id: Mapped[Optional[str]] = mapped_column()
last_updated_time: Mapped[datetime] = mapped_column()
estimated_restoration_time: Mapped[datetime] = mapped_column()
cause: Mapped[str] = mapped_column()
outage_size: Mapped[str] = mapped_column()
status: Mapped[Optional[str]] = mapped_column()
no_longer_in_response_time: Mapped[
Optional[datetime]
] = (
mapped_column()
) # If the event is no longer being returned in the response, this will be set to the current time
no_longer_in_response_time: Mapped[Optional[datetime]] = mapped_column()
def __repr__(self) -> str:
return f"User(scl_outage_id={self.scl_outage_id!r}, most_recent_post_id={self.most_recent_post_id!r}, last_updated_time={self.last_updated_time!r}, no_longer_in_response_time={self.no_longer_in_response_time!r})"
return f"SclOutage(scl_outage_id={self.scl_outage_id!r}, most_recent_post_id={self.most_recent_post_id!r}, last_updated_time={self.last_updated_time!r}, no_longer_in_response_time={self.no_longer_in_response_time!r})"
engine = create_engine("sqlite:///scl.db")
@ -130,7 +118,7 @@ with Session(engine) as session:
mastodon_post_result = mastodon.status_post(
status="\n".join(updated_entries),
in_reply_to_id=existing_record.most_recent_post_id,
visibility="public",
visibility="unlisted",
)
existing_record.most_recent_post_id = mastodon_post_result["id"]
@ -183,7 +171,7 @@ Cause: {}
active_outage.outage_user_id
),
in_reply_to_id=active_outage.most_recent_post_id,
visibility="public",
visibility="unlisted",
)
active_outage.most_recent_post_id = mastodon_post_result["id"]