From 4674f6463158ae86c1df72a8d2b240ecd6dc4439 Mon Sep 17 00:00:00 2001 From: klemek Date: Sat, 25 Apr 2020 11:14:59 +0200 Subject: [PATCH] docs building --- discord_bot/__main__.py | 2 +- docs/README.md | 46 +++++++++++++++++++++++++++++++++++++++++ docs/build_docs.py | 45 +++++++++++++++++++++++++++++++++++----- 3 files changed, 87 insertions(+), 6 deletions(-) create mode 100644 docs/README.md diff --git a/discord_bot/__main__.py b/discord_bot/__main__.py index 1e5b084..a6f37b9 100644 --- a/discord_bot/__main__.py +++ b/discord_bot/__main__.py @@ -122,7 +122,7 @@ async def on_message(message): if img is None: await message.channel.send(f":warning: Template `{args[0]}` not found\n" f"You can find a more detailed help and a list of templates at:\n" - f"") + f"") return with tempfile.NamedTemporaryFile(delete=False) as output: img.save(output, format="JPEG") diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..6b74353 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,46 @@ +#Hello + + +|||| +|:---:|:---:|:---:| +|**aliens**|**alive**
alt: no_brain|**argument**
alt: wrestlers| +|||| +|**bender**
alt: hookers, blackjack|**born_cool**|**brain3**| +|||| +|**brain4**
alt: brains|**brain5**|**buff**
alt: tom, jerry| +|||| +|**burn**|**button**|**bye_mom**
alt: google| +|||| +|**clock**|**culture**
alt: anime|**disappointed**| +|||| +|**distracted**
alt: boyfried, cheating, girlfriend|**dont_look**
alt: ricky, mom, influenced|**drake**| +|||| +|**drift**|**everywhere**
alt: buzz, woody|**everywhere2**
alt: angry| +|||| +|**fight**
alt: vaping|**fine**
alt: fire|**flex_tape**| +|||| +|**gate**|**girl_cat**|**grandma**| +|||| +|**gru**|**guys**|**handshake**| +|||| +|**handshake2**|**idea**|**lion**
alt: shady, king| +|||| +|**meeting**
alt: boardroom, suggestion|**mini**
alt: joker|**nobody_cares**
alt: nobody, jurassic, park, jurassic_park| +|||| +|**nope**|**overconfident**
alt: alcohol, depressed|**patrick**
alt: wallet, id| +|||| +|**pigeon**
alt: butterfly|**pills**|**pleasure3**
alt: satisfied3| +|||| +|**pleasure4**
alt: pleasure, satisfied, satisfied4|**salt_bae**
alt: salt|**scary**
alt: spongebob, fearless| +|||| +|**seagull2**
alt: seagull, screaming|**seagull4**|**see_that_guy**| +|||| +|**sleeping**
alt: brain|**spiderman**
alt: same|**struggle**
alt: choice, hero| +|||| +|**t_pose**
alt: dominance|**tom_cousins**
alt: cousins, backup|**tough2**
alt: tough, fight| +|||| +|**tough2bis**|**tough3**|**trump**
alt: law| +|||| +|**trust_nobody**
alt: yourself, gun|**truth**
alt: scroll| +|||| + diff --git a/docs/build_docs.py b/docs/build_docs.py index a32ac66..be91b38 100644 --- a/docs/build_docs.py +++ b/docs/build_docs.py @@ -11,8 +11,10 @@ imgf.load_fonts() meme_db.load_memes() dst_dir = utils.relative_path(__file__, "templates") - templates_dir = utils.relative_path(__file__, "..", "templates") +doc_file = utils.relative_path(__file__, "README.md") + +COLUMNS = 3 if path.exists(dst_dir): for f in os.listdir(dst_dir): @@ -21,14 +23,47 @@ if path.exists(dst_dir): else: os.mkdir(dst_dir) -count = 0 +ids = sorted(meme_db.DATA.keys()) -for meme_id in meme_db.DATA: +doc_content = "|" * (COLUMNS + 1) \ + + "\n|" + ":---:|" * COLUMNS + +info_line = None +img_line = None + +i = None +for i, meme_id in enumerate(ids): meme = meme_db.get_meme(meme_id) if meme is not None: img = imgf.make(meme.template, meme.texts, debug=True) if img is not None: img.save(path.join(dst_dir, meme.template)) - count += 1 + if i % COLUMNS == 0: + if info_line is not None and img_line is not None: + doc_content += info_line + img_line + info_line = "\n|" + img_line = "\n|" + info_line += f"**{meme_id}**" + if len(meme.aliases) > 0: + info_line += f"
alt: {', '.join(meme.aliases)}" + if meme.info is not None: + info_line += f"
more info" + info_line += "|" + img_line += f"" \ + f"" \ + f"|" -print(f"{count} registered templates / {len(os.listdir(templates_dir))} files") \ No newline at end of file +doc_content += "|" * (COLUMNS - (i % COLUMNS)) + +with open(doc_file, mode='r') as f: + content = "".join(f.readlines()) + +i0 = content.index("") +i1 = content.index("") + len("") + +with open(doc_file, mode='w') as f: + f.write(content[:i0]) + f.write("\n") + f.write(doc_content) + f.write("\n") + f.write(content[i1:])