@@ -76,6 +76,11 @@ def update_readme(image_path, description, section_title, args):
76
76
section_marker_end = "<!-- GCS End -->"
77
77
data_source_title = "## Data Source: Google Custom Search"
78
78
79
+ # Define section markers for each report type
80
+ specific_section_start = f"<!-- { section_title } Start -->"
81
+ specific_section_end = f"<!-- { section_title } End -->"
82
+ data_source_title = "## Data Source: Google Custom Search"
83
+
79
84
# Convert image path to a relative path
80
85
rel_image_path = os .path .relpath (image_path , os .path .dirname (readme_path ))
81
86
@@ -85,6 +90,7 @@ def update_readme(image_path, description, section_title, args):
85
90
else :
86
91
lines = []
87
92
93
+ # Main GCS Section
88
94
section_start = None
89
95
section_end = None
90
96
for i , line in enumerate (lines ):
@@ -93,24 +99,98 @@ def update_readme(image_path, description, section_title, args):
93
99
if section_marker_end in line :
94
100
section_end = i
95
101
102
+ # Check if the main section is present
96
103
if section_start is None or section_end is None :
97
- # If the section does not exist, add it at the end
98
- lines .append (f"\n # { args .quarter } Quantifying the Commons\n " )
99
- lines .append (f"{ section_marker_start } \n " )
100
- lines .append (f"{ data_source_title } \n \n " )
101
- lines .append (f"{ section_marker_end } \n " )
102
- section_start = len (lines ) - 3
104
+ # If the main section is not present, add it
105
+ lines .extend (
106
+ [
107
+ f"# { args .quarter } Quantifying the Commons\n " ,
108
+ f"{ section_marker_start } \n " ,
109
+ f"{ data_source_title } \n \n " ,
110
+ f"{ section_marker_end } \n " ,
111
+ ]
112
+ )
113
+ section_start = len (lines ) - 2
103
114
section_end = len (lines ) - 1
104
115
105
- # Prepare the content to be added
106
- new_content = [
107
- f"\n ### { section_title } \n " ,
108
- f"\n " ,
109
- f"{ description } \n " ,
110
- ]
111
-
112
- # Insert the new content before the section end marker
113
- lines = lines [:section_end ] + new_content + lines [section_end :]
116
+ # Locate the specific section markers within the main section
117
+ specific_start = None
118
+ specific_end = None
119
+ for i in range (section_start , section_end ):
120
+ if specific_section_start in lines [i ]:
121
+ specific_start = i
122
+ if specific_section_end in lines [i ]:
123
+ specific_end = i
124
+
125
+ # If the specific section is found, replace the content
126
+ if specific_start is not None and specific_end is not None :
127
+ # Prepare the new content for this specific section
128
+ new_content = [
129
+ f"{ specific_section_start } \n " ,
130
+ f"### { section_title } \n " ,
131
+ f"\n " ,
132
+ f"{ description } \n " ,
133
+ f"{ specific_section_end } \n " ,
134
+ ]
135
+ # Replace the content between the specific markers
136
+ lines = (
137
+ lines [:specific_start ] + new_content + lines [specific_end + 1 :]
138
+ )
139
+ else :
140
+ # If the specific section does not exist, add it before the main end marker
141
+ new_content = [
142
+ f"{ specific_section_start } \n " ,
143
+ f"### { section_title } \n " ,
144
+ f"\n " ,
145
+ f"{ description } \n " ,
146
+ f"{ specific_section_end } \n " ,
147
+ ]
148
+ lines = lines [:section_end ] + new_content + lines [section_end :]
149
+
150
+ # # If markers are found, replace the content between them
151
+ # if section_start is not None and section_end is not None:
152
+ # # Prepare the new content to replace the old one
153
+ # new_content = [
154
+ # f"{section_marker_start}\n",
155
+ # f"{data_source_title}\n\n",
156
+ # f"### {section_title}\n",
157
+ # f"\n",
158
+ # f"{description}\n",
159
+ # f"{section_marker_end}\n"
160
+ # ]
161
+
162
+ # # Replace the content between the start and end markers
163
+ # lines = lines[:section_start] + new_content + lines[section_end + 1:]
164
+ # else:
165
+ # # If the section does not exist, add it at the end
166
+ # new_content = [
167
+ # f"\n{section_marker_start}\n",
168
+ # f"{data_source_title}\n\n",
169
+ # f"### {section_title}\n",
170
+ # f"\n",
171
+ # f"{description}\n",
172
+ # f"{section_marker_end}\n"
173
+ # ]
174
+ # lines.extend(new_content)
175
+
176
+ # if section_start is None or section_end is None:
177
+ # # If the section does not exist, add it at the end
178
+ # lines.append(f"\n# {args.quarter} Quantifying the Commons\n")
179
+ # lines.append(f"{section_marker_start}\n")
180
+ # lines.append(f"{data_source_title}\n\n")
181
+ # lines.append(f"{section_marker_end}\n")
182
+ # section_start = len(lines) - 3
183
+ # section_end = len(lines) - 1
184
+
185
+ # # Prepare the content to be added
186
+ # new_content = [
187
+ # f"\n### {section_title}\n",
188
+ # f"\n",
189
+ # f"{description}\n",
190
+ # ]
191
+
192
+ # # Insert the new content before the section end marker
193
+ # lines = lines[:section_end] + new_content + lines[section_end:]
114
194
115
195
# Write back to the README.md file
116
196
with open (readme_path , "w" ) as f :
@@ -336,12 +416,12 @@ def visualize_by_language(data, args):
336
416
337
417
def main ():
338
418
339
- try :
340
- # Fetch and merge changes
341
- shared .fetch_and_merge (PATHS ["repo" ])
342
- except shared .GitOperationError as e :
343
- LOGGER .error (f"Fetch and merge failed: { e } " )
344
- sys .exit (e .exit_code )
419
+ # try:
420
+ # # Fetch and merge changes
421
+ # shared.fetch_and_merge(PATHS["repo"])
422
+ # except shared.GitOperationError as e:
423
+ # LOGGER.error(f"Fetch and merge failed: {e}")
424
+ # sys.exit(e.exit_code)
345
425
346
426
args = parse_arguments ()
347
427
@@ -356,19 +436,19 @@ def main():
356
436
visualize_by_license_type (data , args )
357
437
visualize_by_language (data , args )
358
438
359
- try :
360
- # Add and commit changes
361
- shared .add_and_commit (PATHS ["repo" ], "Added and committed new reports" )
362
- except shared .GitOperationError as e :
363
- LOGGER .error (f"Add and commit failed: { e } " )
364
- sys .exit (e .exit_code )
365
-
366
- try :
367
- # Push changes
368
- shared .push_changes (PATHS ["repo" ])
369
- except shared .GitOperationError as e :
370
- LOGGER .error (f"Push changes failed: { e } " )
371
- sys .exit (e .exit_code )
439
+ # try:
440
+ # # Add and commit changes
441
+ # shared.add_and_commit(PATHS["repo"], "Added and committed new reports")
442
+ # except shared.GitOperationError as e:
443
+ # LOGGER.error(f"Add and commit failed: {e}")
444
+ # sys.exit(e.exit_code)
445
+
446
+ # try:
447
+ # # Push changes
448
+ # shared.push_changes(PATHS["repo"])
449
+ # except shared.GitOperationError as e:
450
+ # LOGGER.error(f"Push changes failed: {e}")
451
+ # sys.exit(e.exit_code)
372
452
373
453
374
454
if __name__ == "__main__" :
0 commit comments