Advertisement

08.07.2008 at 03:45PM PDT, ID: 23631275
[x]
Attachment Details

Opening and editing a html page with python.

Asked by kimhand in Python Scripting Language, CGI Scripting

I need a cgi script that reads an html file that i already wrote and replaces the word #ME# with my name, the word #DATE# with today's date, and the word #quote# with a random quote from a text file I have made with quotes. the quote will change each time it runs.
 1. My program needs to output this exact line first - note a
blank line
after the words that follow
Content-type: text/html
When my program runs it must do the following, and then print out
the results.
I have a file called quotes.txt. that has 31 quotes,
each on a line by itself.
I have this so far and I am stuck

Start Free Trial
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:
#!/usr/bin/python
u=open("top.html")
a = u.read()
z = a.split("\n")
z=z.replace("\z"," ")          
z=z.replace("#DATE#","t")
z=z.replace("#Me#","Jake")
z=z.replace("#QUOTE#","")
 
 
import time
t = time.localtime()
year = t[0]
month = t[1]
dayOfMonth = t[2]
hour = t[3]
minute = t[4]
second = t[5]
 
#THIS IS MY HTML CODE!!!#
<html>
<head>
<style>
body { font-family: Verdana, Arial, Helvetica, SansSerif }
p { font-size: 12px; text-align: justify }
</style>
</head>
<body>
<h3>Today's Date is #DATE#</h3>
<p>The quote for today is
#QUOTE#
</p>
<hr>
<span class=tiny>program is #ME#</span>
</body>
</html>
 
 
[+][-]08.07.2008 at 10:07PM PDT, ID: 22187576

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Python Scripting Language, CGI Scripting
Sign Up Now!
Solution Provided By: efn
Participating Experts: 2
Solution Grade: B
 
 
[+][-]08.07.2008 at 11:14PM PDT, ID: 22187754

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 - Hierarchy / EE_QW_2_20070628