Skip to content

Commit a3dd718

Browse files
committed
required changes applied
1 parent 0b0c3b7 commit a3dd718

14 files changed

Lines changed: 172 additions & 335 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ directories to check:
133133
- [ppypa/pipenv][pipenv]: _Python Development Workflow for Humans._
134134
- [pre-commit][pre-commit]: _A framework for managing and maintaining
135135
multi-language pre-commit hooks._
136-
[Logging][logging]: _Utilize the built-in Python logging module to implement a flexible logging system from a shared module._
136+
- [Logging][logging]: _Utilize the built-in Python logging module to implement a flexible logging system from a shared module._
137137

138138
[ccospyguide]: https://opensource.creativecommons.org/contributing-code/python-guidelines/
139139
[black]: https://github.com/psf/black

__init__.py

Whitespace-only changes.

analyze/data_analysis.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import os
77
import re
88
import sys
9+
import traceback
910
import warnings
1011

1112
# Third-party
@@ -16,19 +17,16 @@
1617
import seaborn as sns
1718
from wordcloud import STOPWORDS, WordCloud # noqa: E402
1819

20+
sys.path.append(".")
1921
# First-party/Local
20-
import quantify
22+
import quantify # noqa: E402
2123

2224
# Warning suppression /!\ Caution /!\
2325
warnings.filterwarnings("ignore")
2426

2527
# Setup PATH_WORK_DIR, and LOGGER using quantify.setup()
26-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
2728
_, PATH_WORK_DIR, _, _, LOGGER = quantify.setup(__file__)
2829

29-
# Set the current working directory
30-
CWD = os.path.dirname(os.path.abspath(__file__))
31-
3230

3331
def tags_frequency(csv_path, column_names):
3432
"""
@@ -527,11 +525,11 @@ def main():
527525
try:
528526
main()
529527
except SystemExit as e:
530-
LOGGER.error("System exit with code: %d", e.code)
528+
LOGGER.error(f"System exit with code: {e.code}")
531529
sys.exit(e.code)
532530
except KeyboardInterrupt:
533-
LOGGER.info("Halted via KeyboardInterrupt.")
531+
LOGGER.info("(130) Halted via KeyboardInterrupt.")
534532
sys.exit(130)
535533
except Exception:
536-
LOGGER.exception("Unhandled exception:")
534+
LOGGER.exception(f"(1) Unhandled exception: {traceback.format_exc()}")
537535
sys.exit(1)

deviantart/deviantart_scratcher.py

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
data.
55
"""
66
# Standard library
7-
import logging
87
import os
98
import sys
9+
import traceback
1010

1111
# Third-party
1212
import pandas as pd
@@ -15,11 +15,11 @@
1515
from requests.adapters import HTTPAdapter
1616
from urllib3.util.retry import Retry
1717

18+
sys.path.append(".")
1819
# First-party/Local
19-
import quantify
20+
import quantify # noqa: E402
2021

2122
# Setup paths, Date and LOGGER using quantify.setup()
22-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
2323
PATH_REPO_ROOT, PATH_WORK_DIR, PATH_DOTENV, DATETIME_TODAY, LOGGER = (
2424
quantify.setup(__file__)
2525
)
@@ -36,30 +36,14 @@
3636
PSE_KEY = os.getenv("PSE_KEY")
3737

3838
# Set up file path for CSV report
39-
DATA_WRITE_FILE = (
40-
f"{PATH_WORK_DIR}"
39+
DATA_WRITE_FILE = os.path.join(
40+
PATH_WORK_DIR,
4141
f"/data_deviantart_"
42-
f"{DATETIME_TODAY.year}_{DATETIME_TODAY.month}_{DATETIME_TODAY.day}.csv"
42+
f"{DATETIME_TODAY.year}_{DATETIME_TODAY.month}_{DATETIME_TODAY.day}.csv",
4343
)
4444

45-
# Set up the logger
46-
LOG = logging.getLogger(__name__)
47-
LOG.setLevel(logging.INFO)
48-
49-
# Define both the handler and the formatter
50-
handler = logging.StreamHandler()
51-
formatter = logging.Formatter(
52-
"%(asctime)s - %(levelname)s - %(name)s - %(message)s"
53-
)
54-
55-
# Add formatter to the handler
56-
handler.setFormatter(formatter)
57-
58-
# Add handler to the logger
59-
LOG.addHandler(handler)
60-
6145
# Log the start of the script execution
62-
LOG.info("Script execution started.")
46+
LOGGER.info("Script execution started.")
6347

6448

6549
def get_license_list():
@@ -71,7 +55,7 @@ def get_license_list():
7155
An np array containing all license types that should be searched
7256
via Programmable Search Engine (PSE).
7357
"""
74-
LOG.info("Retrieving list of license from Creative Commons' record.")
58+
LOGGER.info("Retrieving list of license from Creative Commons' record.")
7559

7660
# Read license data from file
7761
cc_license_data = pd.read_csv(
@@ -98,7 +82,9 @@ def get_request_url(license):
9882
Returns:
9983
- str: The API Endpoint URL for the query specified by parameters.
10084
"""
101-
LOG.info(f"Generating API Endpoint URL for specified license: {license}")
85+
LOGGER.info(
86+
f"Generating API Endpoint URL for specified license: {license}"
87+
)
10288

10389
try:
10490
api_key = API_KEYS[API_KEYS_IND]
@@ -127,7 +113,7 @@ def get_response_elems(license):
127113
- dict: A dictionary mapping metadata to its value provided from the API
128114
query.
129115
"""
130-
LOG.info("Making a request to the API and handling potential retries.")
116+
LOGGER.info("Making a request to the API and handling potential retries.")
131117

132118
try:
133119
# Make a request to the API and handle potential retries
@@ -174,7 +160,7 @@ def record_license_data(license_type):
174160
default None value stands for having no assumption about license
175161
type.
176162
"""
177-
LOG.info(
163+
LOGGER.info(
178164
"Writing the row for license type %s to contain DeviantArt data",
179165
license_type,
180166
)
@@ -205,15 +191,14 @@ def main():
205191

206192

207193
if __name__ == "__main__":
208-
# Exception Handling
209194
try:
210195
main()
211196
except SystemExit as e:
212-
LOGGER.error("System exit with code: %d", e.code)
197+
LOGGER.error(f"System exit with code: {e.code}")
213198
sys.exit(e.code)
214199
except KeyboardInterrupt:
215-
LOGGER.info("Halted via KeyboardInterrupt.")
200+
LOGGER.info("(130) Halted via KeyboardInterrupt.")
216201
sys.exit(130)
217202
except Exception:
218-
LOGGER.exception("Unhandled exception:")
203+
LOGGER.exception(f"(1) Unhandled exception: {traceback.format_exc()}")
219204
sys.exit(1)

flickr/data_cleaning.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,17 @@
1313
"""
1414

1515
# Standard library
16-
import os
1716
import sys
17+
import traceback
1818

1919
# Third-party
2020
import pandas as pd
2121

22+
sys.path.append(".")
2223
# First-party/Local
23-
import quantify
24+
import quantify # noqa: E402
2425

2526
# Setup only LOGGER using quantify.setup()
26-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
2727
_, _, _, _, LOGGER = quantify.setup(__file__)
2828

2929

@@ -105,15 +105,14 @@ def main():
105105

106106

107107
if __name__ == "__main__":
108-
# Exception Handling
109108
try:
110109
main()
111110
except SystemExit as e:
112-
LOGGER.error("System exit with code: %d", e.code)
111+
LOGGER.error(f"System exit with code: {e.code}")
113112
sys.exit(e.code)
114113
except KeyboardInterrupt:
115-
LOGGER.info("Halted via KeyboardInterrupt.")
114+
LOGGER.info("(130) Halted via KeyboardInterrupt.")
116115
sys.exit(130)
117116
except Exception:
118-
LOGGER.exception("Unhandled exception:")
117+
LOGGER.exception(f"(1) Unhandled exception: {traceback.format_exc()}")
119118
sys.exit(1)

flickr/photos.py

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,42 +5,26 @@
55

66
# Standard library
77
import json
8-
import logging
98
import os
109
import sys
10+
import traceback
1111

1212
# Third-party
1313
import flickrapi
1414
from dotenv import load_dotenv
1515

16+
sys.path.append(".")
1617
# First-party/Local
17-
import quantify
18+
import quantify # noqa: E402
1819

1920
# Setup paths, and LOGGER using quantify.setup()
20-
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
2121
_, PATH_WORK_DIR, PATH_DOTENV, _, LOGGER = quantify.setup(__file__)
2222

2323
# Load environment variables
2424
load_dotenv(PATH_DOTENV)
2525

26-
# Set up the logger
27-
LOG = logging.getLogger(__name__)
28-
LOG.setLevel(logging.INFO)
29-
30-
# Define both the handler and the formatter
31-
handler = logging.StreamHandler()
32-
formatter = logging.Formatter(
33-
"%(asctime)s - %(levelname)s - %(name)s - %(message)s"
34-
)
35-
36-
# Add formatter to the handler
37-
handler.setFormatter(formatter)
38-
39-
# Add handler to the logger
40-
LOG.addHandler(handler)
41-
4226
# Log the start of the script execution
43-
LOG.info("Script execution started.")
27+
LOGGER.info("Script execution started.")
4428

4529

4630
def main():
@@ -64,15 +48,14 @@ def main():
6448

6549

6650
if __name__ == "__main__":
67-
# Exception Handling
6851
try:
6952
main()
7053
except SystemExit as e:
71-
LOGGER.error("System exit with code: %d", e.code)
54+
LOGGER.error(f"System exit with code: {e.code}")
7255
sys.exit(e.code)
7356
except KeyboardInterrupt:
74-
LOGGER.info("Halted via KeyboardInterrupt.")
57+
LOGGER.info("(130) Halted via KeyboardInterrupt.")
7558
sys.exit(130)
7659
except Exception:
77-
LOGGER.exception("Unhandled exception:")
60+
LOGGER.exception(f"(1) Unhandled exception: {traceback.format_exc()}")
7861
sys.exit(1)

0 commit comments

Comments
 (0)