#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0

    Pass start date and end date as command line argument in pyhton


    HI, I am new to pyhton and wanted to know how can i pass start date and end date as command line argument to retrieve data from table.
    I tried this code but it actually copied one given day with one camera name.

    PHP Code:
    #!/usr/bin/env python

    import anprint
    import os
    import sys
    import re
    import datetime
    from mydb import cursor

    try:
        
    cam_name sys.argv[1]
        
    rec_date sys.argv[2]
    except:
        print 
    "Usage: %s cam_name date " sys.argv[0]
        
    sys.exit(1)

    dbObj anprint.ExcelDb()

    # Get a list of the plates...
    tablename "customer_1.%s_anpr_vega" cam_name
    sql 
    """SELECT plate, datetime, id FROM %s WHERE date(datetime) ="%s" """ % (tablenamerec_date)
    cursor.execute(sql)
    retval cursor.fetchall()
    for 
    values in retval:
        print 
    values
        
    (vrmvrm_datetimerecord_id) = values
        dbObj
    .reconcile_plate(cam_namevrmvrm_datetimerecord_id
    Last edited by kiranv5; December 5th, 2013 at 05:53 AM. Reason: added info
  2. #2
  3. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,576
    Rep Power
    1906
    If you also want to specify a end date, you will have to add an additional argument (sys.argv[3]) to the program.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by MrFujin
    If you also want to specify a end date, you will have to add an additional argument (sys.argv[3]) to the program.
    thanks..
    It would take the argument as endate but i want the entire date range from 02 to 30 can you show how to write the code for it.

    PHP Code:
    try:
        
    cam_name sys.argv[1]
        
    rec_date sys.argv[2]
        
    end_date sys.argv[3]
    except:
        print 
    "Usage: %s cam_name date date " sys.argv[0]
        
    sys.exit(1)

    dbObj anprint.ExcelDb()

    # Get a list of the plates...
    tablename "customer_1.%s_anpr_vega" cam_name
    sql 
    """SELECT plate, datetime, id FROM %s WHERE date(datetime)' ="%s" """ % (tablenamerec_date,end_date)
    cursor.execute(sql)
    retval cursor.fetchall()
    for 
    values in retval:
        print 
    values
        
    (vrmvrm_datetimerecord_id) = values
        dbObj
    .reconcile_plate(cam_namevrmvrm_datetimerecord_id
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480
    Change the sql statement to

    ... (start <= field_date) and (field_date <= end);
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by b49P23TIvg
    Change the sql statement to

    ... (start <= field_date) and (field_date <= end);
    can i please explain to me where can i use it I am new to this language..

    Thanks
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,837
    Rep Power
    480

    untested, not a structured query language expert, ask in the database forum.


    Code:
    sql = """SELECT plate, datetime, id FROM {} WHERE (({} <= date(datetime)) and (date(datetime) <= {}))""" .format (tablename, rec_date,end_date)
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo