Cross platform Python code -


edit

further other below info , helpful input issue caused using strftime %s generate unix timestamp (which system being queried requires). strftime %s not compatible windows platform therefore need use alternative method generate unix timestamp. jez has suggested time.time() have experimented i'm not doing right somewhere along way. need change section of code using strftime time():

    if (args.startdate):        from_time=str(int(args.startdate.strftime('%s')) * 1000)     if (args.enddate):        to_time=str(int(args.enddate.strftime('%s')) * 1000) 

any or steer appreciated. :)

/edit

i've been given python script appears run ok when deployed on apple laptop gives error message when run on windows machine. need talk 3rd party through executing file remotely , has windows machine need try , figure out why isn't working. i'm running 2.7 reference. section appears error being caused:

if __name__ == "__main__": parser = argparse.argumentparser() parser.add_argument('-s', "--startdate", help="the start date (included)- format yyyy-mm-dd -- if not specified earliest available data", type=valid_date) parser.add_argument('-e', "--enddate", help="the end date (excluded) - format yyyy-mm-dd  -- if not specified 'now'", type=valid_date) parser.add_argument('-u', "--user", help="user name use", default='admin') parser.add_argument('-p', "--password", help="password user", default='redwood') parser.add_argument('-a', "--attribute", help="attribute", choices=['temperature', 'motion', 'input-power', 'output-power'], default='motion') parser.add_argument('host', help='hostname/ip address of engine connect to', default='127.0.0.1') args = parser.parse_args()     user = args.user         passwd = args.password     if (args.startdate):        from_time=str(int(args.startdate.strftime('%s')) * 1000)     if (args.enddate):        to_time=str(int(args.enddate.strftime('%s')) * 1000)      scale=1     unit='seconds since 1.1.1970'     if (args.attribute == 'temperature'):        path=temperature_path        scale = 100        unit = "degrees celsius"     elif (args.attribute == 'output-power'):        path=opower_path        scale = 100        unit = "watts"     elif (args.attribute == 'input-power'):        path=ipower_path        scale = 1000        unit = "watts"     else:        path=motion_path     print "epoch time, local time (this machine), attribute, value (%s) " % unit query_stats(args.host) 

this command i'm using execute:

c:\python27>python stats_query.py -s 2016-03-18 -e 2016-03-19 -u admin -p admin -a motion 192.168.2.222 

and error message get:

traceback (most recent call last): file "stats_query.py", line 132, in <module> from_time=str(int(args.startdate.strftime('%s')) * 1000) valueerror: invalid format string 

if has thoughts i'd appreciate feedback. apologies if i'm asking stupid question - i'm not familiar python.

if want print in seconds, use %s (with capital s).


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -