Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import beanstalkc
  4. import time
  5. import json
  6. import MySQLdb
  7.  
  8.  
  9.  
  10. db = MySQLdb.connect("localhost", "root", "YOUR_MySQL_PASSWORD","alprdb")
  11.  
  12. beanstalk = beanstalkc.Connection(host='localhost', port=11300)
  13. cur = db.cursor()
  14. beanstalk.watch('alprd')
  15.  
  16.  
  17. while True:
  18. job = beanstalk.reserve(timeout=0)
  19. if job is not None:
  20. decoded= json.loads(job.body)
  21. _plate = decoded['results'][0]['plate']
  22. _uuid = decoded['uuid']
  23. epoch = decoded['epoch_time']
  24. _date = time.strftime('%Y-%m-%d',time.localtime(epoch/1000))
  25. _time = time.strftime('%H:%M:%S',time.localtime(epoch/1000))
  26. _location = decoded['site_id']
  27. _camera = decoded['camera_id']
  28. cur.execute("INSERT INTO alprdb(date, time, location, camera, plate, uuid) VALUES(%s, %s, %s, %s, %s, %s)",(_date, _time, _location, _camera, _plate, _uuid))
  29. db.commit()
  30. job.delete()
  31. else:
  32. cur.close()
  33. db.close()
  34. break
  35. exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement