Last change
on this file since 888 was
859,
checked in by aslmd, 13 years ago
|
UTIL PYTHON MCDonline. Support for MCD5. Added eps figures. Various other informations added (diapo mode, text file with web arborescence).
|
-
Property svn:executable set to
*
|
File size:
1.6 KB
|
Rev | Line | |
---|
[859] | 1 | #!/usr/bin/python |
---|
| 2 | |
---|
| 3 | from os import listdir |
---|
| 4 | from random import choice |
---|
| 5 | |
---|
| 6 | ext2conttype = {"jpg": "image/jpeg", |
---|
| 7 | "jpeg": "image/jpeg", |
---|
| 8 | "png": "image/png", |
---|
| 9 | "gif": "image/gif"} |
---|
| 10 | |
---|
| 11 | def content_type(filename): |
---|
| 12 | return ext2conttype[filename[filename.rfind(".")+1:].lower()] |
---|
| 13 | |
---|
| 14 | def isimage(filename): |
---|
| 15 | """true if the filename's extension is in the content-type lookup""" |
---|
| 16 | filename = filename.lower() |
---|
| 17 | return filename[filename.rfind(".")+1:] in ext2conttype |
---|
| 18 | |
---|
| 19 | def random_file(dir): |
---|
| 20 | """returns the filename of a randomly chosen image in dir""" |
---|
| 21 | images = [f for f in listdir(dir) if isimage(f)] |
---|
| 22 | return choice(images) |
---|
| 23 | |
---|
| 24 | if __name__ == "__main__": |
---|
| 25 | dir = "../img/" |
---|
| 26 | r = random_file(dir) |
---|
| 27 | #print "Content-type: %s\n" % (content_type(r)) |
---|
| 28 | |
---|
| 29 | print "Content-type:text/html\n" |
---|
| 30 | print " " #Apache needs a space after content-type |
---|
| 31 | header="""<html><head><title>Mars Climate Database: The Web Interface</title></head><body>""" |
---|
| 32 | print header |
---|
| 33 | |
---|
| 34 | print "<form name='diapo' action='./diapo.py' method='post'>" |
---|
| 35 | print "<center>" |
---|
| 36 | print "<b style='font-size: 125%;'>Mars Climate Database: The Web Interface.</b><br />" |
---|
| 37 | print "<b style='font-size: 125%;'>Demo mode!</b>" |
---|
| 38 | print "<input type='submit' value='Click here for another random example' style='font-weight:bold'/><br />" |
---|
| 39 | print "<a href='../index.html'>back to the main interface.</a><br />" |
---|
| 40 | print "</center>" |
---|
| 41 | print "<hr />" |
---|
| 42 | |
---|
| 43 | #dafile = file(dir+r, "rb").read() |
---|
| 44 | dafile = dir+r |
---|
| 45 | print "<img src='"+dafile+"'><br />" |
---|
| 46 | |
---|
| 47 | bottom = "</body></html>" |
---|
| 48 | print bottom |
---|
Note: See
TracBrowser
for help on using the repository browser.