@@ -58,6 +58,41 @@ def load_data(args):
58
58
return data
59
59
60
60
61
+ def update_readme (image_path , description , section_title , args ):
62
+ """
63
+ Update the README.md file with the generated images and descriptions.
64
+ """
65
+ readme_path = os .path .join (PATHS ["data" ], args .quarter , "README.md" )
66
+ section_marker = f"## { section_title } "
67
+
68
+ if os .path .exists (readme_path ):
69
+ with open (readme_path , "r" ) as f :
70
+ lines = f .readlines ()
71
+ else :
72
+ lines = []
73
+
74
+ section_start = None
75
+ for i , line in enumerate (lines ):
76
+ if section_marker in line :
77
+ section_start = i
78
+ break
79
+
80
+ if section_start is None :
81
+ # If section does not exist, add it at the end
82
+ lines .append (f"\n { section_marker } \n " )
83
+ section_start = len (lines ) - 1
84
+
85
+ # Add the image and description
86
+ lines .insert (section_start + 1 , f"\n " )
87
+ lines .insert (section_start + 2 , f"{ description } \n \n " )
88
+
89
+ # Write back to the README.md file
90
+ with open (readme_path , "w" ) as f :
91
+ f .writelines (lines )
92
+
93
+ LOGGER .info (f"Updated { readme_path } with new image and description." )
94
+
95
+
61
96
# By country, by license type, by license language
62
97
63
98
@@ -120,10 +155,18 @@ def visualize_by_country(data, args):
120
155
121
156
# Create the directory if it does not exist
122
157
os .makedirs (output_directory , exist_ok = True )
123
- plt .savefig (os .path .join (output_directory , "gcs_country_report.png" ))
158
+ image_path = os .path .join (output_directory , "gcs_country_report.png" )
159
+ plt .savefig (image_path )
124
160
125
161
plt .show ()
126
162
163
+ update_readme (
164
+ image_path ,
165
+ "Number of Google Webpages Licensed by Country" ,
166
+ "Country Report" ,
167
+ args ,
168
+ )
169
+
127
170
LOGGER .info ("Visualization by country created." )
128
171
129
172
@@ -170,10 +213,19 @@ def millions_formatter(x, pos):
170
213
171
214
# Create the directory if it does not exist
172
215
os .makedirs (output_directory , exist_ok = True )
173
- plt .savefig (os .path .join (output_directory , "gcs_licensetype_report.png" ))
216
+ image_path = os .path .join (output_directory , "gcs_licensetype_report.png" )
217
+
218
+ plt .savefig (image_path )
174
219
175
220
plt .show ()
176
221
222
+ update_readme (
223
+ image_path ,
224
+ "Number of Webpages Licensed by License Type" ,
225
+ "License Type Report" ,
226
+ args ,
227
+ )
228
+
177
229
LOGGER .info ("Visualization by license type created." )
178
230
179
231
@@ -236,10 +288,18 @@ def visualize_by_language(data, args):
236
288
237
289
# Create the directory if it does not exist
238
290
os .makedirs (output_directory , exist_ok = True )
239
- plt .savefig (os .path .join (output_directory , "gcs_language_report.png" ))
291
+ image_path = os .path .join (output_directory , "gcs_language_report.png" )
292
+ plt .savefig (image_path )
240
293
241
294
plt .show ()
242
295
296
+ update_readme (
297
+ image_path ,
298
+ "Number of Google Webpages Licensed by Language" ,
299
+ "Language Report" ,
300
+ args ,
301
+ )
302
+
243
303
LOGGER .info ("Visualization by language created." )
244
304
245
305
0 commit comments