Skip to content

Commit 63b86dd

Browse files
authored
Update deviantart_scratcher.py
1 parent 9575002 commit 63b86dd

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

deviantart/deviantart_scratcher.py

+16-10
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import os
1010
import sys
1111
import traceback
12-
import logging
1312

1413
# Third-party
1514
import pandas as pd
@@ -18,9 +17,6 @@
1817
from requests.adapters import HTTPAdapter
1918
from urllib3.util.retry import Retry
2019

21-
# Set up logging configuration
22-
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
23-
2420
# Set up current working directory (CWD) and root_path
2521
CWD = os.path.dirname(os.path.abspath(__file__))
2622
root_path = os.path.dirname(CWD)
@@ -41,6 +37,7 @@
4137
API_KEYS = os.getenv("GOOGLE_API_KEYS").split(",")
4238
PSE_KEY = os.getenv("PSE_KEY")
4339

40+
4441
def get_license_list():
4542
"""
4643
Provides the list of license from 2018's record of Creative Commons.
@@ -64,6 +61,7 @@ def get_license_list():
6461
)
6562
return license_list[4:]
6663

64+
6765
def get_request_url(license):
6866
"""
6967
Provides the API Endpoint URL for specified parameter combinations.
@@ -84,10 +82,11 @@ def get_request_url(license):
8482
)
8583
except Exception as e:
8684
if isinstance(e, IndexError):
87-
logging.error("Depleted all API Keys provided")
85+
print("Depleted all API Keys provided", file=sys.stderr)
8886
else:
8987
raise e
9088

89+
9190
def get_response_elems(license):
9291
"""
9392
Provides the metadata for query of specified parameters
@@ -123,17 +122,21 @@ def get_response_elems(license):
123122
# If quota limit exceeded, switch to the next API key
124123
global API_KEYS_IND
125124
API_KEYS_IND += 1
126-
logging.error("Changing API KEYS due to depletion of quota")
125+
print(
126+
"Changing API KEYS due to depletion of quota", file=sys.stderr
127+
)
127128
return get_response_elems(license)
128129
else:
129130
raise e
130131

132+
131133
def set_up_data_file():
132134
# Writes the header row to the file to contain DeviantArt data.
133135
header_title = "LICENSE TYPE,Document Count"
134136
with open(DATA_WRITE_FILE, "w") as f:
135137
f.write(f"{header_title}\n")
136138

139+
137140
def record_license_data(license_type):
138141
"""Writes the row for LICENSE_TYPE to the file to contain DeviantArt data.
139142
Args:
@@ -150,6 +153,7 @@ def record_license_data(license_type):
150153
with open(DATA_WRITE_FILE, "a") as f:
151154
f.write(f"{data_log}\n")
152155

156+
153157
def record_all_licenses():
154158
"""
155159
Records the data for all available license types listed in the license
@@ -161,19 +165,21 @@ def record_all_licenses():
161165
for license_type in license_list:
162166
record_license_data(license_type)
163167

168+
164169
def main():
165170
set_up_data_file()
166171
record_all_licenses()
167172

173+
168174
if __name__ == "__main__":
169175
try:
170176
main()
171177
except SystemExit as e:
172-
logging.error(f"System exit with code {e.code}")
173178
sys.exit(e.code)
174179
except KeyboardInterrupt:
175-
logging.info("INFO (130) Halted via KeyboardInterrupt.")
180+
print("INFO (130) Halted via KeyboardInterrupt.", file=sys.stderr)
176181
sys.exit(130)
177182
except Exception:
178-
logging.exception("ERROR (1) Unhandled exception:")
179-
sys.exit(1)
183+
print("ERROR (1) Unhandled exception:", file=sys.stderr)
184+
print(traceback.print_exc(), file=sys.stderr)
185+
sys.exit(1)

0 commit comments

Comments
 (0)