-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
34 lines (28 loc) · 938 Bytes
/
main.py
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
import logging
import logging.handlers
import os
import requests
logger = logging.getLogger(__name__)
logger.setLevel(logging.DEBUG)
logger_file_handler = logging.handlers.RotatingFileHandler(
"status.log",
maxBytes=1024 * 1024,
backupCount=1,
encoding="utf8",
)
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger_file_handler.setFormatter(formatter)
logger.addHandler(logger_file_handler)
try:
SOME_SECRET = os.environ["SOME_SECRET"]
except KeyError:
SOME_SECRET = "Token not available!"
#logger.info("Token not available!")
#raise
if __name__ == "__main__":
logger.info(f"Token value: {SOME_SECRET}")
r = requests.get('https://weather.talkpython.fm/api/weather?city=Chicago&country=US')
if r.status_code == 200:
data = r.json()
temperature = data["forecast"]["temp"]
logger.info(f'Temperature in Chicago: {temperature}')