Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
scripts: dump discusion: Commit each edit
Browse files Browse the repository at this point in the history
Signed-off-by: John Andersen <[email protected]>
  • Loading branch information
pdxjohnny committed Jun 23, 2022
1 parent 9666c24 commit eb9eaf9
Showing 1 changed file with 64 additions and 4 deletions.
68 changes: 64 additions & 4 deletions scripts/dump_discussion.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,14 @@
import asyncio
import pathlib
import tempfile
import subprocess
from typing import Callable, Type, Union, NewType

import dffml


ROOT_PATH = pathlib.Path(__file__).parents[1]

INPUT = json.loads(pathlib.Path("output.json.formated.json").read_text())


Expand Down Expand Up @@ -140,16 +143,35 @@ def output_markdown(
# Data goes through azure log analytics
prefix = ["docs", "arch", "alice", "discussion"]
# prefix = ["docs", "tutorials", "alice"]
text = discussion_node["discussion"]["body"]
node = discussion_node["discussion"]
text = node["body"]
text = text.replace("\r", "")
# path.write_text(text)
# volume = current_volume(text)
path = output_directory.joinpath(
*[*prefix, "_".join([f"{0:04}"]), "index.md"],
)
relative_path = path.relative_to(ROOT_PATH)
print(path, repr(text[:100] + "..."))
if not path.parent.is_dir():
path.parent.mkdir(parents=True)
if node["userContentEdits"]:
for edit in node["userContentEdits"]["nodes"][::-1]:
if not edit["diff"]:
continue
path.write_text(edit["diff"].replace("\r", ""))
for cmd in [
["git", "add", str(relative_path),],
[
"git",
"commit",
"-sm",
": ".join(
list(relative_path.parts) + [edit["editedAt"]]
),
],
]:
subprocess.check_call(cmd, cwd=ROOT_PATH)
path.write_text(text)
for i, comment_node in enumerate(
discussion_node["discussion"]["comments"]["nodes"], start=1
Expand All @@ -165,33 +187,71 @@ def output_markdown(
"""
# Output a file for the comment
path = output_directory.joinpath(*filename_parts, "index.md")
relative_path = path.relative_to(ROOT_PATH)
node = comment_node
text = comment_node["body"]
text = text.replace("\r", "")
print(path, repr(text[:100] + "..."))
if not path.parent.is_dir():
path.parent.mkdir(parents=True)
if node["userContentEdits"]:
for edit in node["userContentEdits"]["nodes"][::-1]:
if not edit["diff"]:
continue
path.write_text(edit["diff"].replace("\r", ""))
for cmd in [
["git", "add", str(relative_path),],
[
"git",
"commit",
"-sm",
": ".join(
list(relative_path.parts) + [edit["editedAt"]]
),
],
]:
subprocess.check_call(cmd, cwd=ROOT_PATH)
path.write_text(text)
replys = []
# Output a file for the reply
for j, reply_node in enumerate(comment_node["replies"]["nodes"]):
path = output_directory.joinpath(
*[*filename_parts, "_".join(["reply", f"{j:04}"]) + ".md"],
)
relative_path = path.relative_to(ROOT_PATH)
node = reply_node
text = reply_node["body"]
text = text.replace("\r", "")
replys += text
print(path, repr(text[:100] + "..."))
if not path.parent.is_dir():
path.parent.mkdir(parents=True)
if node["userContentEdits"]:
for edit in node["userContentEdits"]["nodes"][::-1]:
if not edit["diff"]:
continue
path.write_text(edit["diff"].replace("\r", ""))
for cmd in [
["git", "add", str(relative_path),],
[
"git",
"commit",
"-sm",
": ".join(
list(relative_path.parts)
+ [edit["editedAt"]]
),
],
]:
subprocess.check_call(cmd, cwd=ROOT_PATH)
path.write_text(text)


async def main():
root_path = pathlib.Path(__file__).parents[1]
adr_path = root_path.joinpath("docs", "arch", "alice")
adr_path = ROOT_PATH.joinpath("docs", "arch", "alice")
if adr_path.is_dir():
shutil.rmtree(adr_path)
output_markdown(INPUT, root_path)
output_markdown(INPUT, ROOT_PATH)


if __name__ == "__main__":
Expand Down

0 comments on commit eb9eaf9

Please sign in to comment.