Chintan Donda commited on
Commit
bf2caaf
·
1 Parent(s): 3d0d57c

Convert temperature from Ferenheit to Celcius

Browse files
Files changed (1) hide show
  1. src/weather.py +21 -0
src/weather.py CHANGED
@@ -2,6 +2,15 @@ import requests
2
  from bs4 import BeautifulSoup as bs
3
  import src.constants as constants_utils
4
 
 
 
 
 
 
 
 
 
 
5
 
6
  class WEATHER:
7
  def __init__(self):
@@ -80,4 +89,16 @@ class WEATHER:
80
  time = ' '.join(time.split())
81
  info = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text.split('\n')[1].strip()
82
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  return time, info, temperature
 
2
  from bs4 import BeautifulSoup as bs
3
  import src.constants as constants_utils
4
 
5
+ import logging
6
+ logging.basicConfig(
7
+ format="%(asctime)s %(levelname)s [%(name)s] %(message)s",
8
+ level=logging.INFO,
9
+ datefmt="%Y-%m-%d %H:%M:%S"
10
+ )
11
+ logger = logging.getLogger(__name__)
12
+
13
+
14
 
15
  class WEATHER:
16
  def __init__(self):
 
89
  time = ' '.join(time.split())
90
  info = soup.find('div', attrs={'class': 'BNeawe tAd8D AP7Wnd'}).text.split('\n')[1].strip()
91
 
92
+ # Convert temperature from Ferenheit to Celcius
93
+ if '°F' in temperature:
94
+ temp = temperature.split('°')[0]
95
+ if temp:
96
+ try:
97
+ temp = int(temp)
98
+ celcius = int((temp - 32) * (5/9))
99
+ temperature = celcius
100
+ except Exception as e:
101
+ logger.error(f'Cannot convert temperature from Ferenheit to Celcius!')
102
+ pass
103
+
104
  return time, info, temperature