aboutsummaryrefslogtreecommitdiffstats
path: root/docs/index.rst
blob: 8e82f55b7c4bd9e0d495da012999283dc2738845 (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
.. bbss.py documentation master file, created by
   sphinx-quickstart on Tue Dec  5 20:26:05 2023.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

.. role:: python(code)
   :language: python

=======
bbss.py
=======

For more information on BBSS itself, look `here <https://forum.melonland.net/index.php?topic=2047.0>`_.
This is a simple python module to allow for quickly scraping or exploring BBSS directories on sites.

bbss.site
=========

.. py:module:: bbss.site

   .. py:class:: Site(domain, path, *, scheme = 'https')

      A representation of some BBSS directory. On construction, all information about an individual site
      is downloaded.

      :param str domain: The domain to check for BBSS files

      :param path: An optional subdirectory to treat as the root of the BBSS directory
      :type path: str or None
      :param scheme: What protocol to download over
      :type scheme: 'http' | 'https'

      .. py:attribute:: default_path
         :type: bool

         Whether the site was generated from a default directory, or a user-supplied one

      .. py:attribute:: root
         :type: str

         The base URL of the BBSS directory

      .. py:attribute:: has_sizes_txt
         :type: bool

         Whether the BBSS directory contains a ``sizes.txt`` file

      .. py:attribute:: sizes
         :type: bbss.sizes.SizeListFile

         A list of the sizes found at the site

      .. py:attribute:: friends
         :type: Optional[bbss.friends.FriendListFile]

         A list of friend sites found at the site

     .. doctest::

       >>> site = bbss.site.Site('aleteoryx.me')
       >>> for size in site.sizes:
       ...   print(f"{size.entry} @ {size.url()}")
       ...   if size.exists():
       ...     for button in size.get():
       ...       print(f"===> {button.entry} @ {button.url()}")
       ...   else:
       ...     print("...doesn't seem to exist!")
       ...
       88x31 @ https://aleteoryx.me/BBSS/88x31/list.txt
       ===> ame.gif @ https://aleteoryx.me/BBSS/88x31/ame.gif
       ===> amev2.gif @ https://aleteoryx.me/BBSS/88x31/amev2.gif

bbss.lists
==========

.. py:module:: bbss.lists

   .. py:function:: parse_listfile[T](contents, ctor)

      Parses in the text of a listfile, and calls the passed constructor
      function repeatedly to generate datastructures.

      :param str contents: The contents of the listfile
      :param ctor: The constructor for the internal datastructures
      :type ctor: (str, str or None) -> T
      :return: A list of T, containing the contents of the file
      :rtype: list[T]

      .. doctest::

         >>> listfile = """
         ... entry 1
         ... ## this is a comment on entry two
         ... entry 2
         ... # omitted
         ... entry 3
         ... ## trailing comments are ignored
         ... """
         >>> bbss.lists.parse_listfile(listfile, lambda x, y: (x, y))
         [('entry 1', None), ('entry 2', 'this is a comment on entry two'), ('entry 3', None)]

   .. py:class:: ListFileEntry(entry, comment)

      The base class for all listfile entries

      :param str entry: The main content of the entry
      :param comment: The comment, if present
      :type comment: str or None

   .. py:class:: BaseListFile(contents)

      The base class for all listfile representations

      It supports all the :py:class:`collections.abc.Sequence` operations, meaning it can be used like a list in most cases.

      :param str contents: The contents of the source listfile

      .. py:classmethod:: from_url(url)

         Alternate constructor, which will attempt to download the listfile at ``url``.

         :param str url: The URL to download from.
         :return: A representation of the remote file, if available
         :rtype: BaseListFile | None

   .. py:class:: ListFile(contents)

      A representation of an arbitrary listfile

      It supports all the :py:class:`collections.abc.Sequence` operations, meaning it can be used like a list in most cases.

      :param str contents: The contents of the source listfile

      .. doctest::

         >>> contents = """
         ... entry 1
         ... ## this is a comment on entry two
         ... entry 2
         ... # omitted
         ... entry 3
         ... ## trailing comments are ignored
         ... """
         >>> listfile = bbss.lists.ListFile(contents)
         >>> for entry in listfile:
         ...   print(">", entry.entry)
         ...   if entry.comment is not None:
         ...     print(f"  ``{entry.comment}''")
         ...
         > entry 1
         > entry 2
           ``this is a comment on entry two''
         > entry 3

      .. py:classmethod:: from_url(url)

         Alternate constructor, which will attempt to download the listfile at ``url``.

         :param str url: The URL to download from.
         :return: A representation of the remote file, if available
         :rtype: BaseListFile | None

bbss.buttons
============

.. py:module:: bbss.buttons

   .. py:class:: ButtonListFileEntry(entry, comment, root)

      A representation of a button image

      :param str entry: The button's filename
      :param comment: The comment for this button
      :type comment: str or None
      :param str root: The URL that this button is a child of

      .. py:method:: url()

         :return: The URL of the button file
         :rtype: str

      .. py:method:: exists()

         :return: Whether the button actually exists on the server
         :rtype: bool

      .. py:method:: get()

         :return: The HTTP response from trying to ``GET`` the button
         :rtype: requests.Response

   .. py:class:: ButtonListFile(contents)

      A representation of a list of buttons

      It supports all the :py:class:`collections.abc.Sequence` operations, meaning it can be used like a list in most cases.

      :param str contents: The contents of the source listfile

      .. py:classmethod:: from_url(url)

         Alternate constructor, which will attempt to download the listfile at ``url``.

         :param str url: The URL to download from.
         :return: A representation of the remote button list, if available
         :rtype: ButtonListFile | None

         .. doctest::

            >>> buttons = bbss.buttons.ButtonListFile \
            ...             .from_url("https://aleteoryx.me/BBSS/88x31/list.txt")
            >>> for button in buttons:
            ...   print(button.url())
            ...
            https://aleteoryx.me/BBSS/88x31/ame.gif
            https://aleteoryx.me/BBSS/88x31/amev2.gif

bbss.sizes
============

.. py:module:: bbss.sizes

   .. py:class:: SizeListFileEntry(entry, comment, root)

      A representation of a given size for buttons

      :param str entry: The actual size
      :param comment: The comment for this size
      :type comment: str or None
      :param str root: The BBSS directory that this size is within

      .. py:method:: url()

         :return: The URL of the size's button list
         :rtype: str

      .. py:method:: exists()

         :return: Whether the size's button list file exists
         :rtype: bool

      .. py:method:: get()

         :return: The actual button list, if available
         :rtype: bbss.buttons.ButtonListFile

      .. py:method:: dims()

         :return: The dimensions of the size, ``(x, y)``, if they can be parsed from the name
         :rtype: (int, int) or None

   .. py:class:: SizeListFile(contents)

      A representation of a list of button sizes

      It supports all the :py:class:`collections.abc.Sequence` operations, meaning it can be used like a list in most cases.

      :param str contents: The contents of the source listfile

      .. py:classmethod:: from_url(url)

         Alternate constructor, which will attempt to download the listfile at ``url``

         :param str url: The URL to download from.
         :return: A representation of the remote size list, if available
         :rtype: ButtonListFile | None

bbss.friends
============

.. py:module:: bbss.friends

   .. py:class:: FriendListFileEntry(entry, comment)

      A representation of a friend site

      :param str entry: The actual size
      :param comment: The comment for this size
      :type comment: str or None

      .. py:attribute:: url
         :type: str

         The URL of the size's button list

      .. py:attribute:: domain
         :type: str

         The domain of the friend site

      .. py:attribute:: scheme
         :type: str

         The scheme of the friend site

      .. py:attribute:: path
         :type: str

         The optional path of the remote BBSS directory

      .. py:method:: exists()

         :return: Whether the size's button list file exists
         :rtype: bool

      .. py:method:: get()

         :return: The remote site
         :rtype: bbss.site.Size

   .. py:class:: FriendListFile(contents)

      A representation of a list of friend sites

      It supports all the :py:class:`collections.abc.Sequence` operations, meaning it can be used like a list in most cases.

      :param str contents: The contents of the source listfile

      .. py:classmethod:: from_url(url)

         Alternate constructor, which will attempt to download the listfile at ``url``

         :param str url: The URL to download from.
         :return: A representation of the remote friend list, if available
         :rtype: ButtonListFile | None

==================
Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`