Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- def main():
- outH = '<! DOCTYPE html>\n\r<html>\r\n\t<head>\r\n\t<meta charset="utf-8"/><link rel="stylesheet" href="/static/css/main.css?t={{ts}}"/><script type="text/javascript" src="/static/scripts/main.js?t={{ts}}"></script>\r\n\t</head>\r\n\t\t<body>\r\n\r\n'
- out = ""
- cnt = 1
- pntcnt = 0
- pcnt = 0
- rcnt = 0;
- hrefDictionary = {};
- CurrHeader = "";
- CurrSubHeader = "";
- with open("prawo.txt", "r") as content:
- for line in content:
- if pntcnt > 0 and len(str.strip(line)) == 0 :
- out += '</ol>'
- pntcnt = 0
- continue
- if rcnt > 0 and len(str.strip(line)) == 0 :
- out += '</p>'
- rcnt = 0;
- continue
- if re.match("^\d+\..*$", line) :
- if pntcnt > 0:
- out += '</ol>'
- pntcnt = 0
- CurrHeader = str.strip(str.rstrip(line), "1234567890. ");
- ID = str(cnt)
- hrefDictionary[CurrHeader] = {"ID":ID, "HasSubs":False};
- if cnt > 1 :
- out += '<hr style = "width: 100%; margin-left: 0;color: red; background-color: red; height: 5px; margin-top: 200pt;"></hr>\n\r'
- else :
- out += '<hr style = "width: 100%; margin-left: 0; visibility:hidden; height: 1px; margin-top: 500pt;"></hr>\n\r'
- out += '<h1 style="color: red; font-size: 25pt; font-weight: bold; width: 100%;"' \
- 'id = "' +ID+ '">'\
- + CurrHeader + \
- '</h1>\r\n'
- cnt+=1;
- elif re.match("^\t+\-.*\s*$", line) :
- if pntcnt == 0:
- out += '<ol>'
- pntcnt += 1
- out += '<li style="color: black; width: 100%; margin-left: 25pt;">' \
- +str.strip(line, "- \t") + \
- '</li>\r\n'
- elif re.match("^\t?.*:\s*$", line) :
- pcnt+=1;
- ID = str(cnt)+str(pcnt)
- CurrSubHeader = str.strip(str.rstrip(line))
- hrefDictionary[CurrHeader]["HasSubs"] = True;
- hrefDictionary[CurrHeader][CurrSubHeader] = {"ID":ID, "Important":False}
- out += '<h3 style="color: green; font-weight: bold; width: 100%; margin-left: 10pt; margin-top: 100pt;" '\
- 'id = "' +ID+ '" > ' \
- + CurrSubHeader + \
- '</h3>\r\n'
- elif re.match("^[^\t][a-zA-Z_0-9]+.*$", line) :
- ID = str(cnt)+str(pcnt)
- CurrSubHeader = str.strip(str.rstrip(line))
- hrefDictionary[CurrHeader]["HasSubs"] = True;
- hrefDictionary[CurrHeader][CurrSubHeader] = {"ID":ID, "Important":True}
- out += '<h1 style="color: red; font-size: 25pt; font-weight: bold; width: 100%; margin-top:100pt;"' \
- 'id = "' +ID+ '">'\
- + CurrSubHeader + \
- '</h1>\r\n'
- elif re.match("^.+$", line):
- rcnt+=1
- out += '<p style="color: black; width: 100%; margin-top:0; margin-left: 15pt;">' \
- + line;
- outH += '<div style = "z-index: 10; opacity: 0.8; position: fixed; bottom: 10px; left: 0; width: 250px; height: 150px; background-color: white; border: solid blue 2px; ">' \
- '<a href="#menu" style="display: block; font-size: 30px; color: red; margin-bottom 0;">'\
- '<div style=" width:100%; height:100%; text-align:center; display:inline-block; vertical-align: middle; line-height: 150px; ">Do spisu</div>'\
- '</a>'\
- '</div>'
- outH += '<div style = "width:100%;"id = "menu">'
- for key in sorted(hrefDictionary):
- outH += '<div style="margin-top: 20pt;">'
- if hrefDictionary[key]["HasSubs"] :
- outH += '<i onclick=\'var e = document.getElementById("'+hrefDictionary[key]["ID"]+'unwrap'+'"); if(e.style.display == "none")e.style.display="block"; else e.style.display="none";\' style=" border: solid black;border-width: 0 15pt 15pt 0;display: inline-block; padding: 15pt; transform: rotate(45deg);-webkit-transform: rotate(45deg);"></i>'
- else:
- outH += '<i style=" display: inline-block; background-color: black; border-radius: 16pt; inline-block; padding: 15pt; "></i>'
- outH +='<a style = " display: inline-box; font-weight:bold; width:90%; font-size: 45pt; margin-left: 20pt;" href="#'+hrefDictionary[key]["ID"]+'">'+key+'</a>'
- if hrefDictionary[key]["HasSubs"] :
- outH += '<div style="margin-top: 17pt; display: none; height: auto; width: 100%; " id="'+hrefDictionary[key]["ID"]+'unwrap'+'">'
- for subkey in hrefDictionary[key]:
- if subkey == "ID" or subkey == "HasSubs":
- continue
- color = ""
- if hrefDictionary[key][subkey]["Important"] :
- color = "color: red; text-weight: bold;"
- outH += '<a style = "'+color+' font-size: 22pt; margin-top: 10pt; display: block; width:100%-60pt; clear:both; margin-left: 70pt;" href="#'+hrefDictionary[key][subkey]["ID"]+'">•'+str(subkey)+'</br"></a>';
- outH += '</div>'
- outH += '</div>'
- outH += '</div>'
- out+="\r\n\r\n\t\t</body>"
- out+="\r\n</html>"
- out = outH + out;
- f = open('index.html', 'wb')
- f.write(out)
- if __name__=="__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement