-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoke_info.py
More file actions
37 lines (33 loc) · 1.12 KB
/
Copy pathpoke_info.py
File metadata and controls
37 lines (33 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import logging
import traceback
from poke_api.extract import get_info
from poke_api.transform import summarize
def main():
logging.info('poke_info(poke_api) : start running')
poke_name_id = input('Enter a pokemon name or id: ').lower()
try:
pokemon = get_info('pokemon', poke_name_id)
print(summarize(pokemon))
except Exception as not_found:
print(
'Sorry, pokemon not found. Please check the spelling \
and try again.'
)
logging.critical(f'main(poke_api): unexpected error - {not_found}')
logging.info('poke_info(poke_api) : end running')
if __name__ == '__main__':
logging.root = logging.getLogger('user')
logging.basicConfig(
level=logging.INFO,
filename='logs.log',
format='%(name)s - %(asctime)s - %(levelname)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
filemode='a',
)
try:
main()
except Exception as e:
tb = ''.join(traceback.format_tb(e.__traceback__))
tb = tb.replace('\n', ' - ')
logging.critical(f'poke_info(poke_api): unexpected error - {e} {tb}')
raise e