indentation is significant in python
try:
def read_file(self, event):
try:
with open(self.filename) as f:
# value = f.read()
# line = f.readline()
f.seek(-max_line_length, os.SEEK_END)
line = f.readline()[-1]
value = line.split(',')
syslog.syslog(syslog.LOG_DEBUG, "pond: found value of %s" %
value)
event.record['ccwatt'] = float(value[0])
On Sunday, 8 April 2018 15:35:59 UTC+3, vigilancewx wrote:
> Thank you for your reply Andrew
>
> i assume its my error on how i have tried to make the changes to pond py
> now its is generating this error
>
> Apr 8 13:23:37 pi-X2 OWFS[21349]: ****
> self.loadServices(config_dict)
> Apr 8 13:23:37 pi-X2 OWFS[21349]: **** File
> "/home/weewx/bin/weewx/engine.py", line 141, in loadServices
> Apr 8 13:23:37 pi-X2 OWFS[21349]: ****
> self.service_obj.append(weeutil.weeutil._get_object(svc)(self, config_dict))
> Apr 8 13:23:37 pi-X2 OWFS[21349]: **** File
> "/home/weewx/bin/weeutil/weeutil.py", line 1132, in _get_object
> Apr 8 13:23:37 pi-X2 OWFS[21349]: **** mod = __import__(module)
> Apr 8 13:23:37 pi-X2 OWFS[21349]: **** File
> "/home/weewx/bin/user/pond.py", line 24
> Apr 8 13:23:37 pi-X2 OWFS[21349]: **** value = line.split(',')
> Apr 8 13:23:37 pi-X2 OWFS[21349]: **** ^
> Apr 8 13:23:37 pi-X2 OWFS[21349]: **** IndentationError: unindent
> does not match any outer indentation level
> Apr 8 13:23:37 pi-X2 OWFS[21349]: **** Exiting.
>
>
> I have tried to alter pond.py as follows obviously incorrectly could you
> define were please
>
> thanks
>
> import syslog
> import weewx
> from weewx.wxengine import StdService
>
> class PondService(StdService):
> def __init__(self, engine, config_dict):
> super(PondService, self).__init__(engine, config_dict)
> d = config_dict.get('PondService', {})
> self.filename = d.get('filename', '/var/www/html/data/reading.txt')
> syslog.syslog(syslog.LOG_INFO, "pond: using %s" % self.filename)
> self.bind(weewx.NEW_ARCHIVE_RECORD, self.read_file)
>
> def read_file(self, event):
> try:
> with open(self.filename) as f:
> #value = f.read()
> ####### line = f.readline()
>
> f.seek(-max_line_length, os.SEEK_END)
> line = f.readline()[-1]
>
> value = line.split(',')
> syslog.syslog(syslog.LOG_DEBUG, "pond: found value of %s" %
> value)
> event.record['ccwatt'] = float(value[0])
> event.record['cctemp'] = float(value[1])
> except Exception, e:
> syslog.syslog(syslog.LOG_ERR, "pond: cannot read value: %s" %
> e)
>
>
>
>
>
>
>
> On Saturday, April 7, 2018 at 9:51:39 PM UTC+1, vigilancewx wrote:
>>
>> Hello
>>
>>
>> I have a current cost electricity meter connect to a linux computer via a
>> usb cable
>>
>> On the linux computer is a script that every 20seconds loggs the watt and
>> temp readings from the current cost meter to a txt file and RRD file
>>
>>
>> I can generate the RRD graphs into the weewx public_html directory and
>> display them accrodingly
>>
>>
>> I know that weewx is predominatly for displaying weather data but I would
>> like weewx to handle the watt data, so I have tried to save the readings
>> into the weewx.sdb
>>
>>
>> I found this version of pond.py from the weewx user groups and it works
>> with no errors
>>
>>
>>
>> Following advice given in the weewx help files I can now display the data
>> in the various html files display graphs etc
>>
>>
>> I have one problem, pond.py takes the readings from the first line in the
>> txt file (readings.txt)
>>
>>
>> how do I modify pond.py to take its readings from the last line of the
>> txt file, because file the last line of my txt file holds the latest data
>>
>>
>> thank you for any help
>>
>>
>> import syslog
>>
>> import weewx
>>
>> from weewx.wxengine import StdService
>>
>>
>> class PondService(StdService):
>>
>> def __init__(self, engine, config_dict):
>>
>> super(PondService, self).__init__(engine, config_dict)
>>
>> d = config_dict.get('PondService', {})
>>
>> self.filename = d.get('filename', '/var/www/html/data/reading.txt')
>>
>> syslog.syslog(syslog.LOG_INFO, "pond: using %s" % self.filename)
>>
>> self.bind(weewx.NEW_ARCHIVE_RECORD, self.read_file)
>>
>>
>> def read_file(self, event):
>>
>> try:
>>
>> with open(self.filename) as f:
>>
>> #value = f.read()
>>
>> line = f.readline()
>>
>> value = line.split(',')
>>
>> syslog.syslog(syslog.LOG_DEBUG, "pond: found value of %s" % value)
>>
>> event.record['ccwatt'] = float(value[0])
>>
>> event.record['cctemp'] = float(value[1])
>>
>> except Exception, e:
>>
>> syslog.syslog(syslog.LOG_ERR, "pond: cannot read value: %s" % e)
>>
>
--
You received this message because you are subscribed to the Google Groups
"weewx-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.