-
Notifications
You must be signed in to change notification settings - Fork 5
/
htmlgen.py
194 lines (172 loc) · 8.73 KB
/
htmlgen.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/python3
from moviepal import mp
import webbrowser
import os
class HtmlGen():
"""Generates necessary HTML when called upon"""
def __init__(self):
pass
# def ascii_clean(self):
# return self.encode('ascii', 'ignore').decoode('ascii')
def imgcheck(self, title):
if self == 'N/A':
return (f'<img src="img/popcorn.png" alt="{title}">')
return (f'<img src="{self}" alt="{title}">')
with open('ui/index.html', 'w', encoding='utf-8-sig') as file:
print('Creating HTML Header')
file.write(f'''
<html>
<head>
<title>🎥 Movie Pal</title>
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous">
</script>
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous">
</script>
<script
type="text/javascript"
src="../ui/js/SheetClip.js"></script>
<script
type="text/javascript"
src="../ui/js/copydata.js"
></script>
<link
href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css"
rel="stylesheet"
integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB"
crossorigin="anonymous">
<link
rel="stylesheet"
href="https://use.fontawesome.com/releases/v5.0.13/css/all.css"
integrity="sha384-DNOHZ68U8hZfKXOrtjWvjxusGo9WQnrNx2sqG0tfsghAvtVlRW3tvkXWZh58N9jp"
crossorigin="anonymous">
<link
href="https://fonts.googleapis.com/css?family=Source+Sans+Pro"
rel="stylesheet">
<link
rel="stylesheet"
href="styles/main.css">
</head>
<body>
<div class="movies--wrapper">
<div data-toggle="modal" data-target="#myModal" class="nav-mp">Search</div>
<div class="movies--container container">
''')
print('Gathering film titles...')
movies = mp.display(mp.query(key="Title"))
print('Creating film entities...')
for movie in movies:
try:
(title, ratings, boxoffice, genre,
_type, poster, runtime, plot, imdbid) = (
movie["Title"],
movie["Ratings"],
movie["BoxOffice"],
movie["Genre"],
movie["Type"],
movie["Poster"],
movie["Runtime"],
str(movie["Plot"]),
movie["imdbID"]
)
rotten, imdb, mtc = '', '', ''
try:
file.write(f'''<div class="movie--container">
<a target="_blank" href="https://imdb.com/title/{imdbid}">
<h3>{title}</h3>
</a>
<div class="movie--data">
<div class="movie--left">
<a target="_blank" href="https://imdb.com/title/{imdbid}">
{imgcheck(poster, title)}
</a>
</div>
<div class="movie--right">
<div class="boxoffice">
<span class="boxoffice--icon far fa-money-bill-alt"></span>
<span class="boxoffice--result">{boxoffice}</span>
</div>''')
except UnicodeEncodeError:
pass
for i in ratings:
if i['Source'] == 'Rotten Tomatoes':
value, rotten = i["Value"], i["Value"]
file.write(f'''<div class="review--rt">
<span class="review--rt-icon"><img src="img/tomato.png"></span>
<span class="review--rt-result">{value}</span>
</div>''')
elif i['Source'] == 'Metacritic':
value, mtc = i["Value"], i["Value"]
file.write(f'''<div class="review--metac">
<span class="review--metac-icon"><img src="img/mtc-icon.png"></span>
<span class="review--metac-result">{value}</span>
</div>''')
elif i['Source'] == 'Internet Movie Database':
value, imdb = i["Value"], i["Value"]
file.write(f'''<div class="review--imdb">
<span class="review--imdb-icon fab fa-imdb"></span>
<span class="review--imdb-result">{value}</span>
</div>''')
file.write(f''' </div>
</div>
<div class="plot--container">
<p>{plot}</p>
</div>
<div class="link--wrapper">
<a href="#">Copy Data</a>
<textarea
class="datarow"
data-plot='{plot.replace("'", " ")}'
data-rotten="{rotten}"
data-imdb="{imdb}"
data-mtc="{mtc}"
data-boxoffice="{boxoffice}"
data-genre="{genre}"
data-runtime="{runtime}"
data-title="{title}"
>
</textarea>
</div>
</div>''')
except KeyError:
pass
except UnicodeEncodeError:
pass
file.write('''</div></div>
<div class="copy-all">
<span>Copy All</span>
</div>
<div class="modal" id="myModal" tabindex="-1" role="dialog">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Get Film Info</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<input id="search">
<button type="button" onclick="inputGrabber()"><i class="fas fa-search"></i></button>
<input class="searchinput" type="checkbox"><span class="discover">Discover</span></radio>
<script src="../config.js"></script>
<script src="js/search.js" type="text/javascript"></script>
</input>
<div class="data">
<!-- data here -->
</div>
</div>
<div class="modal-footer">
<div class="footer-deco"></div>
</div>
</div>
</div>
</div>
</body></html>''')
print('Enjoy!')
webbrowser.open('file://' + os.path.abspath('ui/index.html'))