Created
November 10, 2011 16:28
-
-
Save Motoma/1355297 to your computer and use it in GitHub Desktop.
database.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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