You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is it call @shirey . It nothing but a wrapper around
def daily() -> pd.DataFrame:
now = datetime.now()
report_output_directory = "daily-report"
report_output_filename = (
f'{report_output_directory}/{str(now.strftime("%Y%m%d"))}.tsv'
)
if Path(report_output_filename).exists():
df = pd.read_csv(report_output_filename, sep="\t")
return df
else:
url = "https://ingest.api.hubmapconsortium.org/datasets/data-status" # The URL to get the data from
try:
response = requests.get(url) # Send a request to the URL to get the data
response.raise_for_status() # Check if the request was successful (no errors)
json_data = response.json() # Convert the response to JSON format
# Ensure 'data' key exists in the JSON
if "data" in json_data: # Check if the JSON contains the key 'data'
df = pd.DataFrame(
json_data["data"]
) # Create a DataFrame using the data under 'data' key
else:
raise KeyError(
"'data' key not found in the JSON response"
) # Raise an error if 'data' key is missing
except (
ValueError,
KeyError,
) as e: # Catch errors related to value or missing keys
print(f"Error loading data: {e}") # Print the error message
return pd.DataFrame() # Return an empty DataFrame if there is an error
except (
requests.RequestException
) as e: # Catch errors related to the request itself
print(f"Request failed: {e}") # Print the error message
return pd.DataFrame() # Return an empty DataFrame if the request fails
if not Path(report_output_directory).exists():
Path(report_output_directory).mkdir()
try:
df.to_csv(report_output_filename, sep="\t", index=False)
except:
print(f"Unable to save dataframe to {report_output_filename}.")
hive_directory = "/hive/hubmap/bdbags/reports/"
report_output_backup_file = (
f'{hive_directory}/{str(now.strftime("%Y%m%d"))}.tsv'
)
symlink = "/hive/hubmap/bdbags/reports/today.tsv"
if Path(symlink).exists():
Path(symlink).unlink()
Path(symlink).symlink_to(report_output_backup_file)
return df
The text was updated successfully, but these errors were encountered:
This is it call @shirey . It nothing but a wrapper around
The text was updated successfully, but these errors were encountered: