From e21e42e832e4ac633a9d48f6e30c34a9011008bc Mon Sep 17 00:00:00 2001 From: alyx Date: Sat, 25 Nov 2023 22:31:49 -0500 Subject: Main interface done. Up next: docs, logging, and polish --- src/bbss/site.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/bbss/site.py (limited to 'src/bbss/site.py') diff --git a/src/bbss/site.py b/src/bbss/site.py new file mode 100644 index 0000000..7e8871f --- /dev/null +++ b/src/bbss/site.py @@ -0,0 +1,51 @@ +from .sizes import SizeListFile +from .friends import FriendListFile +from . import DEFAULT_PATHS +from typing import Optional +from collections.abc import Sequence +import requests + +class Site: + def __init__(self, domain: str, path: Optional[str], *, scheme: Optional[str]): + base = (scheme if scheme is not None else "https") + "://" + domain + + hit_sizefile = False + + def check_sizefile(path: str) -> bool: + return requests.head(base + path + "/sizes.txt").ok + def check_defaultlist(path: str) -> bool: + return requests.head(base + path + "/88x31/list.txt").ok + + def check_path(path: str): + if check_sizefile(path): + hit_sizefile = True + return True + elif check_defaultlist(path): + return True + + if path is not None: + if not check_path(path): + raise Exception("Oh noes there's nothing.") + else: + self.using_default = False + else: + for potential in DEFAULT_PATHS: + if check_path(potential): + path = potential + self.using_default = True + break + else: + raise Exception("Oh noes there's nothing(no path specified).") + + self.root = base + path + + if hit_sizefile: + self.has_sizes_txt = True + self.sizes = SizeListFile.from_url(self.root + "/sizes.txt") + else: + self.has_sizes_txt = False + self.sizes = SizeListFile("88x31", self.root) + + self.friends = FriendListFile.from_url(self.root + "/friends.txt") + +__all__ = ["Site"] -- cgit v1.2.3-54-g00ecf