mirror of
https://github.com/pyrogram/pyrogram
synced 2025-09-05 00:35:10 +00:00
Move docs scripts into a dedicated folder
This commit is contained in:
84
docs/scripts/releases.py
Normal file
84
docs/scripts/releases.py
Normal file
@@ -0,0 +1,84 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from pathlib import Path
|
||||
|
||||
import pypandoc
|
||||
import requests
|
||||
|
||||
URL = "https://api.github.com/repos/pyrogram/pyrogram/releases"
|
||||
DEST = Path("../source/releases")
|
||||
INTRO = """
|
||||
Release Notes
|
||||
=============
|
||||
|
||||
Release notes for Pyrogram releases will describe what's new in each version, and will also make you aware of any
|
||||
backwards-incompatible changes made in that version.
|
||||
|
||||
When upgrading to a new version of Pyrogram, you will need to check all the breaking changes in order to find
|
||||
incompatible code in your application, but also to take advantage of new features and improvements.
|
||||
|
||||
**Contents**
|
||||
|
||||
""".lstrip("\n")
|
||||
|
||||
shutil.rmtree(DEST, ignore_errors=True)
|
||||
DEST.mkdir(parents=True)
|
||||
|
||||
releases = requests.get(URL).json()
|
||||
|
||||
with open(DEST / "index.rst", "w") as index:
|
||||
index.write(INTRO)
|
||||
|
||||
tags = []
|
||||
|
||||
for release in releases:
|
||||
tag = release["tag_name"]
|
||||
title = release["name"]
|
||||
name = title.split(" - ")[1]
|
||||
|
||||
date = datetime.strptime(
|
||||
release["published_at"],
|
||||
"%Y-%m-%dT%H:%M:%SZ"
|
||||
).strftime("%b %d, %Y")
|
||||
|
||||
body = pypandoc.convert_text(
|
||||
release["body"].replace(r"\r\n", "\n"),
|
||||
"rst",
|
||||
format="markdown_github",
|
||||
extra_args=["--wrap=none"]
|
||||
)
|
||||
|
||||
tarball_url = release["tarball_url"]
|
||||
zipball_url = release["zipball_url"]
|
||||
|
||||
index.write("- :doc:`{} <{}>`\n".format(title, tag))
|
||||
tags.append(tag)
|
||||
|
||||
with open(DEST / "{}.rst".format(tag), "w") as page:
|
||||
page.write("Pyrogram " + tag + "\n" + "=" * (len(tag) + 9) + "\n\n")
|
||||
page.write("\t\tReleased on " + str(date) + "\n\n")
|
||||
page.write("- :download:`Source Code (zip) <{}>`\n".format(zipball_url))
|
||||
page.write("- :download:`Source Code (tar.gz) <{}>`\n\n".format(tarball_url))
|
||||
page.write(name + "\n" + "-" * len(name) + "\n\n")
|
||||
page.write(body + "\n\n")
|
||||
|
||||
index.write("\n.. toctree::\n :hidden:\n\n")
|
||||
index.write("\n".join(" {}".format(tag) for tag in tags))
|
81
docs/scripts/sitemap.py
Normal file
81
docs/scripts/sitemap.py
Normal file
@@ -0,0 +1,81 @@
|
||||
# Pyrogram - Telegram MTProto API Client Library for Python
|
||||
# Copyright (C) 2017-2020 Dan <https://github.com/delivrance>
|
||||
#
|
||||
# This file is part of Pyrogram.
|
||||
#
|
||||
# Pyrogram is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Lesser General Public License as published
|
||||
# by the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# Pyrogram is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Lesser General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import datetime
|
||||
import os
|
||||
|
||||
canonical = "https://docs.pyrogram.org/"
|
||||
|
||||
dirs = {
|
||||
".": ("weekly", 1.0),
|
||||
"intro": ("weekly", 0.9),
|
||||
"start": ("weekly", 0.9),
|
||||
"api": ("weekly", 0.8),
|
||||
"topics": ("weekly", 0.8),
|
||||
"releases": ("weekly", 0.8),
|
||||
"telegram": ("weekly", 0.6)
|
||||
}
|
||||
|
||||
|
||||
def now():
|
||||
return datetime.datetime.today().strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
with open("sitemap.xml", "w") as f:
|
||||
f.write('<?xml version="1.0" encoding="utf-8"?>\n')
|
||||
f.write('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">\n')
|
||||
|
||||
urls = []
|
||||
|
||||
|
||||
def search(path):
|
||||
try:
|
||||
for j in os.listdir(path):
|
||||
search("{}/{}".format(path, j))
|
||||
except NotADirectoryError:
|
||||
if not path.endswith(".rst"):
|
||||
return
|
||||
|
||||
path = path.split("/")[1:]
|
||||
|
||||
if path[0].endswith(".rst"):
|
||||
folder = "."
|
||||
else:
|
||||
folder = path[0]
|
||||
|
||||
path = "{}{}".format(canonical, "/".join(path))[:-len(".rst")]
|
||||
|
||||
if path.endswith("index"):
|
||||
path = path[:-len("index")]
|
||||
|
||||
urls.append((path, now(), *dirs[folder]))
|
||||
|
||||
|
||||
search("../source")
|
||||
|
||||
urls.sort(key=lambda x: x[3], reverse=True)
|
||||
|
||||
for i in urls:
|
||||
f.write(" <url>\n")
|
||||
f.write(" <loc>{}</loc>\n".format(i[0]))
|
||||
f.write(" <lastmod>{}</lastmod>\n".format(i[1]))
|
||||
f.write(" <changefreq>{}</changefreq>\n".format(i[2]))
|
||||
f.write(" <priority>{}</priority>\n".format(i[3]))
|
||||
f.write(" </url>\n\n")
|
||||
|
||||
f.write("</urlset>")
|
Reference in New Issue
Block a user