Need to pass variables from mod_python publisher to standalonescript.

Discussion in 'Python' started by Anthony Raj, Jun 18, 2004.

  1. Anthony Raj

    Anthony Raj Guest

    There's a problem which I'm trying to solve as elegently as possible.

    Its basically a setup that runs mod_python on Apache and its for a
    client that needs to generate dynamic reports by pulling out records
    from Postgres.

    Now once the report is generated , we mail the report in csv format to
    the requested mailid.

    We're trying to seperate the report generation / mailing part from the
    mod_python code by
    passing the report parameters to an external python script and
    processing & mailing the report externally from the httpd daemon .

    We want to do this because some of the reports take something like 5mins
    or more and its really painful for
    having to wait for the report to download etc. (believe me its about a
    couple million records in the db) .

    The solution I have is something like this
    1. Create the a script test.py
    which can be called like so -
    ../test.py -b "{'username': ['motorola'], 'tmonth': ['1'],
    'metrics_select': ['0'], 'dateperiod': ['2'], 'keyword': ['tablecloth']}"
    The parameter would actually be a dict that is processed by mod_python
    and converted into a string.

    2. test.py has a function convert_both() which converts the string that
    is passed into a dictionary (attached below).
    The code works well so far.

    >>>>>> test.py >>>>>>

    #! /usr/bin/python
    import sys
    import getopt
    import t

    #for argv in sys.argv : print "args = ",argv

    def main(argv):
    try :
    opts , args = getopt.getopt(argv,"hg:b:d",["help","grammar="])
    except getopt.GetoptError:
    sys.exit(2)

    for o,a in opts :
    if o in ("-b","--both"): return a

    if __name__ == "__main__":
    both = main(sys.argv[1:])
    print "args(both) = ",both

    d = t.convert_both(both)
    print 'd = ',d
    # Other processing like db transactions & mailing csv files done later.


    3. The issue is currently to be able to invoke this script from within a
    mod_python code .
    ../test.py -b "string from a dictionary" ( needs to be called from a
    python script to work)

    Also I have my doubts if this could be solved in any better way .

    ~Anthony
     
    Anthony Raj, Jun 18, 2004
    #1
    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. Nancy
    Replies:
    1
    Views:
    572
    Doug Holton
    Jul 18, 2004
  2. charlie knudsen

    mod_python 2.7.10 - publisher

    charlie knudsen, Nov 27, 2004, in forum: Python
    Replies:
    1
    Views:
    474
    charliek
    Nov 28, 2004
  3. Python_it
    Replies:
    0
    Views:
    503
    Python_it
    Oct 12, 2005
  4. exhuma.twn
    Replies:
    3
    Views:
    347
    exhuma.twn
    Mar 20, 2006
  5. exhuma.twn
    Replies:
    2
    Views:
    534
    exhuma.twn
    Mar 20, 2006
Loading...

Share This Page