# =============================================================================
# Class AWS_Sync# =============================================================================
class AWS_Sync(ReportGenerator): """Class for managing the "AWS generator".
This will copy everything in the public_html subdirectory to a webserver."""
def run(self): import weeutil.s3upload
# determine how much logging is desired log_success = to_bool(search_up(self.skin_dict, 'log_success', True))
t1 = time.time() try: local_root = os.path.join(self.config_dict['WEEWX_ROOT'], self.skin_dict.get('HTML_ROOT', self.config_dict['StdReport']['HTML_ROOT'])) s3_data = weeutil.s3upload.S3Upload( bucket=self.skin_dict['bucket'], profile=self.skin_dict['profile'], local_root=local_root, remote_root=self.skin_dict['S3_ROOT'], name=self.skin_dict['REPORT_NAME'], debug=int(self.skin_dict.get('debug', 0)), secure_data=to_bool(self.skin_dict.get('secure_data', True))) except KeyError: syslog.syslog(syslog.LOG_DEBUG, "AWS_Sync: AWS upload not requested. Skipped.") return
try: n = s3_data.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, "AWS_Sync: " "Caught exception %s: %s" % (cl, e)) weeutil.weeutil.log_traceback(" **** ") return
if log_success: t2 = time.time() syslog.syslog(syslog.LOG_INFO, "AWS_Sync: awscli S3'd %d files in %0.2f seconds" % (n, (t2 - t1)))
Thoughts
[Generators]
generator_list = weeutil.s3upload.S3Upload
------
where
weeutil is the directory
s3upload is the py file
S3Upload is the class within the py file
---
Already have a section in the main conf file that I have just tested via my other thread on this subject
Maybe you can try it, or use it for ideas. Have fun!
Paul
That makes sense, I have created a skin with its own weewx.conf already, was struggling to work out how to call the generator in its own file
Do I then call it from the S3 conf file like this[Generators]
generator_list = weeutil.s3upload.S3Upload
[Generators]
generator_list = user.s3upload.AWS_Sync def run(self):
import weeutil.s3upload
# determine how much logging is desired
log_success = to_bool(search_up(self.skin_dict, 'log_success', True))
t1 = time.time()
try:
local_root = os.path.join(self.config_dict['WEEWX_ROOT'],
self.skin_dict.get('HTML_ROOT', self.config_dict['StdReport']['HTML_ROOT']))
s3_data = weeutil.s3upload.S3Upload( 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:
local_root = os.path.join(self.config_dict['WEEWX_ROOT'],
self.skin_dict.get('HTML_ROOT', self.config_dict['StdReport']['HTML_ROOT']))
s3_data = user.s3upload.S3Upload(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'
[Generators] generator_list = user.s3upload.S3Upload
import loggingimport osimport sysimport timeimport boto3
from weewx.reportengine import ReportGeneratorfrom 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)))
# =============================================================================# 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()
[[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
[Generators]
generator_list = user.s3upload.S3UploadGenerator