|
| 1 | +# Pyrogram - Telegram MTProto API Client Library for Python |
| 2 | +# Copyright (C) 2017-2019 Dan Tès <https://github.com/delivrance> |
| 3 | +# |
| 4 | +# This file is part of Pyrogram. |
| 5 | +# |
| 6 | +# Pyrogram is free software: you can redistribute it and/or modify |
| 7 | +# it under the terms of the GNU Lesser General Public License as published |
| 8 | +# by the Free Software Foundation, either version 3 of the License, or |
| 9 | +# (at your option) any later version. |
| 10 | +# |
| 11 | +# Pyrogram is distributed in the hope that it will be useful, |
| 12 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | +# GNU Lesser General Public License for more details. |
| 15 | +# |
| 16 | +# You should have received a copy of the GNU Lesser General Public License |
| 17 | +# along with Pyrogram. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + |
| 19 | +import shutil |
| 20 | +from datetime import datetime |
| 21 | +from pathlib import Path |
| 22 | + |
| 23 | +import pypandoc |
| 24 | +import requests |
| 25 | + |
| 26 | +URL = "https://api.github.com/repos/pyrogram/pyrogram/releases" |
| 27 | +DEST = Path("source/releases") |
| 28 | +INTRO = """ |
| 29 | +Release Notes |
| 30 | +============= |
| 31 | +
|
| 32 | +Release notes for Pyrogram releases will describe what's new in each version, and will also make you aware of any |
| 33 | +backwards-incompatible changes made in that version. |
| 34 | +
|
| 35 | +When upgrading to a new version of Pyrogram, you will need to check all the breaking changes in order to find |
| 36 | +incompatible code in your application, but also to take advantage of new features and improvements. |
| 37 | +
|
| 38 | +Releases |
| 39 | +-------- |
| 40 | +
|
| 41 | +""".lstrip("\n") |
| 42 | + |
| 43 | +shutil.rmtree(DEST, ignore_errors=True) |
| 44 | +DEST.mkdir(parents=True) |
| 45 | + |
| 46 | +releases = requests.get(URL).json() |
| 47 | + |
| 48 | +with open(DEST / "index.rst", "w") as index: |
| 49 | + index.write(INTRO) |
| 50 | + |
| 51 | + tags = [] |
| 52 | + |
| 53 | + for release in releases: |
| 54 | + tag = release["tag_name"] |
| 55 | + title = release["name"] |
| 56 | + name = title.split(" - ")[1] |
| 57 | + |
| 58 | + date = datetime.strptime( |
| 59 | + release["published_at"], |
| 60 | + "%Y-%m-%dT%H:%M:%SZ" |
| 61 | + ).strftime("%b %d, %Y - %H:%M:%S (UTC)") |
| 62 | + |
| 63 | + body = pypandoc.convert_text( |
| 64 | + release["body"].replace(r"\r\n", "\n"), |
| 65 | + "rst", |
| 66 | + format="markdown_github", |
| 67 | + extra_args=["--wrap=none"] |
| 68 | + ) |
| 69 | + |
| 70 | + index.write("- :doc:`{} <{}>`\n".format(title, tag)) |
| 71 | + tags.append(tag) |
| 72 | + |
| 73 | + with open(DEST / "{}.rst".format(tag), "w") as page: |
| 74 | + page.write("Pyrogram " + tag + "\n" + "=" * (len(tag) + 9) + "\n\n") |
| 75 | + page.write("--- *Released on " + str(date) + "*\n\n") |
| 76 | + page.write(name + "\n" + "-" * len(name) + "\n\n") |
| 77 | + page.write(body + "\n\n") |
| 78 | + |
| 79 | + index.write("\n.. toctree::\n :hidden:\n\n") |
| 80 | + index.write("\n".join(" {}".format(tag) for tag in tags)) |
0 commit comments