Browse Source

Add initial version

Ian Adam Naval 5 years ago
parent
commit
cb985a2dbc

+ 38
- 0
server.py View File

@@ -0,0 +1,38 @@
1
+from datetime import datetime
2
+
3
+import requests
4
+from flask import Flask, render_template, Response
5
+
6
+
7
+app = Flask(__name__)
8
+
9
+
10
+EASTER_EGG_MESSAGE = "It's DAKA."
11
+DAKA_MENU_XML_URL = ("http://campusdining.compass-usa.com/wpi/Pages/"
12
+                     "SignageXML.aspx?location=Pulse+On+Dining+Marketplace")
13
+
14
+
15
+def its_april_fools():
16
+    now = datetime.now()
17
+    return now.month == 4 and now.day == 1
18
+
19
+
20
+@app.route('/')
21
+def index():
22
+    xsl_header = ('<?xml version="1.0"?>'
23
+                  '<?xml-stylesheet type="text/xsl" href="pod_menu.xsl"?>')
24
+    xml_file = requests.get(DAKA_MENU_XML_URL).text
25
+    return Response(xsl_header + xml_file, mimetype='text/xml')
26
+
27
+
28
+@app.route('/pod_menu.xsl')
29
+def pod_menu():
30
+    xsl = render_template("pod_menu.xsl",
31
+                          easter_egg_message=EASTER_EGG_MESSAGE,
32
+                          easter_egg=its_april_fools(),
33
+                          date=datetime.now().strftime("%A, %B %d, %Y"))
34
+    return Response(xsl, mimetype='text/xsl')
35
+
36
+
37
+if __name__ == '__main__':
38
+    app.run('0.0.0.0', port=5000, debug=True)

BIN
static/img/Dining-Services_Subranded_Print_black.png View File


BIN
static/img/WPIEATS_SocialMediaBanner_WhiteBG_Blacktext.png View File


+ 154
- 0
templates/pod_menu.xsl View File

@@ -0,0 +1,154 @@
1
+<?xml version="1.0"?>
2
+
3
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4
+
5
+	<xsl:template match="/Data/Venues/Venue[1]">
6
+		<html>
7
+			<head>
8
+				<meta charset="UTF-8"/>
9
+				<title>Document</title>
10
+				<style>
11
+					html, body {
12
+						display: flex;
13
+						flex-flow: column wrap;
14
+						margin: 0;
15
+						padding: 0;
16
+						font-size: 1.1em;
17
+						font-family: sans-serif;
18
+						min-height: 100%;
19
+						max-width: 960px;
20
+					}
21
+					@media screen {
22
+						body {
23
+							padding: 32px;
24
+						}
25
+					}
26
+					.vegetarian {
27
+						color: #ac2b37;
28
+					}
29
+					.vegan {
30
+						color: #ac2b37;
31
+						font-style: italic;
32
+					}
33
+					.header {
34
+						background-image: url('{{ url_for('static', filename='img/Dining-Services_Subranded_Print_black.png') }}');
35
+    					background-origin: content-box;
36
+    					background-position: top right;
37
+						background-repeat: no-repeat;
38
+						background-size: 30%;
39
+						border: 1px #000 solid;
40
+						margin-bottom: 16px;
41
+						padding: 8px 8px 8px 8px;
42
+						text-align: center;
43
+						-webkit-print-color-adjust: exact;
44
+					}
45
+					.header:before {
46
+						content: '';
47
+						position: absolute;
48
+						background-size: 100%;
49
+						background-image: url('{{ url_for('static', filename='img/WPIEATS_SocialMediaBanner_WhiteBG_Blacktext.png') }}');
50
+						margin-left: -150px;
51
+						width: 300px;
52
+						height: 48px;
53
+						-webkit-print-color-adjust: exact;
54
+					}
55
+					.header h1 {
56
+						margin-top: 48px;
57
+					}
58
+					.meal-periods {
59
+						flex: 1;
60
+						display: flex;
61
+						align-items: stretch;
62
+						align-content: stretch;
63
+					}
64
+					.meal-period {
65
+						flex: 1;
66
+						border: 1px #000 solid;
67
+						margin-right: 16px;
68
+						margin-bottom: 16px;
69
+						padding: 8px;
70
+						float: left;
71
+					}
72
+					.meal-period:last-child {
73
+						margin-right: 0;
74
+					}
75
+					.footer {
76
+						clear: both;
77
+						line-height: .5em;
78
+					}
79
+					h2 {
80
+						text-align: center;
81
+					}
82
+					h3 {
83
+						text-decoration: underline;
84
+					}
85
+					.menu-item::after {
86
+						content: ', ';
87
+					}
88
+					.menu-item:last-child::after {
89
+						content: '';
90
+					}
91
+					.easter-egg {
92
+						display: none;
93
+					}
94
+					h1::before {
95
+						content: 'POD';
96
+					}
97
+					@media print {
98
+						.easter-egg {
99
+							display: block;
100
+							font-size: 8px;
101
+							color: #f8f8f8;
102
+							position: absolute;
103
+							right: 0;
104
+							bottom: 0;
105
+							-webkit-print-color-adjust: exact;
106
+						}
107
+						{% if easter_egg %}
108
+						h1::before {
109
+							content: 'DAKA';
110
+						}
111
+						{% endif %}
112
+					}
113
+				</style>
114
+			</head>
115
+			<body>
116
+				<div class="header">
117
+					<h1> Menu</h1>
118
+					<h2>{{ date }}</h2>
119
+				</div>
120
+				<div class="meal-periods">
121
+					<xsl:for-each select="MealPeriods/MealPeriod[@name='Lunch' or @name='Dinner']">
122
+						<div class="meal-period">
123
+							<h2><xsl:value-of select="@name" /></h2>
124
+							<xsl:for-each select="MealStation">
125
+								<div class="meal-station">
126
+									<h3><xsl:value-of select="@name" /></h3>
127
+									<xsl:for-each select="MenuItem">
128
+										<xsl:choose>
129
+											<xsl:when test="Categories/Category[text()[contains(.,'Vegetarian')]]">
130
+												<span class="menu-item vegetarian"><xsl:value-of select="@name" />*</span>
131
+											</xsl:when>
132
+											<xsl:when test="Categories/Category[text()[contains(.,'Vegan')]]">
133
+												<span class="menu-item vegan"><xsl:value-of select="@name" />**</span>
134
+											</xsl:when>
135
+											<xsl:otherwise>
136
+												<span class="menu-item"><xsl:value-of select="@name" /></span>
137
+											</xsl:otherwise>
138
+										</xsl:choose>
139
+									</xsl:for-each>
140
+								</div>
141
+							</xsl:for-each>
142
+						</div>
143
+					</xsl:for-each>
144
+				</div>
145
+				<div class="footer">
146
+					<p class="vegetarian">* Vegetarian</p>
147
+					<p class="vegan">** Vegan</p>
148
+					<p class="easter-egg">{{ easter_egg_message }}</p>
149
+				</div>
150
+			</body>
151
+		</html>
152
+	</xsl:template>
153
+
154
+</xsl:stylesheet>

Loading…
Cancel
Save