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

64
main.py
View File

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