Custom Reports

58 views
Skip to first unread message

Mike Revitt

unread,
Feb 12, 2020, 2:27:59 AM2/12/20
to weewx-user
I have just finished writing a utility to copy files to an S3 bucket, which I based on ftpupload.py in the weevil directory.

This is now working perfectly when I call it with hard coded values, but when I add the code at the bottom to get the variables from weewx.conf I get the following error

$ python3 s3upload.py /Users/Mike/WebSites/Weewx/new
Traceback (most recent call last):
 File "s3upload.py", line 145, in <module>
   import weewx
ModuleNotFoundError: No module named 'weewx' .


The code I have used is based on the code in the ftpupload file 

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

    if len(sys.argv) == 2:
        try:
            S3_dir = os.path.join(config_dict['WEEWX_ROOT'], config_dict['StdReport']['HTML_ROOT'])
        except KeyError:
            print("No HTML_ROOT in configuration dictionary.")
            sys.exit(1)
    else:
        S3_dir = sys.argv[2]

    S3_upload = S3Upload(config_dict['StdReport']['AWSCLI']['S3_BUCKET'],
                         config_dict['StdReport']['AWSCLI']['AWS_Profile'],
                         S3_dir,
                         config_dict['StdReport']['AWSCLI']['S3_ROOT'],
                         'S3')
                         
    S3_upload.run()



Any ideas


gjr80

unread,
Feb 12, 2020, 3:20:22 AM2/12/20
to weewx-user
Most likely a PYTHON_PATH issue (basically python has no idea where to find the WeeWX modules. Try something like:

$ PYTHON_PATH=/home/weewx/bin python3 s3upload.py /Users/Mike/WebSites/Weewx/new

or

$ PYTHON_PATH=/usr/share/weewx python3 s3upload.py /Users/Mike/WebSites/Weewx/new

depending on whether you did a setup.py or package WeeWX install.

Gary

gjr80

unread,
Feb 12, 2020, 3:32:18 PM2/12/20
to weewx-user
Sorry, don’t know where I was when I replied but it’s PYTHONPATH not PYTHON_PATH.

Gary

Mike Revitt

unread,
Feb 12, 2020, 5:40:17 PM2/12/20
to weewx-user
That worked perfectly, can now call it from the command line and it works exactly as I need.

The next challenge is on my other thread but looks like I have an answer there as well.

All going well I should have an S3 interface running within the next couples of weeks as a standalone add on.

Happy to share once it is working
Reply all
Reply to author
Forward
0 new messages