-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
47 lines (38 loc) · 1.27 KB
/
app.py
File metadata and controls
47 lines (38 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
from optomize.main import Optomize
import os
import urllib.request
import chardet
import validators
html_url=""
cwd=""
def process_url(html_url):
if(html_url.find('http') == -1 and html_url.find('www') != -1):
html_url = 'https://'+html_url
elif(html_url.find('http') == -1 and html_url.find('www') == -1):
html_url = 'https://www.' + html_url
return html_url
def create_html_file():
html_url = process_url(input("Please enter site URL: "))
if validators.url(html_url):
try:
html_file_bytes = urllib.request.urlopen(html_url)
except Exception as e:
print(e)
html_byte_array = html_file_bytes.read()
encoding_type = chardet.detect(html_byte_array)
html_str = html_byte_array.decode(encoding_type['encoding'])
html_write = open(os.getcwd()+"/optomize/files/html_file.html", "w")
html_write.write(html_str)
html_write.close()
html_file_bytes.close()
else:
print("Error: Incorrect url format")
def main():
create_html_file()
if __name__ == "__main__":
main()
cwd = os.getcwd()
html_path = cwd+"/optomize/files/html_file.html"
css_path = cwd+"/optomize/files/styling.css"
opt = Optomize(html_path, css_path)
opt.run()