Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > calendar from python to html

Reply
Thread Tools

calendar from python to html

 
 
Luca Sanna
Guest
Posts: n/a
 
      10-05-2012
hi,

I enter a calendar in an html page
in each calendar day, I enter a time that is used by the program to perform actions with python

What can I use to do this?

thanks
 
Reply With Quote
 
 
 
 
Jason Benjamin
Guest
Posts: n/a
 
      10-06-2012
Well, you need a web server, a webpage, a database (could just be a
file), a cgi script, and the datetime module. Optionally, you can use a
web framework like CherryPy or Django, which covers a lot of these by
itself.

I only know Python 2, but here are some examples:

A basic web server:

webdir = '.'
port = 80

import os, sys
from BaseHTTPServer import HTTPServer
from CGIHTTPServer import CGIHTTPRequestHandler

if len(sys.argv) > 1: webdir = sys.argv[1]
if len(sys.argv) > 2: port = int(sys.argv[2])
print 'webdir "%s", port %s' % (webdir, port)

#Windows only hack
if sys.platform[:3] == 'win':
CGIHTTPRequestHandler.have_popen2 = False
CGIHTTPRequestHandler.have_popen3 = False
sys.path.append('cgi-bin')

os.chdir(webdir)
srvraddr = ("", port)
srvrobj = HTTPServer(srvraddr, CGIHTTPRequestHandler)
srvrobj.serve_forever()


Start the script in the same directory as the cgi script and HTML.
Assuming you have a file that holds '1' time per date, you could
write a program to pickle and unpickle dictionaries that
are derived from form data:

import pickle
import cgi

file = open('dates.pkl', 'rb')
mydates = pickle.load(file)
file.close()

html = """
<html>
<body>
<h1>Schedule</h1>
<form method=POST action="yourscript.py">
<table border=1>
<tr>
<td><input type=text name=april01 value=%(april01)s></td>
<td><input type=text name=april02 value=%(april02)s></td>
</tr>
<tr>
<td><input type=text name=april03 value=%(april03)s></td>
<td><input type=text name=april04 value=%(april04)s></td>
</tr>
</table>
<input type=hidden name=submitted value=done>
<p><input type=submit>
</form>
</body>
</html>
"""

dates = ['april01', 'april02', 'april03', 'april04']
if form.has_key('submitted'):
newdates = {}
for d in dates:
if form.has_key(d):
newdates[d] = form[d].value
else:
newdates[d] = ''
mydates = newdates
output = open('dates.pkl', 'wb')
pickle.dump(mydates, output)
output.close()
else:
for d in dates:
if not mydates.has_key(d):
mydates[d] = ''

print html % mydates


Then you could write an additional program that runs
in the background or something:

import pickle
from datetime import date, datetime

mycode = 'print "Hello World!"'
file = open('dates.pkl', 'rb')
mydates = pickle.load(file)
file.close()

while True:
today = date.today()
if today.month == 4 and today.day == 01:
hour = datetime.time(datetime.now()).hour
min = datetime.time(datetime.now()).minute
if hour == int(mydates['april04'][0]) and min ==
int(mydates['april04'][-2:]):
exec mycode

_exec_ executes a Python string like a program. To execute an actual
python script use subprocess instead:

import subprocess
subprocess.call(["python", "myscript.py"])

Hope this helps.

On 10/05/2012 11:55 AM, Luca Sanna wrote:
> hi,
>
> I enter a calendar in an html page
> in each calendar day, I enter a time that is used by the program to perform actions with python
>
> What can I use to do this?
>
> thanks
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar GadGets does not show calendar iccsi Windows 64bit 4 08-14-2011 01:52 PM
How to Synchronise Hotmail Calendar with Standard Outlook Calendar using Outlook Connector ?? Synapse Syndrome Computer Support 0 12-02-2007 04:19 AM
Thunderbird Calendar with Exchange 2003 Calendar and Public FoldersCalendar jincmcse Firefox 1 09-03-2005 02:46 AM
Calendar Control - Programatically set the calendar to a date range Shevek ASP .Net 3 06-23-2004 01:41 PM
Calendar Control - Programatically set the calendar to a date range Shevek ASP .Net Web Controls 0 06-23-2004 12:06 PM



Advertisments