added custom option for animations

This commit is contained in:
Navan Chauhan 2020-11-10 20:24:00 +05:30
parent bfe4bab1f2
commit a000e94d4b
1 changed files with 33 additions and 31 deletions

62
main.py
View File

@ -11,6 +11,7 @@ from mdutils import MdUtils
markdown = True
pdf = False
html = True
animations = True
html_stylesheet = "styles/simple.css"
title_animation = "fade-down"
heading_animation = "fade-right"
@ -168,47 +169,48 @@ if html:
with open(ofname) as fp:
soup = BeautifulSoup(fp,'html5lib')
aos_css = soup.new_tag('link',href='https://unpkg.com/aos@2.3.1/dist/aos.css',rel='stylesheet')
soup.head.append(aos_css)
font = soup.new_tag('link',href=html_stylesheet,rel='stylesheet')
soup.head.append(font)
title = soup.new_tag('title')
title.string = "DailyDose"
soup.head.append(title)
aos_js = soup.new_tag('script',src="https://unpkg.com/aos@2.3.1/dist/aos.js")
soup.head.append(aos_js)
aos_script = soup.new_tag('script')
aos_script.string = "AOS.init();"
# <meta name="viewport" content="width=device-width, initial-scale=1.0">
viewport = soup.new_tag("meta",content="width=device-width, initial-scale=1.0")
viewport.attrs["name"] = "viewport"
soup.head.append(viewport)
soup.body.append(aos_script)
custom_css = soup.new_tag('link',href=html_stylesheet,rel='stylesheet')
soup.head.append(custom_css)
for feed in rss_feeds:
ToFindID = str("from-"+str(feed.strip().replace(":","").replace(" ","-").lower()))
ToEdit = soup.find("h1", {"id": ToFindID})
ToEdit['data-aos'] = 'fade-right'
soup.find("h1",{"id":"daily-dose"})['data-aos'] = title_animation
soup.find("h1",{"id":"contents"})['data-aos'] = heading_animation
soup.find("h1",{"id":"contents"})['data-aos-anchor-placement'] = "top-bottom"
if animations:
aos_css = soup.new_tag('link',href='https://unpkg.com/aos@2.3.1/dist/aos.css',rel='stylesheet')
soup.head.append(aos_css)
paragraphs = soup.find_all("p")
for paras in paragraphs:
paras['data-aos'] = list_animation
paras['data-aos-anchor-placement'] = "bottom-bottom"
aos_js = soup.new_tag('script',src="https://unpkg.com/aos@2.3.1/dist/aos.js")
soup.head.append(aos_js)
lis = soup.find_all("li")
for li in lis:
if li.a == None:
li['data-aos'] = list_animation
li['data-aos-anchor-placement'] = "bottom-bottom"
aos_script = soup.new_tag('script')
aos_script.string = "AOS.init();"
soup.body.append(aos_script)
for feed in rss_feeds:
ToFindID = str("from-"+str(feed.strip().replace(":","").replace(" ","-").lower()))
ToEdit = soup.find("h1", {"id": ToFindID})
ToEdit['data-aos'] = 'fade-right'
soup.find("h1",{"id":"daily-dose"})['data-aos'] = title_animation
soup.find("h1",{"id":"contents"})['data-aos'] = heading_animation
soup.find("h1",{"id":"contents"})['data-aos-anchor-placement'] = "top-bottom"
paragraphs = soup.find_all("p")
for paras in paragraphs:
paras['data-aos'] = list_animation
paras['data-aos-anchor-placement'] = "bottom-bottom"
lis = soup.find_all("li")
for li in lis:
if li.a == None:
li['data-aos'] = list_animation
li['data-aos-anchor-placement'] = "bottom-bottom"
with open(ofname, "w") as outf:
outf.write(str(soup))