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: start.py Projeto: lodmm/ta
def addToken():
    att = {'Type': {'DataType': 'String', 'StringValue': 'Token'}}
    mes = 'Token message'
    aws_sqs.put_message(turl, mes, att)
Exemplo n.º 4
0
Arquivo: tagging.py Projeto: lodmm/ta
		key = m['Body']
		#Get the document form the bucket
		filename = key
		aws_bucket.get_doc_bucket(bname,filename,key)
		tag,n = getRepeatedWord(filename)
		print('The tag of the file is '+tag)
		#Get the token
		mtoken = None
		while (mtoken is None):
			try:
				messages = aws_sqs.read_message(turl)
				mtoken = messages['Messages'][0]
			except:
				mtoken = None	
		rh = mtoken['ReceiptHandle']
		aws_sqs.delete_message(turl,rh)
		print('Token received')
		aws_bucket.get_doc_bucket(bname,index,index)
		addFindex(key,tag,n)
		aws_bucket.upload_doc_bucket(bname,index,index)
		addToken()
		#Send message to the client
		mes = tag
		att = {'Type':{'DataType':'String','StringValue':'Tagging Response'},
				'ClientId':{'DataType':'String','StringValue':str(clientid)}
				}
		aws_sqs.put_message(ourl,mes,att)		
		aws_sqs.delete_message(iurl,rhandle)
		print('Tagging response send')