and, here is the original skin configuration file with urls, ports, and
passwords redacted:
############################################################################################
#
#
#
#
# Snapshots SKIN CONFIGURATION
FILE #
#
#
#
#
############################################################################################
#
#
# Copyright (c) 2010 Joe Percival
#
#
#
# See the file LICENSE.txt for your full
rights. #
#
#
############################################################################################
#
# $Revision: 1 $
# $Author: jpercival $
# $Date: 2011-01-15 $
#
############################################################################################
HTML_ROOT=public_html/snapshots
[Extras]
cam_lable_font_path =
/usr/share/fonts/truetype/freefont/FreeMonoBold.ttf
ptz_cam_lable_font_size = 25
fixed_cam_lable_font_size = 12
[[ptzcams]]
[[[ptzcamA]]]
preseturl=preseturl to access first camera presets
imgurl = url to access first camera images
[[[[presets]]]]
[[[[[ps1]]]]]
number = 2
caption = Snow Pole
snap = 1
[[[[[ps2]]]]]
number = 3
caption = Snow Pole Wide
snap = 1
[[[[[ps3]]]]]
number = 4
caption = Kenshaw
snap = 1
[[[[[ps4]]]]]
number = 5
caption = Driveway
snap = 1
[[[[[ps5]]]]]
number = 6
caption = Weather Station
snap = 1
[[[ptzcamB]]]
preseturl=url to access 2nd camera presets
imgurl = url to access 2nd camera images
[[[[presets]]]]
[[[[[ps1]]]]]
number = 1
caption = Driveway to Street Wide
snap = 1
[[[[[ps2]]]]]
number = 2
caption = Driveway to Street Closer
snap = 1
[[[[[ps3]]]]]
number = 3
caption = Driveway to Street Close
snap = 1
[[[[[ps4]]]]]
number = 4
caption = Lot Next Door
snap = 1
[[[[[ps5]]]]]
number = 5
caption = Back Yard
snap = 1
[[[[[ps6]]]]]
number = 6
caption = Side Yard
snap = 1
[[fixedcams]]
chanurl=another camera url
imgurl = another camera image url
[[[cameras]]]
# [[[[cam1]]]]
# port = 0
# [[[[cam2]]]]
# port = 1
# [[[[cam3]]]]
# port = 2
############################################################################################
#
# The list of generators that are to be run:
#
[Generators]
generator_list = weewx.cameragenerator.CameraGenerator
#weewx.filegenerator.FileGenerator,
weewx.imagegenerator.ImageGenerator, weewx.reportengine.CopyGenerator
On Saturday, September 23, 2017 at 10:08:53 AM UTC-7, Joe Percival wrote:
>
> and here is the complete listing of the custom generator code:
>
> # -*- coding: utf-8 -*-
> import Image, ImageFont, ImageDraw, urllib, urllib2, time
> import os, weewx.reportengine
>
> #===============================================================================
> # Class ImageGenerator
>
> #===============================================================================
>
> class CameraGenerator(weewx.reportengine.ReportGenerator):
> """Class for managing the cam image generator."""
>
> def run(self):
> # localpath =
> os.path.join(self.config_dict['Station']['WEEWX_ROOT'],self.skin_dict['HTML_ROOT'])
> fontpath = self.skin_dict['Extras']['cam_lable_font_path']
> ptzfontsize =
> int(self.skin_dict['Extras']['ptz_cam_lable_font_size'])
> for ptzcam in self.skin_dict['Extras']['ptzcams'].keys():
> localpath =
> os.path.join(self.config_dict['Station']['WEEWX_ROOT'],self.skin_dict['HTML_ROOT'],ptzcam)
> camdef = self.skin_dict['Extras']['ptzcams'][ptzcam]
> preseturl=camdef['preseturl']
> imgurl = camdef['imgurl']
> for preset in camdef['presets'].keys():
> psdef = camdef['presets'][preset]
> psNum = int(psdef['number']) # API says add 256 to the
> preset number for the url
> urlNum = psNum + 256
> psCaption = psdef['caption']
> psSnap = int(psdef['snap'])
> moveurl = preseturl+str(urlNum) #the complete move to
> preset url
> tries = 0
> moved = False
> while tries < 3:
> tries += 1
> try:
> mov = urllib.urlopen(moveurl) #tell the camera to
> move to the preset location
> if mov.read().find('OK')>-1:
> moved = True
> mov.close() #close the link
> break
> except:
> print "Unexpected error moving camera:"
> time.sleep(5.0)
> if not moved:
> mov.close() #close the link
> continue
> time.sleep(17.0) #wait for a few seconds for the camera to
> move
> if psSnap==1: #if a snapshot is called for on the
> preset
> tries = 0
> while tries < 3:
> local = open(localpath+str(psNum) + '.jpg','wb')
> #open a file for the image
> tries += 1
> try:
> local.write(urllib.urlopen(imgurl).read())
> #download the snapshot image into the file
> local.close()
> except:
> local.close()
> os.remove(localpath+str(psNum) + '.jpg')
> time.sleep(5.0)
> continue
> if os.path.getsize(localpath+str(psNum) +
> '.jpg')>0:
> try:
> outImage =
> Image.open(localpath+str(psNum)+'.jpg')
> draw = ImageDraw.Draw(outImage)
>
> font=ImageFont.truetype(fontpath,ptzfontsize)
> timestr = time.strftime('%a, %m/%d/%y at
> %I:%M %p %Z',time.localtime(time.time()))
> draw.rectangle([0,0,1280,30],(0,0,0,10))
> draw.text((5,5),psCaption +' updated on
> '+timestr,font=font)
> outImage.save(localpath+str(psNum)+'.jpg')
> break
> except:
> print 'error with camera image and PIL'
> os.remove(localpath+str(psNum) + '.jpg')
> time.sleep(5.0)
> continue
> else:
> if tries == 3:
> os.remove(localpath+str(psNum) + '.jpg')
> break
> time.sleep(5.0)
>
>
> chanurl = self.skin_dict['Extras']['fixedcams']['chanurl']
> imgurl = self.skin_dict['Extras']['fixedcams']['imgurl']
> localpath =
> os.path.join(self.config_dict['Station']['WEEWX_ROOT'],self.skin_dict['HTML_ROOT'],'cam')
> for fixedcam in
> self.skin_dict['Extras']['fixedcams']['cameras'].keys():
> camdef =
> self.skin_dict['Extras']['fixedcams']['cameras'][fixedcam]
> port=int(camdef['port'])
> urlchan = chanurl+str(port)
> tries = 0
> while tries <= 3:
> tries += 1
> try:
> chan = urllib.urlopen(urlchan)
> break
> except IOError as (errno, strerror):
> print "I/O error({0}): {1}".format(errno, strerror)
> except ValueError:
> print "Could not convert data to an integer."
> except:
> print "Unexpected error:", sys.exc_info()[0]
> raise
> chan.close()
> time.sleep(1.0)
> local = open(localpath+str(port+1)+'.jpg','wb')
> tries=0
> while tries <= 3:
> tries += 1
> try:
> local.write(urllib.urlopen(imgurl).read())
> break
> except IOError as (errno, strerror):
> print "I/O error({0}): {1}".format(errno, strerror)
> except ValueError:
> print "Could not convert data to an integer."
> except:
> print "Unexpected error:", sys.exc_info()[0]
> raise
> local.close()
> outImage = Image.open(localpath+str(port+1)+'.jpg')
> draw = ImageDraw.Draw(outImage)
> font=ImageFont.truetype(fontpath,15)
> timestr = time.strftime('%a, %m/%d/%y at %I:%M %p
> %Z',time.localtime(time.time()))
> draw.rectangle([0,0,640,20],(0,0,0,10))
> draw.text((5,5),"Cam " + str(port+1)+' updated on
> '+timestr,font=font)
> outImage.save(localpath+str(port+1)+'.jpg')
>
>
>
> On Saturday, September 23, 2017 at 10:04:46 AM UTC-7, Joe Percival wrote:
>>
>> First, an explanation...
>> I'm adding a report that downloads images from webcams, manipulates them,
>> and copies them to a local file. An FTP report then sends them to a
>> specific location on my remote web server.
>> The skin for this custom report includes a configuration file but does
>> not use a template file. The skin configuration file contains a set of
>> parameters used by the custom generator to find, manipulate, and store the
>> images locally.
>> The custom generator is a highly modified (like completely) version of
>> the original ImageGenerator.
>>
>> Here is what I have now and what I understand needs to change...
>>
>> In the old weewx.conf:
>> [Reports]
>> [[CameraSnapshots]]
>> skin=snapshots
>>
>> In the new weewx.conf:
>> [StdReport]
>> [[CameraSnapshots]]
>> skin=snapshots
>>
>> In the old skins/snapshots/skin.conf:
>> <snipped out all sorts of parameter goodies used by the generator to find
>> and manipulate images>
>> [Generators]
>> generator_list = weewx.cameragenerator.CameraGenerator
>> #weewx.filegenerator.FileGenerator,
>> weewx.imagegenerator.ImageGenerator, weewx.reportengine.CopyGenerator
>>
>> In the new skins/snapshots/skin.conf:
>> <snipped out all the same parameter goodies which will probably not need
>> to change... we'll see>
>> [Generators]
>> generator_list = user.cameragenerator.CameraGenerator
>> #weewx.filegenerator.FileGenerator,
>> weewx.imagegenerator.ImageGenerator, weewx.reportengine.CopyGenerator
>>
>> in the old bin/weewx/cameragenerator.py:
>> import Image, ImageFont, ImageDraw, urllib, urllib2, time
>> import os, weewx.reportengine
>>
>> #===============================================================================
>> # Class CameraGenerator
>>
>> #===============================================================================
>>
>> class CameraGenerator(weewx.reportengine.ReportGenerator):
>> """Class for managing the cam image generator."""
>>
>> In the new user/cameragenerator.py:
>> import Image, ImageFont, ImageDraw, urllib, urllib2, time
>> import os, weewx.reportengine
>>
>> #===============================================================================
>> # Class CameraGenerator
>>
>> #===============================================================================
>>
>> class CameraGenerator(weewx.reportengine.ReportGenerator):
>> """Class for managing the cam image generator."""
>>
>> Is that the right place to start?
>> Thanks,
>> joe
>>
>> On Friday, September 22, 2017 at 5:31:18 PM UTC-7, Tom Keffer wrote:
>>>
>>> It should go in bin/user.
>>>
>>> -tk
>>>
>>> On Fri, Sep 22, 2017 at 5:26 PM, Joe Percival <[email protected]>
>>> wrote:
>>>
>>>> Actually the most important first question I have is regarding the
>>>> custom generator location.... bin/weewx or do I need to move it to
>>>> bin/user?
>>>>
>>>> --
>>>> 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.
>>>>
>>>
>>>
--
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.