Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import beanstalkc
- import time
- import json
- import MySQLdb
- db = MySQLdb.connect("localhost", "root", "YOUR_MySQL_PASSWORD","alprdb")
- beanstalk = beanstalkc.Connection(host='localhost', port=11300)
- cur = db.cursor()
- beanstalk.watch('alprd')
- while True:
- job = beanstalk.reserve(timeout=0)
- if job is not None:
- decoded= json.loads(job.body)
- _plate = decoded['results'][0]['plate']
- _uuid = decoded['uuid']
- epoch = decoded['epoch_time']
- _date = time.strftime('%Y-%m-%d',time.localtime(epoch/1000))
- _time = time.strftime('%H:%M:%S',time.localtime(epoch/1000))
- _location = decoded['site_id']
- _camera = decoded['camera_id']
- cur.execute("INSERT INTO alprdb(date, time, location, camera, plate, uuid) VALUES(%s, %s, %s, %s, %s, %s)",(_date, _time, _location, _camera, _plate, _uuid))
- db.commit()
- job.delete()
- else:
- cur.close()
- db.close()
- break
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement