-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Lines 56 to 67 in e9b3711
| now=datetime.datetime.now() | |
| date=now.strftime('%y%m%d') | |
| export_dir=os.path.realpath('PDN Scraper Exports') | |
| msg_error_1='[sciscraper]: HTTP Error Encountered, moving to next available object. Reason Given:' | |
| logging.basicConfig(filename=f'{date}_scraper.log', level=logging.DEBUG, | |
| format = '%(asctime)s - %(message)s', datefmt='%d-%b-%y %H:%M:%S') | |
| PRIME_SRC =os.path.realpath('211001_PDN_studies_9.csv') | |
| URL_DMNSNS ='https://app.dimensions.ai/discover/publication/results.json' | |
| RESEARCH_DIR=os.path.realpath(f'{date}_PDN Research Papers From Scrape') | |
| URL_SCIHUB='https://sci-hubtw.hkvisa.net/' |
In many places, there are assignment operators without spaces around the
=.
Always surround these binary operators with a single space on either side: assignment (=) [...]
https://pep8.org/#other-recommendations
Lines 84 to 94 in e9b3711
| def __new__(cls, s_bool: bool): | |
| ''' | |
| The ScrapeRequest class looks for the boolean value passed to it from the FileRequest class. | |
| A value of True, or 1, would return a SciHubScrape subclass. Whereas a value of False, of 0, would return a JSONScrape subclass. | |
| ''' | |
| if s_bool == False: | |
| slookup_code = 'json' | |
| elif s_bool == True: | |
| slookup_code = 'sci' | |
| else: | |
| raise Exception('[sciscraper]: Invalid prefix detected.') |
You've already specified that
s_bool is a bool, so on your if statement, you don't need to compare to True and False, you can simply do:
if s_bool:
slookup_code = 'sci'
else:
slookup_code = 'json'Notice that I've "inverted" the order in which the tests happen, as to avoid using if not s_bool: ... else: ... (that could be confusing).
And since you're already specifying that s_bool is supposed to be a bool, I believe it's not necessary to handle cases where it's not a bool, as that's not supposed to happen, and tools like mypy can already do this kind of check.
But if you believe it's necessary, then it could be done like so:
if not isinstance(s_bool, bool):
raise TypeError
if s_bool:
slookup_code = 'sci'
else:
slookup_code = 'json'Also notice that I'm raising a TypeError, instead of a generic Exception since that's pretty much what TypeError is for.
https://docs.quantifiedcode.com/python-anti-patterns/readability/comparison_to_true.html
https://docs.python.org/3/library/exceptions.html#TypeError