banner ghostbanner secret

Quotes Project Page Generation

This is the other half to complement the parsing of the quotes file itself in the previous article. After that text is fed through the series of regex expression to turn it into properly parsed parsed, the only thing to do is associate it with the correct person. This is nice in painless in Python. We define a function to check which name it is, and then return the key portion of the keypair using that name.

The key itself is simply a text color and a background image, and the page itself is served through Apache's cgi-bin. Every refresh returns a new quote.

 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
import storage
import random

reference = {
    'dylan': ('white', 'http://i.imgur.com/4SsKz36.jpg'),
    'colt': ('white', 'http://i.imgur.com/tcMEHMW.jpg'),
    'zipzap': ('purple', 'http://i.imgur.com/SN02gip.jpg'),
    'james': ('orange', 'http://i.imgur.com/lbCHXgU.jpg'),
    'travis': ('#00008B', 'http://i.imgur.com/JWwBlUx.jpg'),
    'none': ['black', '']
}

def check(quote):
    for i in reference:
        if i in quote[1].lower() or i in quote[0].lower():
            return reference[i]
        return reference['none']

phrase = random.choice(storage.quotes)
info = check(phrase)

body = """<html>
    <head>
        <link rel="stylesheet" type="text/css" href="quote.css">
        <link rel="shortcut icon" href="favicon.ico">
        <link href="http://fonts.googleapis.com/css?family=Poiret One"; rel="stylesheet"; type="text/css";/>
        <style>
            h1 {
                color:%s;
            }
            body {
                background-image:url(%s);
            }
        </style>
    </head>
    <body>
        <div class="refresh">
            <a href="/cgi-bin/quotes.py">New Quote~</a>
        </div>
        <div class="whole">
            <h1 class="quote">%s</h1>
            <h1 class="name">~%s %s</h1>
        </div>
    </body>
</html> """ % (info[0], info[1], phrase[0], phrase[1], phrase[2])

print("Content-type: text/html")
print
print body

At the end, all of the information that is needed is essentially embedded using Python's nifty string formatting. I believe this is depreciated after Python 2, however.

Leave a Comment