forked from bdipesh3045/Nepali_Event_Viewer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdate.py
More file actions
78 lines (78 loc) · 2.42 KB
/
Copy pathdate.py
File metadata and controls
78 lines (78 loc) · 2.42 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# from bs4 import BeautifulSoup
# from requests import request
# import requests
# from curses.ascii import BS
# from pyBSDate import convert_AD_to_BS
# print('''Note to write correct date!''')
# # Taking date in international form converting the date
# date=input("Enter the date in international system like(2022-10-3) \n")
# date_list=date.split('-')
# bs_date = convert_AD_to_BS(int(date_list[0]), int(date_list[1]),int(date_list[2]))
# Bs_li=[]
# for x in bs_date:
# Bs_li.append(x)
# year_nepali=int(Bs_li[0])
# month_nepali=int(Bs_li[1])
# url=f"https://www.hamropatro.com/calendar/{year_nepali}/{month_nepali}"
# li=[]
# data=requests.get(url)
# soup=BeautifulSoup(data.text,'html.parser')
# soup= soup.find('li' , {"id":date})
# h1=soup.find('span' , {"class":'event'})
# h1=h1.get_text(strip = True)
# li.append(h1)
# for i in range(1,4):
# a=f"col{i}"
# if(i==1):
# div= soup.find('div' , {"class":a})
# sp1=div.find('span')
# li.append(sp1.get_text(strip = True))
# elif(a=="col2"):
# div= soup.find('div' , {"class":a})
# li.append(div.get_text(strip = True))
# else:
# div= soup.find('div' , {"class":"panchangaWrapper"})
# li.append(div.get_text(strip = True))
# with open('festival.txt', 'w') as f:
# for line in li:
# f.write(line)
# f.write('\n')
from datetime import datetime
import requests
from bs4 import BeautifulSoup
from requests import request
import requests
from curses.ascii import BS
from pyBSDate import convert_AD_to_BS
now = datetime.now()
date = now.strftime("%Y-%m-%e")
date=date.replace(" ", "")
date_list=date.split('-')
bs_date = convert_AD_to_BS(int(date_list[0]), int(date_list[1]),int(date_list[2]))
Bs_li=[]
for x in bs_date:
Bs_li.append(x)
year_nepali=int(Bs_li[0])
month_nepali=int(Bs_li[1])
url=f"https://www.hamropatro.com/calendar/{year_nepali}/{month_nepali}"
print(url)
li=[]
data=requests.get(url)
soup=BeautifulSoup(data.text,'html.parser')
soup= soup.find('li',{"id":date})
h1=soup.find('span' , {"class":'event'})
h1=h1.get_text(strip = True)
li.append(h1)
for i in range(1,4):
a=f"col{i}"
if(i==1):
div= soup.find('div' , {"class":a})
sp1=div.find('span')
li.append(sp1.get_text(strip = True))
elif(a=="col2"):
div= soup.find('div' , {"class":a})
li.append(div.get_text(strip = True))
else:
div= soup.find('div' , {"class":"panchangaWrapper"})
li.append(div.get_text(strip = True))
print(li)