danielrosehill commited on
Commit
c90dbdd
Β·
1 Parent(s): 02488fa
Files changed (2) hide show
  1. .github/scripts/update_stats.py +44 -13
  2. README.md +5 -5
.github/scripts/update_stats.py CHANGED
@@ -85,20 +85,51 @@ def update_readme():
85
  content = file.read()
86
 
87
  # Check if we need to add a download statistics section with the image
88
- if "## Download Statistics" not in content and "![Download Statistics]" not in content:
89
- # Find a good place to insert the download statistics section
90
- maintenance_section = "## πŸ”§ Development and Maintenance"
91
- if maintenance_section in content:
92
- # Insert before the maintenance section
93
- parts = content.split(maintenance_section)
94
- content = parts[0] + "\n## Cumulative Download Statistics\n\n![Cumulative Download Statistics](download_statistics.png)\n\n" + maintenance_section + parts[1]
 
 
 
 
 
95
  else:
96
- # Insert at the end of the file
97
- content += "\n\n## Cumulative Download Statistics\n\n![Cumulative Download Statistics](download_statistics.png)\n"
98
- # Update existing section if it exists
99
- elif "## Download Statistics" in content:
100
- content = content.replace("## Download Statistics", "## Cumulative Download Statistics")
101
- content = content.replace("![Download Statistics]", "![Cumulative Download Statistics]")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
102
 
103
  with open(README_PATH, 'w') as file:
104
  file.write(content)
 
85
  content = file.read()
86
 
87
  # Check if we need to add a download statistics section with the image
88
+ if "## Cumulative Download Statistics" not in content and "![Cumulative Download Statistics]" not in content:
89
+ # Find a good place to insert the download statistics section - after the badges and before navigation index
90
+ badge_line = "![Dataset Downloads Hugging Face](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Cumulative%20Dataset%20Downloads&query=$.downloadsAllTime&url=https://huggingface.co/api/datasets/danielrosehill/ifvi_valuefactors_deriv)"
91
+ navigation_index = "## πŸ“‘ Navigation Index"
92
+
93
+ if badge_line in content and navigation_index in content:
94
+ # Insert after the badges and before navigation index
95
+ parts = content.split(badge_line)
96
+ badge_part = parts[0] + badge_line
97
+ rest_parts = parts[1].split(navigation_index)
98
+
99
+ content = badge_part + "\n\n## Cumulative Download Statistics\n\n![Cumulative Download Statistics](download_statistics.png)\n\n" + navigation_index + rest_parts[1]
100
  else:
101
+ # Fallback: Insert at the beginning of the file
102
+ content = content.split("---\n", 2)
103
+ if len(content) >= 3:
104
+ content = "---\n" + content[1] + "---\n" + "## Cumulative Download Statistics\n\n![Cumulative Download Statistics](download_statistics.png)\n\n" + content[2]
105
+ else:
106
+ content = "## Cumulative Download Statistics\n\n![Cumulative Download Statistics](download_statistics.png)\n\n" + content[0]
107
+
108
+ # Update existing section if it exists but is in the wrong place
109
+ elif "## Cumulative Download Statistics" in content:
110
+ # First remove the existing section
111
+ section_start = content.find("## Cumulative Download Statistics")
112
+ section_end = content.find("\n\n", section_start + 30) # Look for the end of the section
113
+ if section_end == -1: # If not found, try to find the next heading
114
+ section_end = content.find("\n##", section_start + 30)
115
+ if section_end == -1: # If still not found, just use the rest of the content
116
+ section_end = len(content)
117
+ else:
118
+ section_end += 2 # Include the newlines
119
+
120
+ section_content = content[section_start:section_end]
121
+ content = content.replace(section_content, "")
122
+
123
+ # Then add it in the right place
124
+ badge_line = "![Dataset Downloads Hugging Face](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Cumulative%20Dataset%20Downloads&query=$.downloadsAllTime&url=https://huggingface.co/api/datasets/danielrosehill/ifvi_valuefactors_deriv)"
125
+ navigation_index = "## πŸ“‘ Navigation Index"
126
+
127
+ if badge_line in content and navigation_index in content:
128
+ parts = content.split(badge_line)
129
+ badge_part = parts[0] + badge_line
130
+ rest_parts = parts[1].split(navigation_index)
131
+
132
+ content = badge_part + "\n\n## Cumulative Download Statistics\n\n![Cumulative Download Statistics](download_statistics.png)\n\n" + navigation_index + rest_parts[1]
133
 
134
  with open(README_PATH, 'w') as file:
135
  file.write(content)
README.md CHANGED
@@ -11,7 +11,11 @@ pretty_name: IFVI Value Factors - Derivative Dataset For Analysis
11
  [![Hugging Face Dataset](https://img.shields.io/badge/Hugging%20Face-Dataset-orange?logo=huggingface)](https://huggingface.co/datasets/danielrosehill/ifvi_valuefactors_deriv)
12
  [![Original Data](https://img.shields.io/badge/Original-Data-green)](https://ifvi.org/methodology/environmental-topic-methodology/interim-methodologies/#GlobalValueFactorDatabase)
13
 
14
- ![Dataset Downloads Hugging Face](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Dataset%20Downloads%20Hugging%20Face&query=$.downloads&url=https://huggingface.co/api/datasets/danielrosehill/ifvi_valuefactors_deriv)
 
 
 
 
15
 
16
  ## πŸ“‘ Navigation Index
17
 
@@ -136,10 +140,6 @@ This repository includes scripts for maintaining download statistics and other m
136
 
137
  The repository is configured with GitHub Actions to automatically update download statistics daily.
138
 
139
- ## Cumulative Download Statistics
140
-
141
- ![Cumulative Download Statistics](download_statistics.png)
142
-
143
  <a id="release-notes-for-v2"></a>
144
 
145
  ---
 
11
  [![Hugging Face Dataset](https://img.shields.io/badge/Hugging%20Face-Dataset-orange?logo=huggingface)](https://huggingface.co/datasets/danielrosehill/ifvi_valuefactors_deriv)
12
  [![Original Data](https://img.shields.io/badge/Original-Data-green)](https://ifvi.org/methodology/environmental-topic-methodology/interim-methodologies/#GlobalValueFactorDatabase)
13
 
14
+ ![Dataset Downloads Hugging Face](https://img.shields.io/badge/dynamic/json?color=brightgreen&label=Cumulative%20Dataset%20Downloads&query=$.downloadsAllTime&url=https://huggingface.co/api/datasets/danielrosehill/ifvi_valuefactors_deriv)
15
+
16
+ ## Cumulative Download Statistics
17
+
18
+ ![Cumulative Download Statistics](download_statistics.png)
19
 
20
  ## πŸ“‘ Navigation Index
21
 
 
140
 
141
  The repository is configured with GitHub Actions to automatically update download statistics daily.
142
 
 
 
 
 
143
  <a id="release-notes-for-v2"></a>
144
 
145
  ---