Re: [weewx-development] Re: Python 3 version available for limited testing

2019-04-03 Thread Thomas Keffer
Thanks, Luc

Make sure you forward them on to the respective authors.

On Wed, Apr 3, 2019 at 6:04 PM  wrote:

> Tom,
>
> Improved versions for meteotemplate.py, wcloud.py and weather365.py.
> The should run on both Python 2 and Python 3.
>
> Luc
>


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-04-03 Thread ljm . heijst
Tom,

Improved versions for meteotemplate.py, wcloud.py and weather365.py.
The should run on both Python 2 and Python 3.

Luc
#!/usr/bin/env python
# Copyright 2016-2017 Matthew Wall
# Licensed under the terms of the GPLv3

"""
Meteotemplate is a weather website system written in PHP by Jachym.

http://meteotemplate.com

This is a weewx extension that uploads data to a Meteotemplate server.  It uses
the API described in the meteotemplate wiki:

http://www.meteotemplate.com/web/wiki/wikiAPI.php

The set of fields actually sent depends on the sensors available and the way
the hardware sends data from those fields.

More specifically, this extension works with the following API specification:

URL: http[s]://TEMPLATE_ROOT/api.php

Parameters:
  PASS - the "update password" in meteotemplate settings
  U - datetime as epoch
  T - temperature (C)
  H - humidity (%)
  P - barometer (mbar)
  W - wind speed (km/h)
  G - wind gust (km/h)
  B - wind direction (0-359)
  R - daily cumulative rain (mm since midnight)
  RR - current rain rate (mm/h)
  S - solar radiation (W/m^2)
  UV - ultraviolet index
  TIN - indoor temperature (C)
  HIN - indoor humidity (%)
  ...

A parameter is ignored if:
 - it is not provided in the URL
 - it is blank (e.g., T===)
 - is set to null (e.g., T=null=null)

Each request must contain PASS, U, and at least one parameter.

Data can be sent at any interval.  If the interval is shorter than 5 minutes,
data will be cached then aggregated.  The meteotemplate database is updated
every 5 minutes.

Battery status is handled properly for battery status fields in the default
schema.  Battery voltages are not included (the meteotemplate API has no
provision for battery voltage).
"""
from __future__ import print_function  # Python 2/3 compatiblity

from distutils.version import StrictVersion
import sys
import syslog
import time

# Python 2/3 compatiblity
try:
import Queue as queue# python 2
from urllib import urlencode# python 2
from urllib2 import Request# python 2
except ImportError:
import queue# python 3
from urllib.parse import urlencode# python 3
from urllib.request import Request# python 3

import weewx
import weewx.restx
import weewx.units
from weeutil.weeutil import to_bool, accumulateLeaves, startOfDay, list_as_string

VERSION = "0.10"

REQUIRED_WEEWX = "3.5.0"
if StrictVersion(weewx.__version__) < StrictVersion(REQUIRED_WEEWX):
raise weewx.UnsupportedFeature("weewx %s or greater is required, found %s"
   % (REQUIRED_WEEWX, weewx.__version__))

def logmsg(level, msg):
syslog.syslog(level, 'restx: Meteotemplate: %s' % msg)

def logdbg(msg):
logmsg(syslog.LOG_DEBUG, msg)

def loginf(msg):
logmsg(syslog.LOG_INFO, msg)

def logerr(msg):
logmsg(syslog.LOG_ERR, msg)


class Meteotemplate(weewx.restx.StdRESTbase):
DEFAULT_URL = 'http://localhost/template/api.php'

def __init__(self, engine, cfg_dict):
"""This service recognizes standard restful options plus the following:

Parameters:

password: the shared key for uploading data

server_url: full URL to the meteotemplate ingest script
"""
super(Meteotemplate, self).__init__(engine, cfg_dict)
loginf("service version is %s" % VERSION)
try:
site_dict = cfg_dict['StdRESTful']['Meteotemplate']
site_dict = accumulateLeaves(site_dict, max_level=1)
site_dict['password']
except KeyError as e:
logerr("Data will not be uploaded: Missing option %s" % e)
return

site_dict.get('server_url', Meteotemplate.DEFAULT_URL)
binding = list_as_string(site_dict.pop('binding', 'archive').lower())

try:
_mgr_dict = weewx.manager.get_manager_dict_from_config(
cfg_dict, 'wx_binding')
site_dict['manager_dict'] = _mgr_dict
except weewx.UnknownBinding:
pass

self._queue = queue.Queue()
try:
self._thread = MeteotemplateThread(self._queue, **site_dict)
except weewx.ViolatedPrecondition as e:
loginf("Data will not be posted: %s" % e)
return

self._thread.start()
if 'loop' in binding:
self.bind(weewx.NEW_LOOP_PACKET, self.handle_new_loop)
if 'archive' in binding:
self.bind(weewx.NEW_ARCHIVE_RECORD, self.handle_new_archive)
if 'both' in binding:
self.bind(weewx.NEW_LOOP_PACKET, self.handle_new_loop)
self.bind(weewx.NEW_ARCHIVE_RECORD, self.handle_new_archive)
loginf("Data will be uploaded to %s" % site_dict['server_url'])

def handle_new_loop(self, event):
self._queue.put(event.packet)

def handle_new_archive(self, event):
self._queue.put(event.record)


class MeteotemplateThread(weewx.restx.RESTThread):

try:
  

Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-30 Thread ljm . heijst

>
> On Saturday, 30 March 2019 16:27:32 UTC-3, Hartmut Schweidler wrote:
>>
>> I do not remember where I read (ich weiß ich mehr wo ich gelesen habe)
>>
>
I found it here: 
https://groups.google.com/forum/#!msg/weewx-user/h_gvi_b0Inc/Sxfz-waQCAAJ

Hartmut, please open a new thread if you have questions about the uploaded 
software. This tread is about converting programs for use with python3.

Luc


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-30 Thread ljm . heijst


On Saturday, 30 March 2019 16:27:32 UTC-3, Hartmut Schweidler wrote:
>
> Hallo
>
> in kl.py Klimalog-driver
>
>  temp x < 81.0 if temp x = 81.0 temp not defined
> also 
>  humidity x < 100.0 if humidity > 100 not defined
>
> # calculate dewpoints and heatindices
> # FIXME: this belongs in StdWXCalculate
> for y in range(0, 9):
> if data.values['Temp%d' % y] < 81.0 and data.values[
> 'Humidity%d' % y] < 100.1:
> data.values['Dewpoint%d' % y] = weewx.wxformulas.dewpointC
> (data.values['Temp%d' % y], data.values['Humidity%d' % y])
> data.values['Heatindex%d' % y] = weewx.wxformulas.
> heatindexC(data.values['Temp%d' % y], data.values['Humidity%d' % y])
>
> I do not remember where I read (ich weiß ich mehr wo ich gelesen habe)
>
>

Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-30 Thread Hartmut Schweidler
Hallo

in kl.py Klimalog-driver

 temp x < 81.0 if temp x = 81.0 temp not defined
also 
 humidity x < 100.0 if humidity > 100 not defined

# calculate dewpoints and heatindices
# FIXME: this belongs in StdWXCalculate
for y in range(0, 9):
if data.values['Temp%d' % y] < 81.0 and data.values['Humidity%d' 
% y] < 100.1:
data.values['Dewpoint%d' % y] = weewx.wxformulas.dewpointC(
data.values['Temp%d' % y], data.values['Humidity%d' % y])
data.values['Heatindex%d' % y] = weewx.wxformulas.heatindexC
(data.values['Temp%d' % y], data.values['Humidity%d' % y])

I do not remember where I read (ich weiß ich mehr wo ich gelesen habe)



Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-30 Thread ljm . heijst
Thanks, will change it.

Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-30 Thread Hartmut Schweidler
Hallo Luc
Hallo Tom


the driver meteostick.py

# message received via repeater
# Calculate crc with bytes 0-5 and 8-9, result must be equal
# to bytes 6-7
chksum = (pkt[6] << 8) + pkt[7]
for i in xrange(0, 6):must ---> range not xrange in 
Python3
raw_msg_crc[i] = chr(int(parts[i + 2], 16))
for i in range(6, 8):
raw_msg_crc[i] = chr(int(parts[i + 4], 16))
Meteostick._check_crc(raw_msg_crc, chksum)
 the error only after 1 hour 

Hartmut 


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-30 Thread Hartmut Schweidler


Am Samstag, 30. März 2019 08:52:44 UTC+1 schrieb Hartmut Schweidler:
>
> Hallo Luc
> Hallo Tom
>
> Good Morning
> the driver meteostick.py
>
> is IO 
>
> I need a hint
> if a value = Null or None
>
> an Error 
> Mar 30 08:45:21 wx2013 weewx[6461]: cheetahgenerator:  Reason: 
> unorderable types: NoneType() < int()
> Mar 30 08:45:21 wx2013 weewx[6461]:   Traceback (most recent call last
> ):
> Mar 30 08:45:21 wx2013 weewx[6461]: File 
> "/home/weewx/bin/weewx/cheetahgenerator.py", line 331, in generate
> Mar 30 08:45:21 wx2013 weewx[6461]:   unicode_string = 
> compiled_template.respond()
> Mar 30 08:45:21 wx2013 weewx[6461]: File 
> "_home_weewx_skins_Standard_indexOWFS_html_tmpl.py", line 743, in respond
> Mar 30 08:45:21 wx2013 weewx[6461]:   TypeError: unorderable types: 
> NoneType() < int()
>
> my dog wants ...
>
> see you later Hartmut
>


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-30 Thread Hartmut Schweidler
Hallo Luc
Hallo Tom

Good Morning
the driver meteotemplate.py

is IO 

I need a hint
if a value = Null or None

an Error 
Mar 30 08:45:21 wx2013 weewx[6461]: cheetahgenerator:  Reason: 
unorderable types: NoneType() < int()
Mar 30 08:45:21 wx2013 weewx[6461]:   Traceback (most recent call last):
Mar 30 08:45:21 wx2013 weewx[6461]: File 
"/home/weewx/bin/weewx/cheetahgenerator.py", line 331, in generate
Mar 30 08:45:21 wx2013 weewx[6461]:   unicode_string = 
compiled_template.respond()
Mar 30 08:45:21 wx2013 weewx[6461]: File 
"_home_weewx_skins_Standard_indexOWFS_html_tmpl.py", line 743, in respond
Mar 30 08:45:21 wx2013 weewx[6461]:   TypeError: unorderable types: 
NoneType() < int()

my dog wants ...

see you later Hartmut


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-26 Thread ljm . heijst
On Tuesday, 26 March 2019 14:52:48 UTC-3, Hartmut Schweidler wrote:
>
> I'm looking for the drivers  "Meteostick driver for weewx" and/ or "klimalogg 
> driver for weewx" as python3 version
>

Hallo Hartmut,

I will convert and test those two drivers the coming days.

Luc


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-26 Thread Hartmut Schweidler
Hallo

I'm looking for the drivers  "Meteostick driver for weewx" and/ or "klimalogg 
driver for weewx" as python3 version

Hartmut


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread ljm . heijst
On Monday, 25 March 2019 17:59:57 UTC-3, vince...@gmail.com wrote:
>
> You might want to do an altinstall of a later version.   Email me if you 
> want a script I found that does this nicely on the pi and I'll send it 
> tonight...
>

Vince,

Thanks.

Currently all problems are solved and I have two drivers converted both 
running on python 2 and 3 with help of Tom.

Also: I have the latest version of raspbian installed 
(2018-11-13-raspbian-stretch-lite.img) and runned apt-get update and 
apt-get upgrade.
I see no need to go to a higher version of python right now.

Luc


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread Thomas Keffer
If you used

import six
from six.moves import queue


then you want

except queue.Empty


If you are not using six, then you can do something like:

try:
import Queue as queue
except ImportError:
import queue


and the except clause becomes:

except queue.Empty


-tk


On Mon, Mar 25, 2019 at 12:53 PM Thomas Keffer  wrote:

> I can't speak to the logic of the code, but it looks like it should work
> under Python 2 and 3. A couple things to think about:
>
>1. You cannot count on the user having the shim 'six', although it is
>becoming increasingly common. Many python installations include it by
>default. In any case, as you experienced, it's a simple install.
>2. In many places you have something like "m =
>ProcManager.TS.search(str(line))". I assume you needed the str() to
>convert what would otherwise be a byte-string under Python 3 into a true
>string so it can be used in a regular expression. However, by default, that
>conversion is done using the ASCII codec. If "line" has something other
>than ASCII in it, an exception will be raised. If that's a possibility, you
>should use the "decode" function instead: "m =
>ProcManager.TS.search(line.decode('utf-8'))".
>
> -tk
>
> On Mon, Mar 25, 2019 at 11:36 AM  wrote:
>
>> Tom,
>>
>> The driver weewx-tfrc is converted to python 3 and the same file runs
>> without problems on both
>> pi31 (with python2) as pi36 (with python3). See the attached diff file.
>>
>> I didn't make any changes on the python2 system.
>> I tried to install python-six, but as you can see below, the package was
>> already installed.
>>
>> root@pi31:~# apt-get install python-six
>> Reading package lists... Done
>> Building dependency tree
>> Reading state information... Done
>> python-six is already the newest version (1.10.0-3).
>> python-six set to manually installed.
>> 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
>>
>> Luc
>>
>


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread Thomas Keffer
I can't speak to the logic of the code, but it looks like it should work
under Python 2 and 3. A couple things to think about:

   1. You cannot count on the user having the shim 'six', although it is
   becoming increasingly common. Many python installations include it by
   default. In any case, as you experienced, it's a simple install.
   2. In many places you have something like "m =
   ProcManager.TS.search(str(line))". I assume you needed the str() to
   convert what would otherwise be a byte-string under Python 3 into a true
   string so it can be used in a regular expression. However, by default, that
   conversion is done using the ASCII codec. If "line" has something other
   than ASCII in it, an exception will be raised. If that's a possibility, you
   should use the "decode" function instead: "m =
   ProcManager.TS.search(line.decode('utf-8'))".

-tk

On Mon, Mar 25, 2019 at 11:36 AM  wrote:

> Tom,
>
> The driver weewx-tfrc is converted to python 3 and the same file runs
> without problems on both
> pi31 (with python2) as pi36 (with python3). See the attached diff file.
>
> I didn't make any changes on the python2 system.
> I tried to install python-six, but as you can see below, the package was
> already installed.
>
> root@pi31:~# apt-get install python-six
> Reading package lists... Done
> Building dependency tree
> Reading state information... Done
> python-six is already the newest version (1.10.0-3).
> python-six set to manually installed.
> 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
>
> Luc
>


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread ljm . heijst
On Monday, 25 March 2019 15:57:14 UTC-3, vince...@gmail.com wrote:
>
> Just in case, what os are you on, which version, and what version of 
> python3 are you running ?
>

Vince, 

root@pi36:~# uname -a
Linux pi36 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l 
GNU/Linux
root@pi36:~# python --version
Python 2.7.13
root@pi36:~# python3 --version
Python 3.5.3

Luc


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread ljm . heijst
On Monday, 25 March 2019 15:36:08 UTC-3, Tom Keffer wrote:
>
> What's the problem with getting it working?
>

This statemennt:
except Queue.Empty:
All variations I tried gave different errors.
except Queue.Empty:
except Queue.empty:
except queue.Empty:
except queue.empty:

Futhermore: when I change:
def __init__(self):
self._cmd = None
self._process = None
self.stdout_queue = Queue.Queue()
self.stdout_reader = None
self.stderr_queue = Queue.Queue()
self.stderr_reader = None
intO
def __init__(self):
self._cmd = None
self._process = None
self.stdout_queue = Queue()
self.stdout_reader = None
self.stderr_queue = Queue()
self.stderr_reader = None

I don't get errors, but also I don't get any data from the que.

Luc


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread ljm . heijst
On Monday, 25 March 2019 12:53:01 UTC-3, ljm.h...@gmail.com wrote:
>
> I will try this construction once again.
>

Tom,

I give up; can't get it working. I'll wait for Matthew to convert his 
weewx-sdr driver; I've 'borrowed' the code from there.

Luc 


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread ljm . heijst
On Monday, 25 March 2019 12:25:29 UTC-3, Tom Keffer wrote:
>
> from queue import Queue
> works for me under Python 3.
>

Tom, 

I will try this construction once again.

How should I solve the Python 2: xrange, Python 3: range differences?

Luc 


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread ljm . heijst
Soory, I made a mistake.
 

> The first snippet should be:
> snippet from cmon.py:
> ===
> def new_archive_record(self, event):
> """save data to database then prune old records as needed"""
> now = int(time.time() + 0.5)
> delta = now - event.record['dateTime']
> if delta > event.record['interval'] * 60:
> logdbg("Skipping record: time difference %s too big" % delta)
> return
> if self.last_ts is not None:
>
(this line is removed) 

> self.save_data(self.get_data(now, self.last_ts)) ### line 728
> self.last_ts = now
> if self.max_age is not None:
> self.prune_data(now - self.max_age)
>
> def save_data(self, record):
> """save data to database"""
> self.dbm.addRecord(record) ### line 735
> ===
>
> Luc 


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread ljm . heijst
Hi Tom,

I do not know if this issue is known already.

I got a deadlock in cmon.py, see code and traceback below:

snippet from cmon.py:
===
def new_archive_record(self, event):
"""save data to database then prune old records as needed"""
now = int(time.time() + 0.5)
delta = now - event.record['dateTime']
if delta > event.record['interval'] * 60:
logdbg("Skipping record: time difference %s too big" % delta)
return
if self.last_ts is not None:
data = self.get_data(now, self.last_ts)
self.save_data(self.get_data(now, self.last_ts)) ### line 728
self.last_ts = now
if self.max_age is not None:
self.prune_data(now - self.max_age)

def save_data(self, record):
"""save data to database"""
self.dbm.addRecord(record) ### line 735
===

Mar 25 10:25:18 pi36 tfrc[4503]: engine: Shutting down StdReport thread
Mar 25 10:25:38 pi36 tfrc[4503]: engine: Unable to shut down StdReport 
thread
Mar 25 10:25:38 pi36 tfrc[4503]: tfrc: MainThread: shutdown process 
/home/pi/tfrec/tfrec -D -T 1
Mar 25 10:25:38 pi36 tfrc[4503]: tfrc: MainThread: tfrec with pid 4525 
killed
Mar 25 10:25:38 pi36 tfrc[4503]: engine: Caught unrecoverable exception in 
engine:
Mar 25 10:25:38 pi36 tfrc[4503]:   (1213, 'Deadlock found when 
trying to get lock; try restarting transaction')
Mar 25 10:25:38 pi36 tfrc[4503]:   : Traceback (most recent call 
last):
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/home/weewx/bin/weewx/engine.py", line 196, in run
Mar 25 10:25:38 pi36 tfrc[4503]:   :
 self.dispatchEvent(weewx.Event(weewx.CHECK_LOOP, packet=packet))
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/home/weewx/bin/weewx/engine.py", line 225, in dispatchEvent
Mar 25 10:25:38 pi36 tfrc[4503]:   : callback(event)
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/home/weewx/bin/weewx/engine.py", line 565, in check_loop
Mar 25 10:25:38 pi36 tfrc[4503]:   : raise BreakLoop
Mar 25 10:25:38 pi36 tfrc[4503]:   : weewx.engine.BreakLoop
Mar 25 10:25:38 pi36 tfrc[4503]:   :
Mar 25 10:25:38 pi36 tfrc[4503]:   : During handling of the above 
exception, another exception occurred:
Mar 25 10:25:38 pi36 tfrc[4503]:   :
Mar 25 10:25:38 pi36 tfrc[4503]:   : Traceback (most recent call 
last):
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/home/weewx/bin/weewx/engine.py", line 581, in post_loop
Mar 25 10:25:38 pi36 tfrc[4503]:   :
 self._catchup(self.engine.console.genArchiveRecords)
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/home/weewx/bin/weewx/engine.py", line 633, in _catchup
Mar 25 10:25:38 pi36 tfrc[4503]:   : for record in 
generator(lastgood_ts):
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/home/weewx/bin/weewx/drivers/__init__.py", line 30, in genArchiveRecords
Mar 25 10:25:38 pi36 tfrc[4503]:   : raise 
NotImplementedError("Method 'genArchiveRecords' not implemented")
Mar 25 10:25:38 pi36 tfrc[4503]:   : NotImplementedError: Method 
'genArchiveRecords' not implemented
Mar 25 10:25:38 pi36 tfrc[4503]:   :
Mar 25 10:25:38 pi36 tfrc[4503]:   : During handling of the above 
exception, another exception occurred:
Mar 25 10:25:38 pi36 tfrc[4503]:   :
Mar 25 10:25:38 pi36 tfrc[4503]:   : Traceback (most recent call 
last):
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/home/weewx/bin/weedb/mysql.py", line 51, in guarded_fn
Mar 25 10:25:38 pi36 tfrc[4503]:   : return fn(*args, **kwargs)
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/home/weewx/bin/weedb/mysql.py", line 261, in execute
Mar 25 10:25:38 pi36 tfrc[4503]:   :
 self.cursor.execute(mysql_string, tuple(sql_tuple))
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 226, in execute
Mar 25 10:25:38 pi36 tfrc[4503]:   : self.errorhandler(self, 
exc, value)
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/usr/lib/python3/dist-packages/MySQLdb/connections.py", line 36, in 
defaulterrorhandler
Mar 25 10:25:38 pi36 tfrc[4503]:   : raise errorvalue
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 217, in execute
Mar 25 10:25:38 pi36 tfrc[4503]:   : res = self._query(query)
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 378, in _query
Mar 25 10:25:38 pi36 tfrc[4503]:   : rowcount = 
self._do_query(q)
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/usr/lib/python3/dist-packages/MySQLdb/cursors.py", line 341, in _do_query
Mar 25 10:25:38 pi36 tfrc[4503]:   : db.query(q)
Mar 25 10:25:38 pi36 tfrc[4503]:   :   File 
"/usr/lib/python3/dist-packages/MySQLdb/connections.py", line 280, in query
Mar 25 10:25:38 pi36 tfrc[4503]: 

Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-25 Thread Thomas Keffer
Luc,

You are very close to having a code base that will run under both Python 2
and 3. Suggestions:

1. Put this at the top to cover your use of multiple arguments to "print":

from __future__ import print_function

2. For a queue, do this:

try:
# Python 2
from Queue import Queue
except ImportError:
# Python 3
from queue import Queue

Then use "Queue" throughout your code.

3. Your use of "strerror" is non-standard. Instead of this:

   except ValueError as e:
   logerr('thermistor_temp failed for temp_raw %s r (k ohm) %s'
  'error: %s' % (temp_raw, r, e.strerror))

do this:

   except ValueError as e:
   logerr('thermistor_temp failed for temp_raw %s r (k ohm) %s'
  'error: %s' % (temp_raw, r, e))

That's it!

-tk

On Mon, Mar 25, 2019 at 5:15 AM  wrote:

> On Sunday, 24 March 2019 20:02:49 UTC-3, Tom Keffer wrote:
>>
>> Your choices:
>>
> Do a global install, much like we do with Python 2.x. Instructions are in
> the setup.py guide in the development branch. I've also pasted it below.
>
> Tom,
>
> Attached the results of the conversion to python3 of the weewx-rtld driver.
>
> Luc
>


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-02 Thread Thomas Keffer
Yes, this is a limitation in the way database bindings are presently
implemented. It is very hard for a search list extension (in this case,
$alltime) to use a custom binding.

Thank you for reminding me. Version 4 would be a good time to introduce
these kinds of changes, as they may break backwards compatibility.

I've created issue #384  to
track.

-t

On Sat, Mar 2, 2019 at 12:06 PM Hartmut Schweidler 
wrote:

> Thanks
>
>  now weewx 4.0 ... runs under python 3.5, but not  completely.
>
> The upload via FTP is running Thanks
>
>
> progress is under  http://wh3080.hes61.de/
> 
>  to
> observe
> I will post my version in my GIT project as a new version
>
> one thing is there yet I have at
>
> in tags.py I used the old version
> like
> # Iterate over custom span
> def spans(self, data_binding=None, context='day', interval=10800):
> -> python3 -->   def spans(self, context='day', interval=10800):
> for span in weeutil.weeutil.intervalgen(self.timespan.start,
> self.timespan.stop, interval):
> yield TimespanBinder(span, self.db_lookup, data_binding,
>  context, self.formatter, self.converter,
> **self.option_dict)
>
> # Iterate over hours in the time period:
> def hours(self, data_binding=None):  new in python3 is def
> hours(self):
> return TimespanBinder._seqGenerator(weeutil.weeutil.genHourSpans,
> self.timespan,
> self.db_lookup, data_binding,
> 'hour', self.formatter,
> self.converter, **self.option_dict)
>
>
> otherwise there is ERROR in
> #for $year in $alltime.years($data_binding='wd_binding')
> 
>   $year.dateTime.format("%Y")
>  #for $month in $year.months($data_binding='wd_binding')
>  #if $month.outTempDay.min.raw is not None:
> $month.outTempDay.min.formatted
>  #else
> -
>  #end if
>  #end for
> 
> #end for
> maximale Nachttemperatur in der Zeit von 18:00
> Uhr bis 06:00 Uhr
> #for $year in $alltime.years($data_binding='wd_binding')
> 
>   $year.dateTime.format("%Y")
>  #for $month in $year.months($data_binding='wd_binding')
>  #if $month.outTempNight.max.raw is not None:
> $month.outTempNight.max.formatted
>  #else
> -
>  #end if
>  #end for
> 
> #end for
>
>
> lock at  http://wh3080.hes61.de/temp.html
>
>
>> Tagestemperatur in °C (Tag oder Nacht)
>>   Jan Feb Mär Apr Mai Jun Jul Aug Sep Okt Nov Dez
>> minimale Tagestemperatur in der Zeit von 06:00 Uhr bis 18:00 Uhr
>> 2019 - -3,4 -1,1 - - - - - - - - -
>> maximale Nachttemperatur in der Zeit von 18:00 Uhr bis 06:00 Uhr
>> 2019 - 10,0 10,9 - - - - - - - - -
>>
>
>
> thanks again Hartmut
>


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-02 Thread Thomas Keffer
Thanks again!

Fixed in commit 6c24156


Do a pull, and try again.

On Sat, Mar 2, 2019 at 11:18 AM Hartmut Schweidler 
wrote:

> I uploaded the "public_html"  via fileZilla for testing
>
>  the site on http://wh3080.hes61.de/index.html
> it is not complete yet
> but it looks good
>
>
>


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-02 Thread Hartmut Schweidler
I uploaded the "public_html"  via fileZilla for testing

 the site on http://wh3080.hes61.de/index.html  
it is not complete yet 
but it looks good




Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-02 Thread Hartmut Schweidler
Thank you for your prompt reply.
i forgot in weewx.conf

[[FTP]]
> # FTP'ing the results to a webserver is treated as just another 
> report,
> # albeit one with an unusual report generator!
> skin = Ftp
>
> # If you wish to use FTP, set "enable" to "true", then
> # fill out the next four lines.
> # Use quotes around passwords to guard against parsing errors.
> enable = true
> user = NAME
> password = PASS
> server = SERVER
>
   path = /

# Set to True for an FTP over TLS (FTPS) connection. Not all servers
# support this.
secure_ftp = False

# To upload files from something other than what HTML_ROOT is set
# to above, specify a different HTML_ROOT here.
#HTML_ROOT = public_html

# Most FTP servers use port 21
port = 21

# Set to 1 to use passive mode, zero for active mode
passive = 1


the error message

Mar  2 19:55:39 wx2013 weewx[31777]: copygenerator: copied 0 files to /home/
weewx/public_html/mobile
Mar  2 19:58:00 wx2013 weewx[31777]: reportengine: Caught unrecoverable 
exception in generator 'weewx.reportengine.FtpGenerator'
Mar  2 19:58:00 wx2013 weewx[31777]:   catching classes that do 
not inherit from BaseException is not allowed
Mar  2 19:58:00 wx2013 weewx[31777]:   Traceback (most recent 
call last):
Mar  2 19:58:00 wx2013 weewx[31777]: File 
"/home/weewx/bin/weewx/reportengine.py", line 351, in run
Mar  2 19:58:00 wx2013 weewx[31777]:   n = ftp_data.run()
Mar  2 19:58:00 wx2013 weewx[31777]: File 
"/home/weewx/bin/weeutil/ftpupload.py", line 183, in run
Mar  2 19:58:00 wx2013 weewx[31777]:   self.saveLastUpload(
timestamp, fileset)
Mar  2 19:58:00 wx2013 weewx[31777]: File 
"/home/weewx/bin/weeutil/ftpupload.py", line 214, in saveLastUpload
Mar  2 19:58:00 wx2013 weewx[31777]:   cPickle.dump(
timestamp, f)
Mar  2 19:58:00 wx2013 weewx[31777]:   TypeError: write() 
argument must be str, not bytes
Mar  2 19:58:00 wx2013 weewx[31777]: 
Mar  2 19:58:00 wx2013 weewx[31777]:   During handling of the 
above exception, another exception occurred:
Mar  2 19:58:00 wx2013 weewx[31777]: 
Mar  2 19:58:00 wx2013 weewx[31777]:   Traceback (most recent 
call last):
Mar  2 19:58:00 wx2013 weewx[31777]: File 
"/home/weewx/bin/weewx/reportengine.py", line 208, in run
Mar  2 19:58:00 wx2013 weewx[31777]:   obj.start()
Mar  2 19:58:00 wx2013 weewx[31777]: File 
"/home/weewx/bin/weewx/reportengine.py", line 304, in start
Mar  2 19:58:00 wx2013 weewx[31777]:   self.run()
Mar  2 19:58:00 wx2013 weewx[31777]: File 
"/home/weewx/bin/weewx/reportengine.py", line 352, in run
Mar  2 19:58:00 wx2013 weewx[31777]:   except (socket.
timeout, socket.gaierror, ftplib.all_errors, IOError) as e:
Mar  2 19:58:00 wx2013 weewx[31777]:   TypeError: catching 
classes that do not inherit from BaseException is not allowed
Mar  2 19:58:00 wx2013 weewx[31777]:   Generator terminated
Mar  2 20:00:15 wx2013 weewx[31777]: manager: Added record 2019-03-02 20:00:
16 CET (1551553216) to database 'cmon.sdb'


sorry but the installation under Python3 and pip3 went smoothly
Soyy my englisch
Hartmut


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-02 Thread Thomas Keffer
Thanks, Hartmut!

I think the problem is that the file that is to be FTP'd, was being opened
in text mode instead of binary. So, it was trying to decode it into Unicode.

Fixed in commit 5167069


Do a pull on the repository, then try again.

-tk

On Sat, Mar 2, 2019 at 9:37 AM Hartmut Schweidler 
wrote:

> Hallo
> my try python3 and weewx
>
> Mar  2 15:20:47 wx2013 weewx[30145]: copygenerator: copied 0 files to
> /home/weewx/public_html/mobile
> Mar  2 15:20:48 wx2013 weewx[30145]: reportengine: Caught unrecoverable
> exception in generator 'weewx.reportengine.FtpGenerator'
> Mar  2 15:20:48 wx2013 weewx[30145]:   catching classes that
> do not inherit from BaseException is not allowed
> Mar  2 15:20:48 wx2013 weewx[30145]:   Traceback (most recent
> call last):
> Mar  2 15:20:48 wx2013 weewx[30145]: File
> "/home/weewx/bin/weewx/reportengine.py", line 351, in run
> Mar  2 15:20:48 wx2013 weewx[30145]:   n = ftp_data.run()
> Mar  2 15:20:48 wx2013 weewx[30145]: File
> "/home/weewx/bin/weeutil/ftpupload.py", line 159, in run
> Mar  2 15:20:48 wx2013 weewx[30145]: 
> ftp_server.storbinary(STOR_cmd, fd)
> Mar  2 15:20:48 wx2013 weewx[30145]: File
> "/usr/lib/python3.5/ftplib.py", line 505, in storbinary
> Mar  2 15:20:48 wx2013 weewx[30145]:   buf =
> fp.read(blocksize)
> Mar  2 15:20:48 wx2013 weewx[30145]: File
> "/usr/lib/python3.5/codecs.py", line 321, in decode
> Mar  2 15:20:48 wx2013 weewx[30145]:   (result, consumed)
> = self._buffer_decode(data, self.errors, final)
> Mar  2 15:20:48 wx2013 weewx[30145]:   UnicodeDecodeError:
> 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
> Mar  2 15:20:48 wx2013 weewx[30145]: 
> Mar  2 15:20:48 wx2013 weewx[30145]:   During handling of the
> above exception, another exception occurred:
> Mar  2 15:20:48 wx2013 weewx[30145]: 
> Mar  2 15:20:48 wx2013 weewx[30145]:   Traceback (most recent
> call last):
> Mar  2 15:20:48 wx2013 weewx[30145]: File
> "/home/weewx/bin/weewx/reportengine.py", line 208, in run
> Mar  2 15:20:48 wx2013 weewx[30145]:   obj.start()
> Mar  2 15:20:48 wx2013 weewx[30145]: File
> "/home/weewx/bin/weewx/reportengine.py", line 304, in start
> Mar  2 15:20:48 wx2013 weewx[30145]:   self.run()
> Mar  2 15:20:48 wx2013 weewx[30145]: File
> "/home/weewx/bin/weewx/reportengine.py", line 352, in run
> Mar  2 15:20:48 wx2013 weewx[30145]:   except
> (socket.timeout, socket.gaierror, ftplib.all_errors, IOError) as e:
> Mar  2 15:20:48 wx2013 weewx[30145]:   TypeError: catching
> classes that do not inherit from BaseException is not allowed
> Mar  2 15:20:48 wx2013 weewx[30145]:   Generator terminated
> Mar  2 15:23:33 wx2013 systemd[1]: Stopping LSB: weewx weather system...
> Mar  2 15:23:33 wx2013 weewx[30145]: engine: Main loop exiting. Shutting
> engine down.
> Mar  2 15:23:33 wx2013 weewx[30145]: engine: Shutting down StdReport thread
> Mar  2 15:23:34 wx2013 weewx[30145]: engine: Terminating weewx version
> 4.0.0a3
> Mar  2 15:23:39 wx2013 weewx[30298]: Stopping weewx weather system: weewx..
> Mar  2 15:23:39 wx2013 systemd[1]: Stopped LSB: weewx weather system.
> Mar  2 15:23:39 wx2013 systemd[1]: Starting LSB: weewx weather system...
> Mar  2 15:23:39 wx2013 weewx[30339]: engine: Initializing weewx version
> 4.0.0a3
> Mar  2 15:23:39 wx2013 weewx[30339]: engine: Using Python 3.5.3 (default,
> Sep 27 2018, 17:25:39) #012[GCC 6.3.0 20170516]
> Mar  2 15:23:39 wx2013 weewx[30339]: engine: Platform
> Linux-4.14.98-v7+-armv7l-with-debian-9.8
> Mar  2 15:23:39 wx2013 weewx[30339]: engine: Locale is 'de_DE.UTF-8'
> Mar  2 15:23:39 wx2013 weewx[30339]: engine: pid file is /var/run/weewx.pid
> Mar  2 15:23:39 wx2013 weewx[30328]: Starting weewx weather system: weewx.
> Mar  2 15:23:39 wx2013 systemd[1]: Started LSB: weewx weather system.
> Mar  2 15:23:39 wx2013 weewx[30343]: engine: Using configuration file
> /home/weewx/weewx.conf
> Mar  2 15:23:39 wx2013 weewx[30343]: engine: Loading station type
> Simulator (weewx.drivers.simulator)
> Mar  2 15:23:39 wx2013 weewx[30343]: snowdepth: using /home/weewx/snow
> Mar  2 15:23:39 wx2013 weewx[30343]: engine: StdConvert target unit is 0x10
> i have python3 running
>
> but uploading via ftp does not work, i have no idea
> for a debugging
>
> Thanks for weewx-python3 and the support
> Hartmut
>


Re: [weewx-development] Re: Python 3 version available for limited testing

2019-03-02 Thread Hartmut Schweidler
Hallo
my try python3 and weewx

Mar  2 15:20:47 wx2013 weewx[30145]: copygenerator: copied 0 files to 
/home/weewx/public_html/mobile
Mar  2 15:20:48 wx2013 weewx[30145]: reportengine: Caught unrecoverable 
exception in generator 'weewx.reportengine.FtpGenerator'
Mar  2 15:20:48 wx2013 weewx[30145]:   catching classes that do 
not inherit from BaseException is not allowed
Mar  2 15:20:48 wx2013 weewx[30145]:   Traceback (most recent 
call last):
Mar  2 15:20:48 wx2013 weewx[30145]: File 
"/home/weewx/bin/weewx/reportengine.py", line 351, in run
Mar  2 15:20:48 wx2013 weewx[30145]:   n = ftp_data.run()
Mar  2 15:20:48 wx2013 weewx[30145]: File 
"/home/weewx/bin/weeutil/ftpupload.py", line 159, in run
Mar  2 15:20:48 wx2013 weewx[30145]:   
ftp_server.storbinary(STOR_cmd, fd)
Mar  2 15:20:48 wx2013 weewx[30145]: File 
"/usr/lib/python3.5/ftplib.py", line 505, in storbinary
Mar  2 15:20:48 wx2013 weewx[30145]:   buf = 
fp.read(blocksize)
Mar  2 15:20:48 wx2013 weewx[30145]: File 
"/usr/lib/python3.5/codecs.py", line 321, in decode
Mar  2 15:20:48 wx2013 weewx[30145]:   (result, consumed) = 
self._buffer_decode(data, self.errors, final)
Mar  2 15:20:48 wx2013 weewx[30145]:   UnicodeDecodeError: 
'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
Mar  2 15:20:48 wx2013 weewx[30145]: 
Mar  2 15:20:48 wx2013 weewx[30145]:   During handling of the 
above exception, another exception occurred:
Mar  2 15:20:48 wx2013 weewx[30145]: 
Mar  2 15:20:48 wx2013 weewx[30145]:   Traceback (most recent 
call last):
Mar  2 15:20:48 wx2013 weewx[30145]: File 
"/home/weewx/bin/weewx/reportengine.py", line 208, in run
Mar  2 15:20:48 wx2013 weewx[30145]:   obj.start()
Mar  2 15:20:48 wx2013 weewx[30145]: File 
"/home/weewx/bin/weewx/reportengine.py", line 304, in start
Mar  2 15:20:48 wx2013 weewx[30145]:   self.run()
Mar  2 15:20:48 wx2013 weewx[30145]: File 
"/home/weewx/bin/weewx/reportengine.py", line 352, in run
Mar  2 15:20:48 wx2013 weewx[30145]:   except 
(socket.timeout, socket.gaierror, ftplib.all_errors, IOError) as e:
Mar  2 15:20:48 wx2013 weewx[30145]:   TypeError: catching 
classes that do not inherit from BaseException is not allowed
Mar  2 15:20:48 wx2013 weewx[30145]:   Generator terminated
Mar  2 15:23:33 wx2013 systemd[1]: Stopping LSB: weewx weather system...
Mar  2 15:23:33 wx2013 weewx[30145]: engine: Main loop exiting. Shutting 
engine down.
Mar  2 15:23:33 wx2013 weewx[30145]: engine: Shutting down StdReport thread
Mar  2 15:23:34 wx2013 weewx[30145]: engine: Terminating weewx version 
4.0.0a3
Mar  2 15:23:39 wx2013 weewx[30298]: Stopping weewx weather system: weewx..
Mar  2 15:23:39 wx2013 systemd[1]: Stopped LSB: weewx weather system.
Mar  2 15:23:39 wx2013 systemd[1]: Starting LSB: weewx weather system...
Mar  2 15:23:39 wx2013 weewx[30339]: engine: Initializing weewx version 
4.0.0a3
Mar  2 15:23:39 wx2013 weewx[30339]: engine: Using Python 3.5.3 (default, 
Sep 27 2018, 17:25:39) #012[GCC 6.3.0 20170516]
Mar  2 15:23:39 wx2013 weewx[30339]: engine: Platform 
Linux-4.14.98-v7+-armv7l-with-debian-9.8
Mar  2 15:23:39 wx2013 weewx[30339]: engine: Locale is 'de_DE.UTF-8'
Mar  2 15:23:39 wx2013 weewx[30339]: engine: pid file is /var/run/weewx.pid
Mar  2 15:23:39 wx2013 weewx[30328]: Starting weewx weather system: weewx.
Mar  2 15:23:39 wx2013 systemd[1]: Started LSB: weewx weather system.
Mar  2 15:23:39 wx2013 weewx[30343]: engine: Using configuration file 
/home/weewx/weewx.conf
Mar  2 15:23:39 wx2013 weewx[30343]: engine: Loading station type Simulator 
(weewx.drivers.simulator)
Mar  2 15:23:39 wx2013 weewx[30343]: snowdepth: using /home/weewx/snow
Mar  2 15:23:39 wx2013 weewx[30343]: engine: StdConvert target unit is 0x10
i have python3 running

but uploading via ftp does not work, i have no idea 
for a debugging

Thanks for weewx-python3 and the support
Hartmut