def comm_callback(ch, method, properties, body): print body try: ref = json.loads(body) except: print body + ' not json' ch.basic_ack(delivery_tag=method.delivery_tag) return if 'bobbin' in ref: status, caller = try_load(ref['bobbin']) if status: print 'spin up' tmp_cq = adapter.couch_queue() thread_id = uuid.uuid4() threads[thread_id] = tmp_cq tmp_cq.start_spool(ref['bobbin'], caller) cq.channel.basic_publish( 'command', 'notify', json.dumps({'bobbin': { 'id': str(thread_id), 'name': body }})) ch.basic_ack(delivery_tag=method.delivery_tag) else: ch.basic_ack(delivery_tag=method.delivery_tag) cq.channel.basic_publish('error', 'error', json.dumps({'error': body})) if ref['bobbin'] == 'status': print threads for i in threads: print dir(threads[i]) if ref['bobbin'] == 'die': ch.stop_consuming()
def comm_callback(ch, method, properties, body): print body try: ref = json.loads(body) except: print body + " not json" ch.basic_ack(delivery_tag=method.delivery_tag) return if "bobbin" in ref: status, caller = try_load(ref["bobbin"]) if status: print "spin up" tmp_cq = adapter.couch_queue() thread_id = uuid.uuid4() threads[thread_id] = tmp_cq tmp_cq.start_spool(ref["bobbin"], caller) cq.channel.basic_publish("command", "notify", json.dumps({"bobbin": {"id": str(thread_id), "name": body}})) ch.basic_ack(delivery_tag=method.delivery_tag) else: ch.basic_ack(delivery_tag=method.delivery_tag) cq.channel.basic_publish("error", "error", json.dumps({"error": body})) if ref["bobbin"] == "status": print threads for i in threads: print dir(threads[i]) if ref["bobbin"] == "die": ch.stop_consuming()
#!/usr/bin/python -i import os,subprocess import pika,couchdbkit,json import httplib,adapter,traceback import readline , rlcompleter,string,uuid readline.parse_and_bind('tab:complete') import BeautifulSoup print('bl3dr console') cq = adapter.couch_queue() print('base object = cq') tdir = 'thingiverse_cache' def load(path='thingiverse_cache'): li = os.listdir(path) cq.redis.delete('pages') cq.thingi_id.list() for i in li: print i cq.redis.set(i,open(path+os.sep+i).read()) if i[0:4] == 'page': cq.redis.sadd('pages',i) def grab(page): doc = cq.redis.get(page) bs = BeautifulSoup.BeautifulSoup(doc) items = bs.findAll(attrs={'class':'thing-float'}) docs = [] for i in items: thing_info = i.find(attrs={'class':'thing-info'})
import os,subprocess import pika,couchdbkit,json import yaml,adapter,traceback def spool_attachment(cq,doc): #print doc mime_dict = cq.config['mime_routing'] mime = doc['value'][0] if mime_dict.has_key(mime): cq.message(json.dumps(doc),mime_dict[mime]) else: cq.message(json.dumps(doc),'classify') def callback(ch, method, properties, body): ref = json.loads(body) cid = ref['_id'] D = ch.cq.id(cid) #if 'name' in D: #print 'process ' + D['name'] if '_attachments' in D: att = D['_attachments'] for i in att: #print '\t'+i+' = '+str(att[i]['content_type']) ch.basic_publish('mime_type',att[i]['content_type'],json.dumps({'name':i})) ch.basic_ack(delivery_tag = method.delivery_tag) if __name__ == "__main__": cq = adapter.couch_queue() cq.run_queue('process',callback)