Beispiel #1
0
def bootstrap(job):
    """
    Get us off and running!
    """
    cursor.execute("""SELECT * from webcams where id = %s""", (job.site,))
    row = cursor.fetchone()
    if row['scrape_url'] is None:
        job.camera = common.get_vbcam(row["id"])

        if job.camera.settings == {}:
            logging.info("Failed to reach camera, aborting...")
            sys.exit(0)
    else:
        job.camera = lapse.scrape(job.site, row)

    cursor.close()
    dbconn.close()

    # Initially sleep until it is go time!
    logging.debug("Initial sleep of: %s", job.init_delay)
    time.sleep(job.init_delay + random.random())

    # compute
    sts = datetime.datetime.now()
    job.ets = sts + datetime.timedelta(seconds=job.secs)
Beispiel #2
0
def camRunner(cid):
    # Who am I running for
    cursor.execute("""SELECT * from webcams where id = %s """, (cid,))
    row = cursor.fetchone()
    now = datetime.datetime.now()
    now = now.replace(tzinfo=pytz.timezone("America/Chicago"))
    gmt = datetime.datetime.utcnow()
    if row['scrape_url'] is None:
        cam = common.get_vbcam(cid)
        cam.retries = 2

        # Get Still
        buf = StringIO.StringIO()
        buf.write(cam.getOneShot())
        buf.seek(0)

    else:
        url = row['scrape_url']
        req = urllib2.Request(url)
        try:
            req2 = urllib2.urlopen(req)
        except Exception, exp:
            if now.minute == 0:
                print 'Exception for %s: %s' % (cid, exp)
            return
        modified = req2.info().getheader('Last-Modified')
        if modified:
            gmt = datetime.datetime.strptime(modified,
                                             "%a, %d %b %Y %H:%M:%S %Z")
            now = gmt + datetime.timedelta(seconds=now.utcoffset().seconds)
            # Round up to nearest 5 minute bin
            roundup = 5 - now.minute % 5
            gmt += datetime.timedelta(minutes=roundup)
        buf = StringIO.StringIO(req2.read())
        buf.seek(0)
""" Sync four webcams in time generating a timelapse """
import common

from PIL import Image, ImageDraw, ImageFont
import mx.DateTime
import sys
import time
import os
import logging

os.chdir("../tmp")

cams = []
for camid in sys.argv[1:5]:
    print 'Adding %s webcam' % (camid,)
    cams.append(common.get_vbcam(camid))

x = [0, 320, 0, 320]
y = [0, 0, 240, 240]

fontsize = 22
font = ImageFont.truetype('../lib/veramono.ttf', fontsize)

mydir = "iemsync.%s" % (mx.DateTime.now().strftime("%Y%m%d%H%M%S"),)
os.makedirs(mydir)
os.chdir(mydir)

logging.basicConfig(filename="iemsync.log", filemode='w')


for i in range(100000):
Beispiel #4
0
from PIL import ImageDraw
import psycopg2.extras
import common
import logging
logging.basicConfig(level=logging.DEBUG)

mesosite = common.get_dbconn()
cursor = mesosite.cursor(cursor_factory=psycopg2.extras.DictCursor)

os.chdir("../tmp")


# Which webcam, establish existing lat/lon and pan0
cid = sys.argv[1]

camera = common.get_vbcam(cid, loglevel=logging.DEBUG)
clat = camera.d['lat']
clon = camera.d['lon']
newpan0 = camera.d['pan0'] + int(sys.argv[2])
if newpan0 < 0:
    newpan0 += 360.
logging.info('Webcam %s initial pan0: %s attempting: %s' % (cid, 
                                                camera.d['pan0'], newpan0 ))
logging.info("\n  UPDATE webcams SET pan0 = %s WHERE id = '%s'; \n" % (
                                                            newpan0, cid))
camera.pan0 = newpan0

# Figure out solar location
sun = ephem.Sun()
here = ephem.Observer()
here.long, here.lat = str(clon), str(clat)
Beispiel #5
0
fontsize = 18
font = ImageFont.truetype('../lib/veramono.ttf', fontsize)

os.chdir("../tmp/")

site = sys.argv[1]

mydir = "longterm.%s.%s" % (site, mx.DateTime.now().strftime("%Y%m%d%H%M%S"))
os.makedirs(mydir)
os.chdir(mydir)

logging.basicConfig(filename="%s.log" % (site,), filemode='w',
                    level=logging.INFO)
logger = logging.getLogger()

c = common.get_vbcam(site)
logger.info("Camera Settings: %s" % (c.settings, ))


def do(i):
    logging.debug("i = %s" % (i,))

    # Set up buffer for image to go to
    buf = StringIO.StringIO()

    drct = c.getDirection()
    buf.write(c.getOneShot())
    buf.seek(0)
    i0 = Image.open(buf)

    now = mx.DateTime.now()
Beispiel #6
0
"""Simple utility to print out the camera settings"""
import common
import sys
import logging
logging.basicConfig(level=logging.DEBUG)

cid = sys.argv[1]
cam = common.get_vbcam(cid)
keys = cam.settings.keys()
keys.sort()

for k in keys:
    print "[%s] %s" % (k, cam.settings[k])
Beispiel #7
0
""" Create a panoramic image for a given site """
import common
import os
from PIL import Image, ImageDraw
import sys
import time

os.chdir("../tmp")

# Which webcam, establish existing lat/lon and pan0
cid = sys.argv[1]
camera = common.get_vbcam(cid)
camera.zoom(40.0)
camera.tilt(0.0)
out = Image.new('RGB', (720, 480))

i = 0
for ang in range(-160, 180, 40):
    print "Working on Angle: %s" % (ang,)
    camera.pan(ang)
    time.sleep(2)  # Settle down the cam
    o = open("tmp.jpg", 'w')
    o.write(camera.getStillImage())
    o.close()

    i0 = Image.open("tmp.jpg")
    i02 = i0.resize((144, 240))
    draw = ImageDraw.Draw(i02)
    draw.rectangle([0, 119, 144, 121], fill="#000000")

    row = int(i/5)