blob: 3829ae9c0caa2735b795e81948b7a86d2cf00fe4 (
plain) (
blame)
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
40
41
42
43
44
45
46
47
48
49
50
51
|
from bbss.sizes import SizeListFile
import bbss.friends as friends
from bbss import DEFAULT_PATHS
from typing import Optional
from collections.abc import Sequence
import requests
class Site:
def __init__(self, domain: str, path: Optional[str] = None, *, scheme: Optional[str] = None):
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("No BBSS data found at user-supplied location!")
else:
self.default_path = False
else:
for potential in DEFAULT_PATHS:
if check_path(potential):
path = potential
self.default_path = True
break
else:
raise Exception("No BBSS data found at default locations!")
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 = friends.FriendListFile.from_url(self.root + "/friends.txt")
__all__ = ["Site"]
|