Skip to content

Commit

Permalink
Remove excess method in save_zenodo_metrics, update docstrings for ma…
Browse files Browse the repository at this point in the history
…ke_request() method
  • Loading branch information
e-belfer committed Oct 4, 2024
1 parent b32c65c commit 68f5db6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/usage_metrics/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ def get_table_name_from_context(context: OutputContext) -> str:
def make_request(
url: str, headers: str | None = None, params: str | None = None, timeout: int = 100
) -> requests.models.Response:
"""Makes a request to the github api.
"""Makes a request with some error handling.
Args:
query (str): A github api request url.
query (str): A request url.
headers (str): Header to include in the request.
params (str): Params of request.
timeout (int): Timeout of request (in seconds).
Expand Down
17 changes: 8 additions & 9 deletions src/usage_metrics/scripts/save_zenodo_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ def check_empty_string(cls, doi: str): # noqa: N805
return


def get_zenodo_logs() -> pd.DataFrame():
"""Download JSONs of metrics for all versions in the Catalyst Cooperative Zenodo community."""
def save_zenodo_logs() -> pd.DataFrame():
"""Get JSONs of Zenodo metrics for all Catalyst records and upload to GCS.
Get metrics for all versions in the Catalyst Cooperative Zenodo community locally,
and then upload to the sources.catalyst.coop GCS bucket.
"""
bucket_name = "pudl-usage-metrics-archives.catalyst.coop"
client = storage.Client()
bucket = client.get_bucket(bucket_name)
Expand All @@ -69,17 +73,12 @@ def get_zenodo_logs() -> pd.DataFrame():
def upload_to_bucket(
bucket: storage.Client.bucket, blob_name: str, data: pd.DataFrame
) -> None:
"""Upload a gcp object."""
"""Upload a GCP object to a selected bucket."""
blob = bucket.blob(blob_name)
blob.upload_from_string(data)

logger.info(f"Uploaded {blob_name} to GCS bucket.")


def save_metrics():
"""Save Zenodo traffic metrics to google cloud bucket."""
get_zenodo_logs()


if __name__ == "__main__":
sys.exit(save_metrics())
sys.exit(save_zenodo_logs())

0 comments on commit 68f5db6

Please sign in to comment.