@@ -121,14 +121,16 @@ def url(self):
121
121
def _beautiful_soup (content ):
122
122
"""
123
123
Parses HTML content into a BeautifulSoup object.
124
+
124
125
Parameters
125
126
----------
126
127
content: :class:`str`
127
128
The HTML content.
128
129
129
130
Returns
130
131
-------
131
- :class:`bs4.BeautifulSoup`: The parsed content.
132
+ :class:`bs4.BeautifulSoup`
133
+ The parsed content.
132
134
"""
133
135
return bs4 .BeautifulSoup (content .replace ('ISO-8859-1' , 'utf-8' ), 'lxml' ,
134
136
parse_only = bs4 .SoupStrainer ("div" , class_ = "BoxContent" ))
@@ -177,12 +179,10 @@ def _parse_current_member(guild, previous_rank, values):
177
179
----------
178
180
guild: :class:`dict`[str, Any]
179
181
Dictionary where information will be stored.
180
- previous_rank
181
- values
182
-
183
- Returns
184
- -------
185
-
182
+ previous_rank: :class:`dict`[int, str]
183
+ The last rank present in the rows.
184
+ values: tuple[:class:`str`]
185
+ A list of row contents.
186
186
"""
187
187
rank , name , vocation , level , joined , status = values
188
188
rank = previous_rank [1 ] if rank == " " else rank
@@ -205,12 +205,32 @@ def _parse_current_member(guild, previous_rank, values):
205
205
206
206
@staticmethod
207
207
def _parse_guild_applications (guild , info_container ):
208
+ """
209
+ Parses the guild's application info.
210
+
211
+ Parameters
212
+ ----------
213
+ guild: :class:`dict`[str, Any]
214
+ Dictionary where information will be stored.
215
+ info_container: :class:`bs4.Tag`
216
+ The parsed content of the information container.
217
+ """
208
218
m = applications_regex .search (info_container .text )
209
219
if m :
210
220
guild ["open_applications" ] = m .group (1 ) == "opened"
211
221
212
222
@staticmethod
213
223
def _parse_guild_disband_info (guild , info_container ):
224
+ """
225
+ Parses the guild's disband info, if available.
226
+
227
+ Parameters
228
+ ----------
229
+ guild: :class:`dict`[str, Any]
230
+ Dictionary where information will be stored.
231
+ info_container: :class:`bs4.Tag`
232
+ The parsed content of the information container.
233
+ """
214
234
m = disband_regex .search (info_container .text )
215
235
if m :
216
236
guild ["disband_condition" ] = m .group (2 )
@@ -221,6 +241,16 @@ def _parse_guild_disband_info(guild, info_container):
221
241
222
242
@staticmethod
223
243
def _parse_guild_guildhall (guild , info_container ):
244
+ """
245
+ Parses the guild's guildhall info.
246
+
247
+ Parameters
248
+ ----------
249
+ guild: :class:`dict`[str, Any]
250
+ Dictionary where information will be stored.
251
+ info_container: :class:`bs4.Tag`
252
+ The parsed content of the information container.
253
+ """
224
254
m = guildhall_regex .search (info_container .text )
225
255
if m :
226
256
guild ["guildhall" ] = {"name" : m .group ("name" ), "paid_until" : m .group ("date" ).replace ("\xa0 " , " " )}
@@ -229,6 +259,16 @@ def _parse_guild_guildhall(guild, info_container):
229
259
230
260
@staticmethod
231
261
def _parse_guild_homepage (guild , info_container ):
262
+ """
263
+ Parses the guild's homepage info.
264
+
265
+ Parameters
266
+ ----------
267
+ guild: :class:`dict`[str, Any]
268
+ Dictionary where information will be stored.
269
+ info_container: :class:`bs4.Tag`
270
+ The parsed content of the information container.
271
+ """
232
272
m = homepage_regex .search (info_container .text )
233
273
if m :
234
274
guild ["homepage" ] = m .group (1 )
@@ -237,6 +277,16 @@ def _parse_guild_homepage(guild, info_container):
237
277
238
278
@staticmethod
239
279
def _parse_guild_info (guild , info_container ):
280
+ """
281
+ Parses the guild's general information.
282
+
283
+ Parameters
284
+ ----------
285
+ guild: :class:`dict`[str, Any]
286
+ Dictionary where information will be stored.
287
+ info_container: :class:`bs4.Tag`
288
+ The parsed content of the information container.
289
+ """
240
290
m = founded_regex .search (info_container .text )
241
291
if m :
242
292
description = m .group ("desc" ).strip ()
@@ -247,6 +297,21 @@ def _parse_guild_info(guild, info_container):
247
297
248
298
@staticmethod
249
299
def _parse_guild_list (content , active_only = False ):
300
+ """
301
+ Parses the contents of a world's guild list page.
302
+
303
+ Parameters
304
+ ----------
305
+ content: :class:`str`
306
+ The HTML content of the page.
307
+ active_only: :class:`bool`
308
+ Whether to only show active guilds.
309
+
310
+ Returns
311
+ -------
312
+ List[:class:`dict`[str, Any]]
313
+ A list of guild dictionaries.
314
+ """
250
315
parsed_content = Guild ._beautiful_soup (content )
251
316
selected_world = parsed_content .find ('option' , selected = True )
252
317
try :
@@ -284,6 +349,21 @@ def _parse_guild_list(content, active_only=False):
284
349
285
350
@staticmethod
286
351
def _parse_guild_logo (guild , parsed_content ):
352
+ """
353
+ Parses the guild's logo.
354
+
355
+ Parameters
356
+ ----------
357
+ guild: :class:`dict`[str, Any]
358
+ Dictionary where information will be stored.
359
+ parsed_content: :class:`bs4.Tag`
360
+ The parsed content of the page.
361
+
362
+ Returns
363
+ -------
364
+ :class:`bool`
365
+ Whether the logo was found or not.
366
+ """
287
367
logo_img = parsed_content .find ('img' , {'height' : '64' })
288
368
if logo_img is None :
289
369
return False
@@ -293,25 +373,55 @@ def _parse_guild_logo(guild, parsed_content):
293
373
294
374
@staticmethod
295
375
def _parse_guild_members (guild , parsed_content ):
376
+ """
377
+ Parses the guild's member and invited list.
378
+
379
+ Parameters
380
+ ----------
381
+ guild: :class:`dict`[str, Any]
382
+ Dictionary where information will be stored.
383
+ parsed_content: :class:`bs4.Tag`
384
+ The parsed content of the guild's page
385
+ """
296
386
member_rows = parsed_content .find_all ("tr" , {'bgcolor' : ["#D4C0A1" , "#F1E0C6" ]})
297
387
guild ["members" ] = []
298
388
guild ["invites" ] = []
299
389
previous_rank = {}
300
390
for row in member_rows :
301
391
columns = row .find_all ('td' )
302
- values = (c .text .replace ("\u00a0 " , " " ) for c in columns )
392
+ values = tuple (c .text .replace ("\u00a0 " , " " ) for c in columns )
303
393
if len (columns ) == COLS_GUILD_MEMBER :
304
394
Guild ._parse_current_member (guild , previous_rank , values )
305
395
if len (columns ) == COLS_INVITED_MEMBER :
306
396
Guild ._parse_invited_member (guild , values )
307
397
308
398
@staticmethod
309
399
def _parse_guild_name (guild , parsed_content ):
400
+ """
401
+ Parses the guild's name.
402
+
403
+ Parameters
404
+ ----------
405
+ guild: :class:`dict`[str, Any]
406
+ Dictionary where information will be stored.
407
+ parsed_content: :class:`bs4.Tag`
408
+ The parsed content of guild's page.
409
+ """
310
410
header = parsed_content .find ('h1' )
311
411
guild ["name" ] = header .text
312
412
313
413
@staticmethod
314
414
def _parse_invited_member (guild , values ):
415
+ """
416
+ Parses the column texts of an invited row into a invited dictionary.
417
+
418
+ Parameters
419
+ ----------
420
+ guild: :class:`dict`[str, Any]
421
+ Dictionary where information will be stored.
422
+ values: tuple[:class:`str`]
423
+ A list of row contents.
424
+ """
315
425
name , date = values
316
426
if date != "Invitation Date" :
317
427
guild ["invites" ].append ({
@@ -329,9 +439,9 @@ def list_from_content(content, active_only=False):
329
439
330
440
Parameters
331
441
----------
332
- content: str
442
+ content: :class:` str`
333
443
The html content of the page.
334
- active_only: bool
444
+ active_only: :class:` bool`
335
445
Whether to only show active guilds or not.
336
446
337
447
Returns
@@ -346,10 +456,9 @@ def list_from_content(content, active_only=False):
346
456
def from_content (content ) -> Optional ['Guild' ]:
347
457
"""Creates an instance of the class from the html content of the guild's page.
348
458
349
-
350
459
Parameters
351
460
-----------
352
- content: str
461
+ content: :class:` str`
353
462
The HTML content of the page.
354
463
355
464
Returns
@@ -378,12 +487,12 @@ def get_url(name):
378
487
379
488
Parameters
380
489
------------
381
- name: str
490
+ name: :class:` str`
382
491
The name of the guild
383
492
384
493
Returns
385
494
--------
386
- str
495
+ :class:` str`
387
496
The URL to the guild's page"""
388
497
return GUILD_URL + urllib .parse .quote (name .encode ('iso-8859-1' ))
389
498
@@ -393,12 +502,12 @@ def get_world_list_url(world):
393
502
394
503
Parameters
395
504
----------
396
- world: str
505
+ world: :class:` str`
397
506
The name of the world
398
507
399
508
Returns
400
509
-------
401
- str
510
+ :class:` str`
402
511
The URL to the guild's page
403
512
"""
404
513
return GUILD_LIST_URL + urllib .parse .quote (world .title ().encode ('iso-8859-1' ))
@@ -410,11 +519,11 @@ def json_list_from_content(content, active_only=False, indent=None):
410
519
411
520
Parameters
412
521
----------
413
- content: str
522
+ content: :class:` str`
414
523
The html content of the page.
415
- active_only: bool
524
+ active_only: :class:` bool`
416
525
Whether to only show active guilds or not.
417
- indent: int
526
+ indent: :class:` int`
418
527
The number of spaces to indent the output with.
419
528
420
529
Returns
@@ -431,15 +540,16 @@ def parse_to_json(content, indent=None):
431
540
432
541
Parameters
433
542
-------------
434
- content: str
543
+ content: :class:` str`
435
544
The HTML content of the page.
436
- indent: int
545
+ indent: :class:` int`
437
546
The number of spaces to indent the output with.
438
547
439
548
Returns
440
549
------------
441
550
:class:`str`
442
- A string in JSON format."""
551
+ A string in JSON format.
552
+ """
443
553
char_dict = Guild ._parse (content )
444
554
return json .dumps (char_dict , indent = indent )
445
555
@@ -500,8 +610,8 @@ class GuildInvite(abc.Character):
500
610
The name of the character
501
611
502
612
date: :class:`datetime.date`
503
- The day when the character was invited."""
504
-
613
+ The day when the character was invited.
614
+ """
505
615
__slots__ = ("date" , )
506
616
507
617
def __init__ (self , name = None , date = None ):
0 commit comments