Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 KB | None | 0 0
  1. import re
  2.  
  3.  
  4. def main():
  5. 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'
  6. out = ""
  7. cnt = 1
  8. pntcnt = 0
  9. pcnt = 0
  10. rcnt = 0;
  11.  
  12. hrefDictionary = {};
  13.  
  14. CurrHeader = "";
  15. CurrSubHeader = "";
  16.  
  17.  
  18.  
  19.  
  20.  
  21. with open("prawo.txt", "r") as content:
  22. for line in content:
  23.  
  24. if pntcnt > 0 and len(str.strip(line)) == 0 :
  25. out += '</ol>'
  26. pntcnt = 0
  27. continue
  28. if rcnt > 0 and len(str.strip(line)) == 0 :
  29. out += '</p>'
  30. rcnt = 0;
  31. continue
  32.  
  33. if re.match("^\d+\..*$", line) :
  34.  
  35. if pntcnt > 0:
  36. out += '</ol>'
  37. pntcnt = 0
  38.  
  39. CurrHeader = str.strip(str.rstrip(line), "1234567890. ");
  40. ID = str(cnt)
  41. hrefDictionary[CurrHeader] = {"ID":ID, "HasSubs":False};
  42. if cnt > 1 :
  43. out += '<hr style = "width: 100%; margin-left: 0;color: red; background-color: red; height: 5px; margin-top: 200pt;"></hr>\n\r'
  44. else :
  45. out += '<hr style = "width: 100%; margin-left: 0; visibility:hidden; height: 1px; margin-top: 500pt;"></hr>\n\r'
  46.  
  47. out += '<h1 style="color: red; font-size: 25pt; font-weight: bold; width: 100%;"' \
  48. 'id = "' +ID+ '">'\
  49. + CurrHeader + \
  50. '</h1>\r\n'
  51. cnt+=1;
  52. elif re.match("^\t+\-.*\s*$", line) :
  53. if pntcnt == 0:
  54. out += '<ol>'
  55.  
  56. pntcnt += 1
  57. out += '<li style="color: black; width: 100%; margin-left: 25pt;">' \
  58. +str.strip(line, "- \t") + \
  59. '</li>\r\n'
  60.  
  61. elif re.match("^\t?.*:\s*$", line) :
  62. pcnt+=1;
  63. ID = str(cnt)+str(pcnt)
  64. CurrSubHeader = str.strip(str.rstrip(line))
  65. hrefDictionary[CurrHeader]["HasSubs"] = True;
  66. hrefDictionary[CurrHeader][CurrSubHeader] = {"ID":ID, "Important":False}
  67. out += '<h3 style="color: green; font-weight: bold; width: 100%; margin-left: 10pt; margin-top: 100pt;" '\
  68. 'id = "' +ID+ '" > ' \
  69. + CurrSubHeader + \
  70. '</h3>\r\n'
  71.  
  72.  
  73. elif re.match("^[^\t][a-zA-Z_0-9]+.*$", line) :
  74. ID = str(cnt)+str(pcnt)
  75. CurrSubHeader = str.strip(str.rstrip(line))
  76. hrefDictionary[CurrHeader]["HasSubs"] = True;
  77. hrefDictionary[CurrHeader][CurrSubHeader] = {"ID":ID, "Important":True}
  78. out += '<h1 style="color: red; font-size: 25pt; font-weight: bold; width: 100%; margin-top:100pt;"' \
  79. 'id = "' +ID+ '">'\
  80. + CurrSubHeader + \
  81. '</h1>\r\n'
  82.  
  83. elif re.match("^.+$", line):
  84. rcnt+=1
  85. out += '<p style="color: black; width: 100%; margin-top:0; margin-left: 15pt;">' \
  86. + line;
  87.  
  88.  
  89.  
  90. 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; ">' \
  91. '<a href="#menu" style="display: block; font-size: 30px; color: red; margin-bottom 0;">'\
  92. '<div style=" width:100%; height:100%; text-align:center; display:inline-block; vertical-align: middle; line-height: 150px; ">Do spisu</div>'\
  93. '</a>'\
  94. '</div>'
  95.  
  96. outH += '<div style = "width:100%;"id = "menu">'
  97. for key in sorted(hrefDictionary):
  98.  
  99. outH += '<div style="margin-top: 20pt;">'
  100.  
  101. if hrefDictionary[key]["HasSubs"] :
  102. 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>'
  103. else:
  104. outH += '<i style=" display: inline-block; background-color: black; border-radius: 16pt; inline-block; padding: 15pt; "></i>'
  105.  
  106. outH +='<a style = " display: inline-box; font-weight:bold; width:90%; font-size: 45pt; margin-left: 20pt;" href="#'+hrefDictionary[key]["ID"]+'">'+key+'</a>'
  107.  
  108. if hrefDictionary[key]["HasSubs"] :
  109.  
  110. outH += '<div style="margin-top: 17pt; display: none; height: auto; width: 100%; " id="'+hrefDictionary[key]["ID"]+'unwrap'+'">'
  111. for subkey in hrefDictionary[key]:
  112. if subkey == "ID" or subkey == "HasSubs":
  113. continue
  114.  
  115. color = ""
  116. if hrefDictionary[key][subkey]["Important"] :
  117. color = "color: red; text-weight: bold;"
  118.  
  119. 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"]+'">&bull;'+str(subkey)+'</br"></a>';
  120. outH += '</div>'
  121.  
  122. outH += '</div>'
  123.  
  124. outH += '</div>'
  125.  
  126. out+="\r\n\r\n\t\t</body>"
  127. out+="\r\n</html>"
  128.  
  129. out = outH + out;
  130.  
  131.  
  132.  
  133. f = open('index.html', 'wb')
  134. f.write(out)
  135.  
  136. if __name__=="__main__":
  137. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement