-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmhr_time.py
More file actions
27 lines (22 loc) · 724 Bytes
/
mhr_time.py
File metadata and controls
27 lines (22 loc) · 724 Bytes
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
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from utility import get_english_names
class Time:
def __init__(self, city: str):
self.city, self.country = get_english_names(city)
self.base_url = "https://www.timeanddate.com/worldclock/?query="
self.url = ""
def send_request(self):
url = self.base_url + '+'.join([x for x in self.city.split()])
self.url = url
txt = requests.get(url).text
soup = BeautifulSoup(txt, "html.parser")
listing_select = soup.select("#p0")
page_select = soup.select("#ct")
if listing_select:
return listing_select[0].text.split()[1]
elif page_select:
return page_select[0].text[:-3]
else:
return datetime.now().strftime("%H:%M")