Esempio n. 1
0
def logincheck(id, password):
    body = {
        "query": {
            "bool": {
                "must": {
                    "match_phrase": {
                        "email": id
                    }
                },
                "must": {
                    "match_phrase": {
                        "password": password
                    }
                }
            }
        }
    }
    result = mapping.elasticSearch('user-index', body)
    result = result['hits']
    if result['total'] >= 1:
        #print result
        hits = result['hits']
        if hits:
            for hit in hits:
                userid = hit['_id']
                break
        return userid
    return False
Esempio n. 2
0
def searchuser(id):
    body = {"query": {"match_phrase": {"email": id}}}
    result = mapping.elasticSearch('user-index', body)
    result = result['hits']
    if result['total'] >= 1:
        return True
    return False
Esempio n. 3
0
def listofTours():
    result_list = []
    result = mapping.elasticSearch('tour-index')
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            _id = hit['_id']
            name = hit['_source']['name']
            createdBy = hit['_source']['createdBy']
            category = hit['_source']['category']
            time = hit['_source']['time']
            distance = hit['_source']['distance']
            stops = hit['_source']['stops']
            latitude = hit['_source']['latitude']
            longitude = hit['_source']['longitude']
            result_list.append(
                dict(tourid=_id,
                     name=name,
                     createdBy=createdBy,
                     category=category,
                     time=time,
                     distance=distance,
                     stops=stops,
                     latitude=latitude,
                     longitude=longitude))
    return result_list
Esempio n. 4
0
def getTour(tourid):
    result_list = []
    body = {"query": {"match_phrase": {"_id": tourid}}}
    result = mapping.elasticSearch('tour-index', body)
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            _id = hit['_id']
            name = hit['_source']['name']
            createdBy = hit['_source']['createdBy']
            category = hit['_source']['category']
            time = hit['_source']['time']
            distance = hit['_source']['distance']
            stops = hit['_source']['stops']
            latitude = hit['_source']['latitude']
            longitude = hit['_source']['longitude']
            return (dict(tourid=_id,
                         name=name,
                         createdBy=createdBy,
                         category=category,
                         time=time,
                         distance=distance,
                         stops=stops,
                         latitude=latitude,
                         longitude=longitude))
Esempio n. 5
0
def getStopName(stopid):
    body = {"query": {"match_phrase": {"_id": stopid}}}
    result = mapping.elasticSearch('stops-index', body)
    print result
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            Name = hit['_source']['name']
            break
        return str(Name)
    else:
        return None
Esempio n. 6
0
def getUserName(userid):
    body = {"query": {"match_phrase": {"_id": userid}}}
    result = mapping.elasticSearch('user-index', body)
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            firstName = hit['_source']['firstName']
            lastName = hit['_source']['lastName']
            break
        return str(firstName) + ' ' + str(lastName)
    else:
        return None
Esempio n. 7
0
def userhistory(userid):
    result_list = []
    body = {"query": {"match_phrase": {"userId": userid}}}
    result = mapping.elasticSearch('history-index', body)
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            tour = getTour(hit['_source']['tourId'])
            tour['historyid'] = hit['_id']
            tour['takenOn'] = hit['_source']['takenOn']
            result_list.append(tour)
    return result_list
Esempio n. 8
0
def fullhistory():
    result_list = []
    result = mapping.elasticSearch('history-index')
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            _id = hit['_id']
            userid = hit['_source']['userId']
            tourid = hit['_source']['tourId']
            takenon = hit['_source']['takenOn']
            result_list.append(
                dict(historyid=_id,
                     userid=userid,
                     tourid=tourid,
                     takenon=takenon))
    return result_list
Esempio n. 9
0
def tourTaken(tourid, userid):
    # create a entry in history table with the userid and tourid
    body = {"query": {"match_phrase": {"_id": userid}}}
    result = mapping.elasticSearch('user-index', body)
    result = result['hits']
    if result['total'] >= 1:
        data = dict(tourId=tourid,
                    userId=userid,
                    takenOn=strftime("%Y-%m-%d %H:%M:%S", localtime()))
        result = mapping.elasticInsert('history-index', 'history', data)
        if result['_id']:
            return True
        else:
            return False
    else:
        print 'No user with userid - {}'.format(userid)
        return False
Esempio n. 10
0
def listofusers():
    result_list = []
    result = mapping.elasticSearch('user-index')
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            _id = hit['_id']
            firstName = hit['_source']['firstName']
            lastName = hit['_source']['lastName']
            email = hit['_source']['email']
            password = hit['_source']['password']
            result_list.append(
                dict(firstName=firstName,
                     lastName=lastName,
                     email=email,
                     password=password,
                     userid=_id))
    return result_list
Esempio n. 11
0
def stopdeatils(stopid):
    try:
        #print stopid
        comments = []
        body = {"query": {"match_phrase": {"stopId": stopid}}}
        result = mapping.elasticSearch('comment-index', body)
        #print result
        hits = result['hits']['hits']
        if hits:
            for hit in hits:
                _id = hit['_id']
                comment = hit['_source']['comments']
                userName = getUserName(hit['_source']['userId'])
                postedOn = hit['_source']['postedOn']
                comments.append(
                    dict(commentid=_id,
                         id=stopid,
                         comments=comment,
                         userName=userName,
                         postedOn=postedOn))
    except Exception as e:
        comments = False
    return comments
Esempio n. 12
0
def specificTour(tourid):
    stopresult = []
    tourresult = dict()
    comments = []
    body = {"query": {"match_phrase": {"_id": tourid}}}
    result = mapping.elasticSearch('tour-index', body)
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            _id = hit['_id']
            name = hit['_source']['name']
            createdBy = hit['_source']['createdBy']
            category = hit['_source']['category']
            time = hit['_source']['time']
            distance = hit['_source']['distance']
            stops = hit['_source']['stops']
            latitude = hit['_source']['latitude']
            longitude = hit['_source']['longitude']
            tourresult = dict(tourid=_id,
                              name=name,
                              createdBy=createdBy,
                              category=category,
                              time=time,
                              distance=distance,
                              stops=stops,
                              latitude=latitude,
                              longitude=longitude)

    body = {"query": {"match_phrase": {"tourId": tourid}}}
    result = mapping.elasticSearch('stops-index', body)
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            _id = hit['_id']
            name = hit['_source']['name']
            sequence = hit['_source']['sequence']
            description = hit['_source']['description']
            stop_latitude = hit['_source']['stop_latitude']
            stop_longitude = hit['_source']['stop_longitude']
            stopresult.append(
                dict(stopid=_id,
                     name=name,
                     sequence=sequence,
                     description=description,
                     stop_latitude=stop_latitude,
                     stop_longitude=stop_longitude))

    body = {"query": {"match_phrase": {"stopId": tourid}}}
    result = mapping.elasticSearch('comment-index', body)
    hits = result['hits']['hits']
    if hits:
        for hit in hits:
            _id = hit['_id']
            comment = hit['_source']['comments']
            userName = getUserName(hit['_source']['userId'])
            postedOn = hit['_source']['postedOn']
            comments.append(
                dict(commentid=_id,
                     id=tourid,
                     comments=comment,
                     userName=userName,
                     postedOn=postedOn))

    result = dict(tour=tourresult, stops=stopresult, comments=comments)
    return result