-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpage_generator.py
34 lines (31 loc) · 1.22 KB
/
webpage_generator.py
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
from html.parser import HTMLParser
import sys
IP:str = sys.argv[1] if len(sys.argv) == 2 else "127.0.0.1"
NEW_WEBSITE:str = ""
class MyHTMLParser(HTMLParser):
def handle_starttag(self, tag, attrs):
global NEW_WEBSITE, IP
out="<"+str(tag)
for att,value in attrs:
if (tag == "link" and 'rel' in attrs and att == 'href'):
value = 'http://'+IP+'/favicon.ico'
elif (tag == "div" and att == 'background'):
value = 'http://'+IP+'/background.png'
elif (tag == "video" and att == 'poster'):
value = 'http://'+IP+'/background.png'
elif (tag == "source" and att == 'src'):
value = 'http://'+IP+':8899/playlist.m3u8'
value = '\"'+str(value)+'\"'
out+=" "+str(att)+"="+str(value)
NEW_WEBSITE+=str(out)+">"
def handle_endtag(self, tag):
global NEW_WEBSITE
NEW_WEBSITE+="</"+str(tag)+">"
def handle_data(self, data):
global NEW_WEBSITE
NEW_WEBSITE+=str(data)
parser = MyHTMLParser()
with open('html/index.html',"r") as webpage:
data = webpage.read()
parser.feed(data)
with open('html/index.html',"w") as webpage: webpage.write(NEW_WEBSITE)