1. replace -max line length with -10 or whatever your max line length
actually is ie set the amount to go back from the end of the file
2. replace f.readline()[-1] with f.readlines()[-1]
3. google for 'python read last line of text file' and there are several
possible solutions similar to this one!!
On Monday, 9 April 2018 01:41:55 UTC+3, vigilancewx wrote:
> Thanks for your input Andrew
>
> your additional comments have removed the indentation errors but for some
> reason weewx.sbd has stopped being populated by pond.py and the modified
> lines
>
> but again thanks
>
>
>
> 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.