From a000e94d4b7675295c98e0c7133f7ba9fffaab12 Mon Sep 17 00:00:00 2001 From: Navan Chauhan Date: Tue, 10 Nov 2020 20:24:00 +0530 Subject: [PATCH] added custom option for animations --- main.py | 64 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/main.py b/main.py index 7c79f9f..3e7c388 100644 --- a/main.py +++ b/main.py @@ -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" @@ -167,48 +168,49 @@ 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();" - # 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))