-
Notifications
You must be signed in to change notification settings - Fork 0
/
UI.py
53 lines (40 loc) · 1.33 KB
/
UI.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'''
Created on Sep 20, 2015
@author: xinshen
'''
import tool_box
import stream_of_stories
import codecs
NewProcess = stream_of_stories.time_manager(stream_of_stories.stopFlag)
NewProcess.start()
def get_texts(time_manager):
return time_manager.texts
def build_content(passages):
template = open("template.html",'r')
template = template.read()
result = ''
if passages!=[]:
for i in range(10):
box =template.find('boxen')
result += template[:box]+passages[i]
template =template[box+5:]
else:
content = tool_box.present_story_list(tool_box.top_stories)
for i in range(10):
box = template.find('boxen')
result += template[:box]+content[i]
template = template[box+5:]
return result
#print(build_content(get_texts(NewProcess)))
def main():
browseLocal(build_content(get_texts(NewProcess)))
def strToFile(text, filename):
"""Write a file with the given name and the given text."""
with codecs.open(filename,'w',encoding='utf8') as output:
output.write(text)
output.close()
def browseLocal(webpageText, filename='tempBrowseLocal.html'):
import webbrowser, os.path
strToFile(webpageText, filename)
webbrowser.open("file:///" + os.path.abspath(filename)) #elaborated for Mac
main()