Skip to content

Instantly share code, notes, and snippets.

@Motoma
Created November 10, 2011 16:28
Show Gist options
  • Save Motoma/1355297 to your computer and use it in GitHub Desktop.
Save Motoma/1355297 to your computer and use it in GitHub Desktop.
database.py
#!/usr/bin/env python
import os
import pickle
import beanstalkc
OUTPUT_DIRECTORY = 'processed'
MQHOST = 'arbiter'
MQPORT = 11300
def main():
# Pull images from the people message queue
beanstalk = beanstalkc.Connection(host=MQHOST, port=MQPORT)
beanstalk.watch('people')
while True:
# Request an processed image
job = beanstalk.reserve()
# Deserialize the image
filename, data = pickle.loads(job.body)
# Write the image to a file
image = open(os.path.join(OUTPUT_DIRECTORY, filename), 'w')
image.write(data)
image.close()
# Remove the image from the people queue
job.delete()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment