diff options
author | neodarz <neodarz@neodarz.net> | 2017-05-19 17:38:40 +0200 |
---|---|---|
committer | neodarz <neodarz@neodarz.net> | 2017-05-19 17:38:40 +0200 |
commit | fb6baf22d226feb94e7a106ddfc4838eedb79901 (patch) | |
tree | c9b23d9229339a365a2bce221bc67564c948859f /pyblog | |
parent | 7d35d4f394f3a774b8b99e5a24a3c4cf9f6efa7b (diff) | |
download | my_new_personal_website-fb6baf22d226feb94e7a106ddfc4838eedb79901.tar.xz my_new_personal_website-fb6baf22d226feb94e7a106ddfc4838eedb79901.zip |
Add test for internet before generating the tag cloud
Diffstat (limited to 'pyblog')
-rwxr-xr-x | pyblog | 65 |
1 files changed, 34 insertions, 31 deletions
@@ -550,26 +550,27 @@ def generate_tagcloud(): documents_fileList = [] documents_fileList.append("/website/Documents/veille_techno.html") - r = requests.get("https://shaarli.neodarz.net/?do=tagcloud") - data = r.text - soup = bs4.BeautifulSoup(data, 'lxml') - fd, tmppath = tempfile.mkstemp() os.close(fd) - htmly_website_page = "" + try: + r = requests.get("https://shaarli.neodarz.net/?do=tagcloud") + data = r.text + soup = bs4.BeautifulSoup(data, 'lxml') - if os.path.exists(BUILDDIR+"/website/Documents/veille_techno.html"): - sys.stderr.write("generating tagcloud\n") + htmly_website_page = "" - # Put in a list the pages where the menu will be written - #for root, dirs, files in os.walk(BUILDDIR+"/website/Documents/Situation2"): - # for name in files: - # if name.endswith(".html"): - # try: - # documents_fileList.append(os.path.join(root.split('build')[1], name)) - # except IndexError: - # documents_fileList.append(name) + if os.path.exists(BUILDDIR+"/website/Documents/veille_techno.html"): + sys.stderr.write("generating tagcloud\n") + + # Put in a list the pages where the menu will be written + #for root, dirs, files in os.walk(BUILDDIR+"/website/Documents/Situation2"): + # for name in files: + # if name.endswith(".html"): + # try: + # documents_fileList.append(os.path.join(root.split('build')[1], name)) + # except IndexError: + # documents_fileList.append(name) # Generate the string who contain the links of the menu #htmly_website_page = "<ul>" @@ -577,22 +578,24 @@ def generate_tagcloud(): # htmly_website_page += "<a href='/website/Documents/Situation2/"+name+"' class='situation2lia'><li><span class='situation2left-lia'></span><span class='situation2center-lia'>"+name.split('.html')[0]+"</span><span class='situation2right-lia'></span></li></a>" #htmly_website_page += "</ul>" - #Writing the menu in all pages contained in the variable in place of the -- generate submenu here -- - for document_file in documents_fileList: - with open(tmppath, 'w', encoding='utf-8') as tmpfile: - if os.path.exists("build"+document_file): - with open("build"+document_file, 'r', encoding='utf-8') as indexmd: - lines = indexmd.readlines() - with open("build"+document_file, 'w', encoding='utf-8') as indexmd: - for line in lines: - indexmd.write(re.sub(r'-- generate tagcloud --', str(soup.find('div', {'id': 'cloudtag'})), line)) - #https://shaarli.neodarz.net/ - with open("build"+document_file, 'r', encoding='utf-8') as indexmd: - lines = indexmd.readlines() - with open("build"+document_file, 'w', encoding='utf-8') as indexmd: - for line in lines: - indexmd.write(re.sub(r'\?searchtags=', 'https://shaarli.neodarz.net/?searchtags=', line)) - + #Writing the menu in all pages contained in the variable in place of the -- generate submenu here -- + for document_file in documents_fileList: + with open(tmppath, 'w', encoding='utf-8') as tmpfile: + if os.path.exists("build"+document_file): + with open("build"+document_file, 'r', encoding='utf-8') as indexmd: + lines = indexmd.readlines() + with open("build"+document_file, 'w', encoding='utf-8') as indexmd: + for line in lines: + indexmd.write(re.sub(r'-- generate tagcloud --', str(soup.find('div', {'id': 'cloudtag'})), line)) + #https://shaarli.neodarz.net/ + with open("build"+document_file, 'r', encoding='utf-8') as indexmd: + lines = indexmd.readlines() + with open("build"+document_file, 'w', encoding='utf-8') as indexmd: + for line in lines: + indexmd.write(re.sub(r'\?searchtags=', 'https://shaarli.neodarz.net/?searchtags=', line)) + + except Exception: + print("generating tagcloud... /!\ No internet connection ! => tagcloud not generated !") os.remove(tmppath) |