Compare commits

..

No commits in common. "bec08bcf4899cb8a286613ced4750030d188288f" and "1c41baacb4edd8cf448ae0c235a15cf9e4cc91b9" have entirely different histories.

30
scl.py
View file

@ -1,11 +1,19 @@
from datetime import datetime
from typing import Optional
import requests
from bs4 import BeautifulSoup
from mastodon import Mastodon
from sqlalchemy import create_engine, select
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
from sqlalchemy.exc import NoResultFound
from sqlalchemy.orm import DeclarativeBase, Mapped, Session, mapped_column
from sqlalchemy import create_engine
post_datetime_format = "%b %e %l:%M %p"
@ -28,16 +36,20 @@ 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[Optional[str]] = mapped_column()
most_recent_post_id: Mapped[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()
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
def __repr__(self) -> str:
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})"
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})"
engine = create_engine("sqlite:///scl.db")
@ -118,7 +130,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="unlisted",
visibility="public",
)
existing_record.most_recent_post_id = mastodon_post_result["id"]
@ -171,7 +183,7 @@ Cause: {}
active_outage.outage_user_id
),
in_reply_to_id=active_outage.most_recent_post_id,
visibility="unlisted",
visibility="public",
)
active_outage.most_recent_post_id = mastodon_post_result["id"]