2
0
mirror of https://github.com/pyrogram/pyrogram synced 2025-08-31 06:16:06 +00:00

Move single methods, types and bound-methods to separated pages

The resulting pages were huge and were also taking a while to load
This will improve docs navigation
This commit is contained in:
Dan
2019-07-09 19:03:46 +02:00
parent ee2d5b1315
commit efcf7d5503
9 changed files with 662 additions and 637 deletions

View File

@@ -23,6 +23,7 @@ import shutil
HOME = "compiler/docs"
DESTINATION = "docs/source/telegram"
PYROGRAM_API_DEST = "docs/source/api"
FUNCTIONS_PATH = "pyrogram/api/functions"
TYPES_PATH = "pyrogram/api/types"
@@ -117,6 +118,352 @@ def generate(source_path, base):
f.write("\n")
def pyrogram_api():
def get_title_list(s: str) -> list:
return [i.strip() for i in [j.strip() for j in s.split("\n") if j] if i]
# Methods
categories = dict(
utilities="""
Utilities
start
stop
restart
idle
run
add_handler
remove_handler
stop_transmission
export_session_string
""",
messages="""
Messages
send_message
forward_messages
send_photo
send_audio
send_document
send_sticker
send_animated_sticker
send_video
send_animation
send_voice
send_video_note
send_media_group
send_location
send_venue
send_contact
send_cached_media
edit_message_text
edit_message_caption
edit_message_media
edit_message_reply_markup
edit_inline_text
edit_inline_caption
edit_inline_media
edit_inline_reply_markup
send_chat_action
delete_messages
get_messages
get_history
get_history_count
read_history
iter_history
send_poll
vote_poll
stop_poll
retract_vote
download_media
""",
chats="""
Chats
join_chat
leave_chat
kick_chat_member
unban_chat_member
restrict_chat_member
promote_chat_member
export_chat_invite_link
set_chat_photo
delete_chat_photo
set_chat_title
set_chat_description
pin_chat_message
unpin_chat_message
get_chat
get_chat_member
get_chat_members
get_chat_members_count
iter_chat_members
get_dialogs
iter_dialogs
get_dialogs_count
restrict_chat
update_chat_username
archive_chats
unarchive_chats
""",
users="""
Users
get_me
get_users
get_profile_photos
get_profile_photos_count
iter_profile_photos
set_profile_photo
delete_profile_photos
update_username
get_user_dc
block_user
unblock_user
""",
contacts="""
Contacts
add_contacts
get_contacts
get_contacts_count
delete_contacts
""",
password="""
Pssword
enable_cloud_password
change_cloud_password
remove_cloud_password
""",
bots="""
Bots
get_inline_bot_results
send_inline_bot_result
answer_callback_query
answer_inline_query
request_callback_answer
send_game
set_game_score
get_game_high_scores
""",
advanced="""
Advanced
send
resolve_peer
save_file
"""
)
root = PYROGRAM_API_DEST + "/methods"
shutil.rmtree(root, ignore_errors=True)
os.mkdir(root)
with open("template/methods.rst") as f:
template = f.read()
with open(root + "/index.rst", "w") as f:
fmt_keys = {}
for k, v in categories.items():
name, *methods = get_title_list(v)
fmt_keys.update({k: "\n ".join("{0} <{0}>".format(m) for m in methods)})
for method in methods:
with open(root + "/{}.rst".format(method), "w") as f2:
title = "{}()".format(method)
f2.write(title + "\n" + "=" * len(title) + "\n\n")
f2.write(".. automethod:: pyrogram.Client.{}()".format(method))
f.write(template.format(**fmt_keys))
# Types
categories = dict(
users_chats="""
Users & Chats
User
UserStatus
Chat
ChatPreview
ChatPhoto
ChatMember
ChatPermissions
Dialog
""",
messages_media="""
Messages & Media
Message
MessageEntity
Photo
Thumbnail
Audio
Document
Animation
Video
Voice
VideoNote
Contact
Location
Venue
Sticker
Game
WebPage
Poll
PollOption
""",
bots_keyboard="""
Bots & Keyboards
ReplyKeyboardMarkup
KeyboardButton
ReplyKeyboardRemove
InlineKeyboardMarkup
InlineKeyboardButton
ForceReply
CallbackQuery
GameHighScore
CallbackGame
""",
input_media="""
Input Media
InputMedia
InputMediaPhoto
InputMediaVideo
InputMediaAudio
InputMediaAnimation
InputMediaDocument
InputPhoneContact
""",
inline_mode="""
Inline Mode
InlineQuery
InlineQueryResult
InlineQueryResultArticle
""",
input_message_content="""
InputMessageContent
InputMessageContent
InputTextMessageContent
"""
)
root = PYROGRAM_API_DEST + "/types"
shutil.rmtree(root, ignore_errors=True)
os.mkdir(root)
with open("template/types.rst") as f:
template = f.read()
with open(root + "/index.rst", "w") as f:
fmt_keys = {}
for k, v in categories.items():
name, *types = get_title_list(v)
fmt_keys.update({k: "\n ".join(types)})
# noinspection PyShadowingBuiltins
for type in types:
with open(root + "/{}.rst".format(type), "w") as f2:
title = "{}".format(type)
f2.write(title + "\n" + "=" * len(title) + "\n\n")
f2.write(".. autoclass:: pyrogram.{}()".format(type))
f.write(template.format(**fmt_keys))
# Bound Methods
categories = dict(
message="""
Message
Message.click
Message.delete
Message.download
Message.forward
Message.pin
Message.edit_text
Message.edit_caption
Message.edit_media
Message.edit_reply_markup
Message.reply_text
Message.reply_animation
Message.reply_audio
Message.reply_cached_media
Message.reply_chat_action
Message.reply_contact
Message.reply_document
Message.reply_game
Message.reply_inline_bot_result
Message.reply_location
Message.reply_media_group
Message.reply_photo
Message.reply_poll
Message.reply_sticker
Message.reply_venue
Message.reply_video
Message.reply_video_note
Message.reply_voice
""",
chat="""
Chat
Chat.archive
Chat.unarchive
Chat.set_title
Chat.set_description
Chat.set_photo
Chat.kick_member
Chat.unban_member
Chat.restrict_member
Chat.promote_member
""",
user="""
User
User.archive
User.unarchive
""",
callback_query="""
Callback Query
CallbackQuery.answer
CallbackQuery.edit_message_text
CallbackQuery.edit_message_caption
CallbackQuery.edit_message_media
CallbackQuery.edit_message_reply_markup
""",
inline_query="""
InlineQuery
InlineQuery.answer
"""
)
root = PYROGRAM_API_DEST + "/bound-methods"
shutil.rmtree(root, ignore_errors=True)
os.mkdir(root)
with open("template/bound-methods.rst") as f:
template = f.read()
with open(root + "/index.rst", "w") as f:
fmt_keys = {}
for k, v in categories.items():
name, *bound_methods = get_title_list(v)
fmt_keys.update({"{}_hlist".format(k): "\n ".join("- :meth:`~{}`".format(bm) for bm in bound_methods)})
fmt_keys.update(
{"{}_toctree".format(k): "\n ".join("{} <{}>".format(bm.split(".")[1], bm) for bm in bound_methods)})
# noinspection PyShadowingBuiltins
for bm in bound_methods:
with open(root + "/{}.rst".format(bm), "w") as f2:
title = "{}()".format(bm)
f2.write(title + "\n" + "=" * len(title) + "\n\n")
f2.write(".. automethod:: pyrogram.{}()".format(bm))
f.write(template.format(**fmt_keys))
def start():
global page_template
global toctree
@@ -131,6 +478,7 @@ def start():
generate(TYPES_PATH, TYPES_BASE)
generate(FUNCTIONS_PATH, FUNCTIONS_BASE)
pyrogram_api()
if "__main__" == __name__:
@@ -138,5 +486,6 @@ if "__main__" == __name__:
TYPES_PATH = "../../pyrogram/api/types"
HOME = "."
DESTINATION = "../../docs/source/telegram"
PYROGRAM_API_DEST = "../../docs/source/api"
start()