dynamically generating temporary files through python/cgi

Discussion in 'Python' started by poisondart, Apr 28, 2005.

  1. poisondart

    poisondart Guest

    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
    poisondart, Apr 28, 2005
    #1
    1. Advertising

  2. 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/20050428T14/d41d8cd98f00b204e9800998ecf8427e.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
    Michael Hoffman, Apr 28, 2005
    #2
    1. Advertising

  3. 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/20050428T14/d41d8cd98f00b204e9800998ecf8427e.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/20050428T14/d4/1d/8cd98f00b204e9800998ecf8427e.html

    --
    Michael Hoffman
    Michael Hoffman, Apr 28, 2005
    #3
  4. poisondart

    Jaime Wyant Guest

    On 27 Apr 2005 23:32:15 -0700, 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?


    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
    Jaime Wyant, Apr 28, 2005
    #4
  5. poisondart

    Steve Holden Guest

    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/
    Steve Holden, Apr 28, 2005
    #5
  6. 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
    Tiziano Bettio, Apr 28, 2005
    #6
  7. poisondart

    fred.dixon Guest

    import tempfile
    works under windows and linux
    fred.dixon, Apr 29, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    5
    Views:
    734
    Juan T. Llibre
    Jan 26, 2007
  2. Replies:
    1
    Views:
    653
    bruce barker
    Feb 22, 2007
  3. Replies:
    7
    Views:
    3,169
    James Kanze
    Feb 12, 2008
  4. AAaron123
    Replies:
    3
    Views:
    552
    AAaron123
    Nov 4, 2008
  5. Mark Liang

    generating ipod video through cgi

    Mark Liang, Jun 8, 2006, in forum: Ruby
    Replies:
    1
    Views:
    80
Loading...

Share This Page