473,507 Members | 8,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

dynamically generating temporary files through python/cgi

Is there a way to dynamically generate temporary files (such as an
html, xml or text file) in Python?

I'm not sure if I'm explaining myself clearly as I've no clue how to
describe this mechanism. I've seen it on certain websites that will
generate a file under certain parameters (through forms) that will
dissapear (i.e. delete itself) after a specified amount of time. These
files usually have some phony string for their filenames...like it's
been md5 hashed or something.

Is there a group of library functions that allow this? I imagine that
if i manually go and allocate a bunch of timers to monitor files, it
would be really expensive in load. Or perhaps is this a client-side
mechanism?

Thanks,
- poisondart

Jul 19 '05 #1
6 2182
poisondart wrote:
I've seen it on certain websites that will
generate a file under certain parameters (through forms) that will
dissapear (i.e. delete itself) after a specified amount of time...

Is there a group of library functions that allow this?


No.

The easiest way, in my mind would be to store the files in a directory
according to the hour they were requested, for example, a file generated
between 2 p.m. and 3 p.m. today:

http://www.example.com/temp/20050428...8ecf8427e.html

Then you can have a cron job that runs every hour that deletes
everything in the temp directory generated 24 hours ago.
--
Michael Hoffman
Jul 19 '05 #2
Michael Hoffman wrote:
The easiest way, in my mind would be to store the files in a directory
according to the hour they were requested, for example, a file generated
between 2 p.m. and 3 p.m. today:

http://www.example.com/temp/20050428...8ecf8427e.html


Depending on the filesystem you use, generating thousands of files in a
single directory might be somewhat inefficient. So you might want to
make subdirectories based on the MD5 digest instead, like this:

http://www.example.com/temp/20050428...8ecf8427e.html

--
Michael Hoffman
Jul 19 '05 #3
import tempfile
works under windows and linux

Jul 19 '05 #4
poisondart wrote:
Is there a way to dynamically generate temporary files (such as an
html, xml or text file) in Python?

I'm not sure if I'm explaining myself clearly as I've no clue how to
describe this mechanism. I've seen it on certain websites that will
generate a file under certain parameters (through forms) that will
dissapear (i.e. delete itself) after a specified amount of time. These
files usually have some phony string for their filenames...like it's
been md5 hashed or something.

Is there a group of library functions that allow this? I imagine that
if i manually go and allocate a bunch of timers to monitor files, it
would be really expensive in load. Or perhaps is this a client-side
mechanism?

Thanks,
- poisondart

hi there

first of you could use the tempfile

import tempfile

tempfile.mktemp('.thefileendingudlike')

i never really studied the cgi capability of python but for example in
php there is the posibility to serve a request with a mime formated
response such as html, gif, pdf, and so on. so if u want to generate
content dynamically u wouldn't need to store those files but generate
and send em on request without having to destroy them later on..

hope this is helpful

cheers

tc
Jul 19 '05 #5
poisondart wrote:
Is there a way to dynamically generate temporary files (such as an
html, xml or text file) in Python?

I'm not sure if I'm explaining myself clearly as I've no clue how to
describe this mechanism. I've seen it on certain websites that will
generate a file under certain parameters (through forms) that will
dissapear (i.e. delete itself) after a specified amount of time. These
files usually have some phony string for their filenames...like it's
been md5 hashed or something.

Is there a group of library functions that allow this? I imagine that
if i manually go and allocate a bunch of timers to monitor files, it
would be really expensive in load. Or perhaps is this a client-side
mechanism?

Thanks,
- poisondart

Typically such functionality would be provided by having the server
periodically run a task to delete files from the temporary directory
whose age exceeds a given value.

regards
Steve
--
Steve Holden +1 703 861 4237 +1 800 494 3119
Holden Web LLC http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/

Jul 19 '05 #6
On 27 Apr 2005 23:32:15 -0700, poisondart <po***********@gmail.com> wrote:
Is there a way to dynamically generate temporary files (such as an
html, xml or text file) in Python?

I'm not sure if I'm explaining myself clearly as I've no clue how to
describe this mechanism. I've seen it on certain websites that will
generate a file under certain parameters (through forms) that will
dissapear (i.e. delete itself) after a specified amount of time. These
files usually have some phony string for their filenames...like it's
been md5 hashed or something.

Is there a group of library functions that allow this? I imagine that
if i manually go and allocate a bunch of timers to monitor files, it
would be really expensive in load. Or perhaps is this a client-side
mechanism?


I think the best way to do that is have a web page that generates the
files with random filenames. These files probably ought to reside in
their own special directory. This web page gives the user a link to
the filename.

Next, have a cron job kick off every 5 minutes or so that deletes any
files that are older than 'X' minutes. This seems to be the simplest
approach.

jw
Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2897
by: JAWS | last post by:
I get this error message when trying to run a unittest test with a dynamically created test method: Traceback (most recent call last): File "unittest.py", line 215, in __call__ testMethod()...
2
1919
by: Satish Kumar Chimakurthi | last post by:
Hi all, An external solver program is dynamically producing files with different names 0000001.dat, 0000002.dat, 0000003.dat etc.....at regular intervals. These files contain all numeric data....
0
1890
by: Dan Gass | last post by:
The difflib.py module and the diff.py tools script in Python 2.4 alpha 3 now support generating side by side (with intra line differences) in HTML format. I have found this useful for performing...
13
4619
by: Tim Henderson | last post by:
Hi I want to dynamically generate a graph in python that would be displayable on a web page. What would be the best way to do this? The reason I want to do this, is because I am making a program...
4
5995
by: Andreas Jung | last post by:
Hi, does anyone know of a high-level solution to produce RTF from Python (something similar to Reportlab for producing PDF)? Thanks, Andreas -----BEGIN PGP SIGNATURE----- Version: GnuPG...
4
6756
by: Frank Millman | last post by:
Hi all I need to generate potentially large reports from a database, and I want to offer the option of print preview before actually printing (using wxPython). I figure that the best way to...
2
2330
by: rtilley | last post by:
A bit off-topic, but Python related. Below is a script that recursively deletes files from a directory. It works well on the two directories that I'm currently using it on: C:\Documents and...
4
1293
by: shaun roe | last post by:
I have a directory which contains many xml files as a result of some analysis. I would like to have an XSL which loops over all these files and generates a web page indicating some summary...
10
2553
by: Jess | last post by:
Hello, If I create a temporary object using a dynamically created object's pointer, then when the temporary object is destroyed, will the dynamically created object be destroyed too? My guess...
0
7220
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5617
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5037
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3188
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.