Skip to content

Commit deb086d

Browse files
committed
update reports to generate README.md
1 parent 056b230 commit deb086d

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

data/2024Q2/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
## Country Report
3+
![Number of Google Webpages Licensed by Country](/Users/naishasinha/quantifying/data/2024Q2/3-reports/gcs_country_report.png)
4+
Number of Google Webpages Licensed by Country
5+
6+
7+
## License Type Report
8+
![Number of Webpages Licensed by License Type](/Users/naishasinha/quantifying/data/2024Q2/3-reports/gcs_licensetype_report.png)
9+
Number of Webpages Licensed by License Type
10+
11+
12+
## Language Report
13+
![Number of Google Webpages Licensed by Language](/Users/naishasinha/quantifying/data/2024Q2/3-reports/gcs_language_report.png)
14+
Number of Google Webpages Licensed by Language

data/2024Q3/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
## Country Report
3+
![Number of Google Webpages Licensed by Country](/Users/naishasinha/quantifying/data/2024Q3/3-reports/gcs_country_report.png)
4+
Number of Google Webpages Licensed by Country
5+
6+
7+
## License Type Report
8+
![Number of Webpages Licensed by License Type](/Users/naishasinha/quantifying/data/2024Q3/3-reports/gcs_licensetype_report.png)
9+
Number of Webpages Licensed by License Type
10+
11+
12+
## Language Report
13+
![Number of Google Webpages Licensed by Language](/Users/naishasinha/quantifying/data/2024Q3/3-reports/gcs_language_report.png)
14+
Number of Google Webpages Licensed by Language

scripts/3-reports/gcs_reports.py

+63-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,41 @@ def load_data(args):
5858
return data
5959

6060

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"![{description}]({image_path})\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+
6196
# By country, by license type, by license language
6297

6398

@@ -120,10 +155,18 @@ def visualize_by_country(data, args):
120155

121156
# Create the directory if it does not exist
122157
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)
124160

125161
plt.show()
126162

163+
update_readme(
164+
image_path,
165+
"Number of Google Webpages Licensed by Country",
166+
"Country Report",
167+
args,
168+
)
169+
127170
LOGGER.info("Visualization by country created.")
128171

129172

@@ -170,10 +213,19 @@ def millions_formatter(x, pos):
170213

171214
# Create the directory if it does not exist
172215
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)
174219

175220
plt.show()
176221

222+
update_readme(
223+
image_path,
224+
"Number of Webpages Licensed by License Type",
225+
"License Type Report",
226+
args,
227+
)
228+
177229
LOGGER.info("Visualization by license type created.")
178230

179231

@@ -236,10 +288,18 @@ def visualize_by_language(data, args):
236288

237289
# Create the directory if it does not exist
238290
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)
240293

241294
plt.show()
242295

296+
update_readme(
297+
image_path,
298+
"Number of Google Webpages Licensed by Language",
299+
"Language Report",
300+
args,
301+
)
302+
243303
LOGGER.info("Visualization by language created.")
244304

245305

0 commit comments

Comments
 (0)