Commit
•
9188762
1
Parent(s):
27c16af
Update readme to not use Repository
Browse files- utilities/readme_update.py +13 -14
utilities/readme_update.py
CHANGED
@@ -27,25 +27,24 @@ def update_dataset_readme(dataset_name: str, subreddit: str, new_rows: int) -> N
|
|
27 |
# Initialize HfApi
|
28 |
api = HfApi()
|
29 |
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
#
|
34 |
-
|
35 |
-
|
36 |
-
# Read the README file
|
37 |
-
with open(f"{local_repo_path}/README.md", "r") as file:
|
38 |
old_readme = file.read()
|
39 |
|
40 |
-
# Modify
|
41 |
new_readme = append_to_readme(subreddit=subreddit, new_rows=new_rows, old_readme=old_readme)
|
42 |
|
43 |
-
#
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
|
|
|
|
49 |
|
50 |
|
51 |
def append_to_readme(subreddit: str, new_rows: int, old_readme: str) -> str:
|
|
|
27 |
# Initialize HfApi
|
28 |
api = HfApi()
|
29 |
|
30 |
+
# Download README file
|
31 |
+
readme_path = api.hf_hub_download(repo_id=dataset_name, repo_type="dataset", filename="README.md")
|
32 |
|
33 |
+
# Read it
|
34 |
+
with open(readme_path, "r") as file:
|
|
|
|
|
|
|
35 |
old_readme = file.read()
|
36 |
|
37 |
+
# Modify it
|
38 |
new_readme = append_to_readme(subreddit=subreddit, new_rows=new_rows, old_readme=old_readme)
|
39 |
|
40 |
+
# Commit modifications
|
41 |
+
api.upload_file(
|
42 |
+
path_or_fileobj=new_readme.encode(),
|
43 |
+
path_in_repo="README.md",
|
44 |
+
repo_id=dataset_name,
|
45 |
+
repo_type="dataset",
|
46 |
+
commit_message=f'Pushing {new_rows} new rows'
|
47 |
+
)
|
48 |
|
49 |
|
50 |
def append_to_readme(subreddit: str, new_rows: int, old_readme: str) -> str:
|