Skip to content

Commit c4c64b7

Browse files
committed
github_scratcher logger added
1 parent cbec4c9 commit c4c64b7

File tree

1 file changed

+25
-8
lines changed

1 file changed

+25
-8
lines changed

github/github_scratcher.py

+25-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
#!/usr/bin/env python
2+
"""
3+
This file is dedicated to obtain a .csv record report for Github Data.
4+
"""
5+
16
# Standard library
27
import os
3-
import os.path
48
import sys
59
import traceback
610

@@ -13,16 +17,21 @@
1317
# First-party/Local
1418
import quantify # noqa: E402
1519

16-
PATH_REPO_ROOT, PATH_WORK_DIR, PATH_DOTENV, DATETIME_TODAY = quantify.setup(
20+
# Setup paths, Date and LOGGER using quantify.setup()
21+
PATH_REPO_ROOT, PATH_WORK_DIR, _, DATETIME_TODAY, LOGGER = quantify.setup(
1722
__file__
1823
)
1924

25+
# Set up file path for CSV report
2026
DATA_WRITE_FILE = os.path.join(
2127
PATH_WORK_DIR,
22-
f"data_github_"
28+
"data_github_"
2329
f"{DATETIME_TODAY.year}_{DATETIME_TODAY.month}_{DATETIME_TODAY.day}.csv",
2430
)
2531

32+
# Log the start of the script execution
33+
LOGGER.info("Script execution started.")
34+
2635

2736
def set_up_data_file():
2837
"""Writes the header row of the data file."""
@@ -43,6 +52,7 @@ def get_response_elems(license):
4352
dict: A dictionary mapping metadata to its value provided from the API
4453
query of specified parameters.
4554
"""
55+
LOGGER.info("Providing the metadata for query of specified License")
4656
try:
4757
base_url = "https://api.github.com/search/repositories?q=license:"
4858
request_url = f"{base_url}{license}"
@@ -57,8 +67,15 @@ def get_response_elems(license):
5767
response.raise_for_status()
5868
search_data = response.json()
5969
return {"totalResults": search_data["total_count"]}
60-
except Exception as e:
61-
raise e
70+
except requests.HTTPError as e:
71+
LOGGER.error(f"HTTP Error: {e}")
72+
raise
73+
except requests.RequestException as e:
74+
LOGGER.error(f"Request Exception: {e}")
75+
raise
76+
except KeyError as e:
77+
LOGGER.error(f"KeyError: {e}. Search data is: {search_data}")
78+
raise
6279

6380

6481
def record_license_data(license_type):
@@ -96,11 +113,11 @@ def main():
96113
try:
97114
main()
98115
except SystemExit as e:
116+
LOGGER.error(f"System exit with code: {e.code}")
99117
sys.exit(e.code)
100118
except KeyboardInterrupt:
101-
print("INFO (130) Halted via KeyboardInterrupt.", file=sys.stderr)
119+
LOGGER.info("(130) Halted via KeyboardInterrupt.")
102120
sys.exit(130)
103121
except Exception:
104-
print("ERROR (1) Unhandled exception:", file=sys.stderr)
105-
print(traceback.print_exc(), file=sys.stderr)
122+
LOGGER.exception(f"(1) Unhandled exception: {traceback.format_exc()}")
106123
sys.exit(1)

0 commit comments

Comments
 (0)