-
Notifications
You must be signed in to change notification settings - Fork 2
/
announcements.py
39 lines (30 loc) · 911 Bytes
/
announcements.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from cardinal import Cardinal
from tg_bot.utils import NotificationTypes
from threading import Thread
import requests
import json
import os
import time
DELAY = 600
def get_last_tag():
if not os.path.exists("storage/cache/announcement_tag.txt"):
return None
with open("storage/cache/announcement_tag.txt", "r", encoding="UTF-8") as f:
data = f.read()
return data
def save_last_tag(tag: str):
if not os.path.exists("storage/cache"):
os.makedirs("storage/cache")
with open("storage/cache/announcement_tag.txt", "w", encoding="UTF-8") as f:
f.write(tag)
def get_photo(url: str) -> bytes | None:
try:
response = requests.get(url)
if response.status_code != 200:
return None
except:
return None
return response.content