Thanks for all your help Gary,
That did the trick, Just fixed all off the error handling today, now that I
have it running, and am ready to package it up and put my new website live.
What is the process for adding a plugin to weewx?
Mike
On Sunday, February 16, 2020 at 8:02:05 AM UTC, gjr80 wrote:
>
> Mike,
>
> The generator_list setting should contain one or more references to
> generator classes to be used, ie classes that are based on class
> ReportGenerator. Given your code that would be S3UploadGenerator, so
> something like:
>
> [Generators]
>
> generator_list = user.s3upload.S3UploadGenerator
>
> should do the trick.
>
> Gary
>
> On Sunday, 16 February 2020 00:29:13 UTC+10, Mike Revitt wrote:
>>
>> You have been super helpful so far Gary, so bear with me, I am almost
>> there.
>>
>> My program is now called S3UploadGenerator and is in the bin/user
>> directory. I have also successfully installed weewx 4.0 on my raspberry
>> pi using python3, which is also now the default
>>
>> Calling it from the command line now works perfectly and I also
>> successfully call it when running weewxd
>>
>> But: 1 error remains when s3upload.py is called:
>>
>> Traceback (most recent call last):
>> File "/home/weewx/bin/weewx/reportengine.py", line 202, in run
>> obj.start()
>> AttributeError: 'S3Upload' object has no attribute 'start'
>> Exception in thread ReportThread:
>> Traceback (most recent call last):
>> File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
>> self.run()
>> File "/home/weewx/bin/weewx/reportengine.py", line 215, in run
>> obj.finalize()
>> AttributeError: 'S3Upload' object has no attribute 'finalize'
>>
>>
>> I have searched the manuals and looked at all of the existing code and
>> can't work out what to do to resolve this.
>>
>> my S3/skin.conf contains the following:
>>
>> [Generators]
>> generator_list = user.s3upload.S3Upload
>>
>>
>> This is the relevant part of s3upload.py
>> import logging
>> import os
>> import sys
>> import time
>> import boto3
>>
>> from weewx.reportengine import ReportGenerator
>> from six.moves import cPickle
>>
>> log = logging.getLogger(__name__)
>>
>> #
>> =============================================================================
>> # Class S3UploadGenerator
>> #
>> =============================================================================
>> class S3UploadGenerator(ReportGenerator):
>>
>> """Class for managing the "AWS generator".
>>
>> This will copy everything in the public_html subdirectory to a
>> webserver."""
>>
>> def run(self):
>> import user.s3upload
>>
>> # determine how much logging is desired
>> log_success = to_bool(search_up(self.skin_dict, 'log_success',
>> True))
>>
>> t1 = time.time()
>> try:
>> S3_upload =
>> user.s3upload.S3Upload(bucket=self.skin_dict['S3_BUCKET'],
>>
>> profile=self.skin_dict['AWS_Profile'],
>>
>> html_root=self.config_dict['StdReport']['HTML_ROOT'],
>>
>> remote_root=self.skin_dict['S3_ROOT'],
>>
>> name=self.skin_dict['REPORT_NAME'])
>> except KeyError:
>> syslog.syslog(syslog.LOG_DEBUG,
>> "S3UploadGenerator: AWS upload not requested.
>> Skipped.")
>> return
>>
>> try:
>> n = S3_upload.run()
>> except (socket.timeout, socket.gaierror, ftplib.all_errors,
>> IOError) as e:
>> (cl, unused_ob, unused_tr) = sys.exc_info()
>> syslog.syslog(syslog.LOG_ERR, "S3UploadGenerator: "
>> "Caught exception %s: %s" %
>> (cl, e))
>> weeutil.weeutil.log_traceback(" **** ")
>> return
>>
>> if log_success:
>> t2 = time.time()
>> syslog.syslog(syslog.LOG_INFO,
>> "S3UploadGenerator: AWS-S3 S3'd %d files in
>> %0.2f seconds" %
>> (n, (t2 - t1)))
>>
>>
>>
>> And this is the main, which works from the command line
>> #
>> =============================================================================
>> # Main
>> #
>> =============================================================================
>> if __name__ == '__main__':
>> import configobj
>>
>> import weewx
>> import weeutil.logger
>>
>> weewx.debug = 1
>>
>> weeutil.logger.setup('S3upload', {})
>>
>> if len(sys.argv) < 2:
>> print("""Usage: s3upload.py path-to-configuration-file
>> [path-to-be-ftp'd]""")
>> sys.exit(weewx.CMD_ERROR)
>>
>> try:
>> config_dict = configobj.ConfigObj(sys.argv[1], file_error=True,
>> encoding='utf-8')
>> except IOError:
>> print("Unable to open configuration file %s" % sys.argv[1])
>> raise
>>
>> S3_upload = S3Upload(config_dict['StdReport']['AWS-S3']['S3_BUCKET'],
>>
>> config_dict['StdReport']['AWS-S3']['AWS_Profile'],
>> config_dict['StdReport']['HTML_ROOT'],
>> config_dict['StdReport']['AWS-S3']['S3_ROOT'],
>> 'S3')
>>
>> print(config_dict['StdReport']['AWS-S3']['S3_BUCKET'],
>> config_dict['StdReport']['AWS-S3']['AWS_Profile'],
>> config_dict['WEEWX_ROOT'],
>> config_dict['StdReport']['AWS-S3']['S3_ROOT'],
>> 'S3')
>> S3_upload.run()
>>
>>
>> And this is the relevant section of weewx.conf
>> [[AWS-S3]]
>> # Using AWSCLI to copy the results to a webserver is treated as
>> just
>> # another report, albeit one with an unusual report generator!
>> skin = S3
>> enable = true
>>
>> # You must configure AWS at the command line and create some
>> logon credentials
>> # in the credentials file. This is the name of the profile
>> defined in that
>> # file that you wish to use for the copy
>> AWS_Profile = mike
>>
>> # This is the name of the S3 bucket where the files will be copied
>> S3_BUCKET = s3-archive.revittmk.aws.co.uk
>>
>> # This is the folder into which the files will be copied within
>> the S3 bucket,
>> S3_ROOT = /MountWeather
>>
>>
>>
>>
>>
--
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].
To view this discussion on the web visit
https://groups.google.com/d/msgid/weewx-user/92deda85-76e3-40c6-a9c4-60a57487c1a2%40googlegroups.com.