473,721 Members | 2,186 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...lik e 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 2187
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...lik e 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 ('.thefileendin gudlike')

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...lik e 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...lik e 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
2916
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() TypeError: ?() takes no arguments (1 given) I have no clue as to where the 1 given argument comes from...
2
1940
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. Is it possible to read each of these dynamically in python ?? If so, how should my code look like ?? If it was not dynamically required, then, I would change the name of the file in my *open* statement every time and read the corresponding one. But...
0
1904
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 build release comparisons (I use a script to generate a main page showing all the files that were changed in a build with hyperlinks to side by side differences for each of those files). I also find it useful for generating HTML test reports to...
13
4645
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 to convert data from scientic probes into web pages. I have been able to do every thing except the graph generation. Your help would be much appriciated
4
6014
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 v1.4.0 (Darwin)
4
6793
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 achieve this is to write the report to a temporary file, or more likely to a temporary directory with a separate file for each page. I can use that for previewing and for printing, and then delete the file/directory. There seems to be a few ways to...
2
2341
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 Settings\user\Cookies C:\Documents and Settings\user\Temp However, I'd like to use it on this directory as well:
4
1303
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 information from each one of these files. Is there any way of doing this in XSLT entirely, or am I forced to go to perl/python for this kind of task? I am aware of the "document" command in xsl but cannot see how to pipe it a whole series of files such...
10
2578
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 is that it's not destroyed, but I'm not sure. I have the following program: #include<iostream>
0
8840
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9367
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9064
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8007
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4484
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4753
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2130
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.