bupa1018 commited on
Commit
050be50
·
1 Parent(s): 776b230

Create repo_versions.py

Browse files
Files changed (1) hide show
  1. repo_versions.py +36 -0
repo_versions.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import huggingface_hub
3
+ from huggingface_hub import Repository
4
+ from datetime import datetime
5
+
6
+ # Define the path to your JSON file
7
+
8
+ DATASET_REPO_URL = "https://huggingface.co/datasets/bupa1018/Test"
9
+ DATA_FILENAME = "repo_data.json"
10
+ DATA_FILE = os.path.join("data", DATA_FILENAME)
11
+
12
+ # Function to retrieve the last download entry from the JSON file
13
+ def store_message_from_json():
14
+ try:
15
+ # Open and load the JSON file
16
+ with open(DATA_FILE, "r") as jsonfile:
17
+ data = json.load(jsonfile)
18
+
19
+ # Check if the "downloads" list exists and is not empty
20
+ if "downloads" in data and len(data["downloads"]) > 0:
21
+ # Retrieve the last item in the "downloads" list
22
+ last_download = data["downloads"][-1]
23
+ version = last_download["version"]
24
+ commit_hash = last_download["commit_hash"]
25
+ download_date = last_download["download_date"]
26
+
27
+ # Print or return the extracted data
28
+ return f"Version: {version}, Commit Hash: {commit_hash}, Download Date: {download_date}"
29
+ else:
30
+ return "No downloads found in the JSON file."
31
+ except FileNotFoundError:
32
+ return "The JSON file does not exist."
33
+ except json.JSONDecodeError:
34
+ return "Error decoding the JSON file."
35
+ except Exception as e:
36
+ return f"An error occurred: {e}"