[f2203b]: / tutorials / generate_tutorial.py

Download this file

92 lines (81 with data), 3.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
"""
Generate `tutorial_name` with placeholder
> python generate_tutorial.py Tutorial_Name
Tutorial_Name/
├── Concepts/
│ ├── Introduction.md # Overview of the tutorial
│ ├── Chapter1_Concept1.md # Detailed explanation of concept 1
│ ├── Chapter2_Concept2.md # Detailed explanation of concept 2
│ └── ...
├── Code/
│ ├── Source_Code/ # Folder for source code files
│ │ ├── main.py # Main code file
│ │ ├── utils.py # Utility functions
│ │ └── ...
│ │
│ ├── Examples/ # Folder for code examples
│ │ ├── example1.py # Code example 1
│ │ ├── example2.py # Code example 2
│ │ └── ...
│ │
│ └── README.md # Instructions for running code, dependencies, etc.
├── Docs/
│ ├── Tutorial_Documentation.md # Documentation for the tutorial
│ ├── API_Documentation.md # Documentation for any APIs used
│ └── ...
├── Assets/ # Folder for images, diagrams, etc.
│ ├── diagrams/ # Diagrams illustrating concepts
│ ├── screenshots/ # Screenshots of code output or examples
│ └── ...
├── README.md # Overview of the tutorial, setup instructions, etc.
└── LICENSE # License information for the tutorial
"""
import os
import sys
def generate_tutorial_structure(tutorial_name):
# Create the main tutorial folder
os.makedirs(tutorial_name)
# Create Concepts folder and files
concepts_path = os.path.join(tutorial_name, "Concepts")
os.makedirs(concepts_path)
open(os.path.join(concepts_path, "Introduction.md"), 'a').close()
open(os.path.join(concepts_path, "Chapter1_Concept1.md"), 'a').close()
open(os.path.join(concepts_path, "Chapter2_Concept2.md"), 'a').close()
# Create Code folder and files
code_path = os.path.join(tutorial_name, "Code")
os.makedirs(code_path)
src_code = tutorial_name.lower().replace(" ","_")
os.makedirs(os.path.join(code_path, src_code))
open(os.path.join(code_path, src_code, "main.py"), 'a').close()
open(os.path.join(code_path, src_code, "utils.py"), 'a').close()
os.makedirs(os.path.join(code_path, "Examples"))
open(os.path.join(code_path, "Examples", "example1.py"), 'a').close()
open(os.path.join(code_path, "Examples", "example2.py"), 'a').close()
with open(os.path.join(code_path, "README.md"), 'w') as readme:
readme.write("# Code\n\nInstructions for running code, dependencies, etc.")
# Create Docs folder and files
docs_path = os.path.join(tutorial_name, "Docs")
os.makedirs(docs_path)
open(os.path.join(docs_path, "Tutorial_Documentation.md"), 'a').close()
open(os.path.join(docs_path, "API_Documentation.md"), 'a').close()
# Create Assets folder and subfolders
assets_path = os.path.join(tutorial_name, "Assets")
os.makedirs(assets_path)
os.makedirs(os.path.join(assets_path, "diagrams"))
os.makedirs(os.path.join(assets_path, "screenshots"))
# Create README.md and LICENSE files
with open(os.path.join(tutorial_name, "README.md"), 'w') as readme:
readme.write(f"# {tutorial_name}\n\nOverview of the tutorial, setup instructions, etc.")
open(os.path.join(tutorial_name, "LICENSE"), 'a').close()
if __name__ == "__main__":
if len(sys.argv) != 2:
print("Usage: python generate_tutorial.py <tutorial_name>")
sys.exit(1)
tutorial_name = sys.argv[1]
generate_tutorial_structure(tutorial_name)
print(f"{tutorial_name} structure generated successfully!")