question

drdiesel avatar image
drdiesel asked

Help with python3 datetime in Venus v2.7+

I'm using an older script I found here to upload data to pvoutput. I am not a python expert but I have successfully converted it to python3 for use with Venus v2.7+ and i'm left with one last issue I can't seem to figure out. When I call datetime.now it returns the correct time in UTC, but I need local time. This wouldn't be a big deal but easiest packages to make this happen are not available, pytz and/or timedelta. To my knowledge these cannot be installed and survive upgrades/reboots?

I won't clog the next few pages with all of the code, I simply need to turn datetime which returns this in UTC:

2021-08-19 18:25:04.424956

Into local time (Eastern US) that obeys daylight savings time? I'm sure I'm missing a supported way to achieve this without writing a custom function to simply subtract hours between certain dates.


BR,

Edit, I'm currently on v2.80~13

Venus OS
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

2 Answers
jeroen avatar image
jeroen answered ·

This should work:

import datetime, os, time; os.environ['TZ'] = 'Europe/London'; time.tzset(); print(datetime.datetime.now())
1 comment
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

drdiesel avatar image drdiesel commented ·
Works, thank you Sir!
0 Likes 0 ·
isimobile avatar image
isimobile answered ·

@DrDiesel You willing to share your script? I tried to convert my script to version 3, but something is not working. It is not uploading with python3

5 comments
2 |3000

Up to 8 attachments (including images) can be used with a maximum of 190.8 MiB each and 286.6 MiB total.

drdiesel avatar image drdiesel commented ·

Hi @isimobile

Going from v2.80~13 to v2.80 broke all of my and my customers scripts, including this one (though it's not erroring out, running just not working, so some data format or something has changed). I have been working to resolve the issues but I've not yet gotten to this one, but once I do I will post back here.

BR,

0 Likes 0 ·
isimobile avatar image isimobile drdiesel commented ·

Hi @dr.diesel ,

I got it working. Had to made a few more changes. Seems to be working fine now.

You can find the new script here: https://github.com/isimobile/dbus-pvoutput It is the file named dbus-pvoutput-p3.py

Hope it helps.



0 Likes 0 ·
isimobile avatar image isimobile isimobile commented ·

Ok, code sort of works, but also not. So do not use yet. will see if I can get it working.

It seems the conversion does not work 100% the stats.pg & stats.pc value should change but it does not.


0 Likes 0 ·
isimobile avatar image isimobile isimobile commented ·
Ok, got it working. Took a while figuring it out. Code available from above link.
0 Likes 0 ·
drdiesel avatar image drdiesel isimobile commented ·
Thank you @isimobile
0 Likes 0 ·

Related Resources