-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetDate.py
30 lines (20 loc) · 829 Bytes
/
getDate.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
import urllib.request as scraper
import datetime
def scrapeDate(country , city) -> str:
global ss
url2 =F'https://www.timeanddate.com/worldclock/{country}/{city}'
headers = {"Accept-Language": "en-US,en;q=0.5"}
try:
req = scraper.Request(url2, headers=headers)
response = scraper.urlopen(req)
data = response.read()
scraped_data2 = str(data)
date_before = scraped_data2.find("<span id=ctdat>")
date_after = scraped_data2.find("</span></p><a hre")
actual_date = scraped_data2[date_before+15:date_after]
actual_date = actual_date.replace(',','')
final_date = datetime.datetime.strptime(actual_date, "%A %d %B %Y")
ss = str(final_date.date())
return(ss)
except Exception as e:
return(e)