Exemplo n.º 1
0
def tagFile(filename):
    clientID = cherrypy.session.id
    dfilename = str(clientID) + '_' + filename
    aws_bucket.upload_doc_bucket(bname, filename, dfilename)
    att = {
        'Type': {
            'DataType': 'String',
            'StringValue': 'Tagging'
        },
        'ClientId': {
            'DataType': 'String',
            'StringValue': str(clientID)
        }
    }
    body = dfilename

    r = None
    while r is None:
        r = aws_sqs.put_message(iurl, body, att)
    print('Message for tagging sent\n')
    send = False
    while send is False:
        m = None
        while m is None:
            try:
                messages = aws_sqs.read_message(ourl)
                m = messages['Messages'][0]
                rhandle = m['ReceiptHandle']
                aws_sqs.change_vis(ourl, rhandle, 40)
            except:
                m = None
        typem = m['MessageAttributes']['Type']['StringValue']
        if typem == 'Tagging Response':
            clientid = m['MessageAttributes']['ClientId']['StringValue']
            if clientid == clientID:
                aws_sqs.change_vis(ourl, rhandle, 20)
                print('Tagging response received\n')
                tag = m['Body']
                addTags(tag)
                aws_sqs.delete_message(ourl, rhandle)
                print('The tag is: ' + tag + '\n\n')
                send = True
                return tag

            else:
                send = False
Exemplo n.º 2
0
def searchTag(tag):
    clientID = cherrypy.session.id
    att = {
        'Type': {
            'DataType': 'String',
            'StringValue': 'Searching'
        },
        'ClientId': {
            'DataType': 'String',
            'StringValue': str(clientID)
        }
    }
    body = tag
    r = None
    while r is None:
        r = aws_sqs.put_message(iurl, body, att)
    print('Message for searching sent\n')
    send = False
    while send is False:
        m = None
        while m is None:
            try:
                messages = aws_sqs.read_message(ourl)
                m = messages['Messages'][0]
                rhandle = m['ReceiptHandle']
                aws_sqs.change_vis(ourl, rhandle, 40)
            except:
                m = None
        typem = m['MessageAttributes']['Type']['StringValue']
        if typem == 'Searching Response':
            clientid = m['MessageAttributes']['ClientId']['StringValue']
            if clientid == clientID:
                aws_sqs.change_vis(ourl, rhandle, 100)
                print('Searching response received\n')
                docs = m['Body']
                aws_sqs.delete_message(ourl, rhandle)
                docs_aux, urls = printDocs(docs)
                send = True
                return docs_aux, urls
            else:
                send = False
Exemplo n.º 3
0
Arquivo: tagging.py Projeto: lodmm/ta
index = 'Findex.json'
bname = 'lo-ta-bucket-p1'
inbox = 'inbox'
outbox = 'outbox'
qtoken = 'token'
iurl = aws_sqs.get_url(inbox)
ourl = aws_sqs.get_url(outbox)
turl = aws_sqs.get_url(qtoken)


while True:
	m = None
	while m is None:
		try:
			messages = aws_sqs.read_message(iurl)
			m = messages['Messages'][0]
			rhandle = m['ReceiptHandle']
			aws_sqs.change_vis(iurl, rhandle, 20)
		except:
			m = None		
	typem = m['MessageAttributes']['Type']['StringValue']
	if typem =='Tagging':
		aws_sqs.change_vis(iurl, rhandle, 200)
		print('Tagging message received')
		clientid = m['MessageAttributes']['ClientId']['StringValue']
		key = m['Body']
		#Get the document form the bucket
		filename = key
		aws_bucket.get_doc_bucket(bname,filename,key)
		tag,n = getRepeatedWord(filename)