Example #1
0
    def search(
        self,
        location: Optional[str] = None,
        language: Optional[str] = None,
        fulltime: bool = False,
    ) -> Dict:
        req_params = {
            "location": f'"{location}"' if location else None,
            "description": f'"{language}"' if language else None,
            "full_time": f"on" if fulltime else None,
            "utf8": "✓",
        }

        res = REQUESTS.get(f"https://jobs.github.com/positions.json", params=req_params)

        jobs = None

        if res.status_code == 200:
            jobs = res.json()

        search_data = {
            "location": location,
            "description": language,
            "full_time": fulltime,
            "ip_address": request.remote_addr,
        }

        search = Search(**search_data)
        search.save(commit=True)

        return self.schema.dump(jobs, many=True)
Example #2
0
def genres():
    genres = tuple(request.args.getlist('gen'))
    page = request.args.get('page', '1')
    search = Search()
    films, page, pageCount, filmsCount = search.films_by_genres(genres, page)
    return render_template('genres.html', films=films, page=page,
                           pageCount=pageCount, filmsCount=filmsCount,
                           genres=genres)
Example #3
0
def resources(request):

    zipcode = request.POST.get('zipcode')
    resource = request.POST.get('resource')

    if not zipcode and not resource:
        return render(request, 'resources.html')

    if zipcode and resource:
        # Save the search
        search = Search(**{
                'zipcode': zipcode,
                'resource': resource
            })
        search.save()

    try:
        zipcode = int(zipcode[:5])

        # Zero-pad New England zipcodes
        if len(str(zipcode)) == 4:
            zipcode = '0{0}'.format(zipcode)
    except:
        messages.error(request, "Sorry, I didn't recognize that zipcode. Please try again.")
        return HttpResponseRedirect('/app/resources')
    else:
        try:
            zipcode_coords = ZipcodeCoordinates.objects.get(zipcode=zipcode)
        except:
            # If this zipcode has not yet been searched, create a new one
            zipcode_coords = ZipcodeCoordinates(zipcode=zipcode)
            zipcode_coords.save()

    try:
        resource = Resource.objects.get(name=resource.lower())
    except:
        messages.error(request, "Please choose a resource and try again.")
        return HttpResponseRedirect('/app/resources')
    else:
        locations = Location.objects.select_related('provider').filter(
            resources_available=resource).exclude(provider__approved=False)
        within_radius = []
        for location in locations:
            if vincenty(
                (location.latitude, location.longitude), 
                (zipcode_coords.latitude, zipcode_coords.longitude)
            ).miles <= RADIUS_DISTANCE:
                within_radius.append(location)

    context = {
        'within_radius': within_radius,
        'zipcode': zipcode,
        'resource': resource,
        'search_from': zipcode_coords,
    }

    return render(request, 'resources.html', dictionary=context)
Example #4
0
def search_items(context, request):
    """
    Method to handle item search.
    Validates SearchForm from GET request, persists the search specifics and returns context with item table.
    """
    if request.method != 'GET':
        context['form'] = SearchForm()
        return render(request, 'app/index.html', context)

    form = SearchForm(request.GET)
    if not form.is_valid():
        return render(request, 'app/index.html', context)
    what = form.cleaned_data['what'].strip()
    place = form.cleaned_data['place']
    location = form.cleaned_data['location']
    category = form.cleaned_data['category']

    search = None
    if what or category or place or location:
        search_data = form.cleaned_data
        if request.user.is_authenticated():
            search_data['user'] = request.user
        search = Search(**search_data)
        search.save()
        context['searched'] = True

    # Cannot repopulate location field. Google places api js populates it based on the place field.
    form = SearchForm(data=dict(what=what, place=place, category=category))
    context['form'] = form

    # Search
    items = Item.objects.filter(is_published=True)
    if category:
        items = items.filter(categories=category)
    if what:
        # items = items.annotate(what=SearchVector('name', 'description'))
        items = items.filter(
            Q(name__icontains=what) | Q(description__icontains=what))

    # Create table from results
    table = None
    if items and search and search.location:
        found_items = []
        for item in items:
            found_item = FoundItem(item=item, search=search)
            found_item.distance = distance(item.location, location).miles
            found_item.save()
            found_items.append(found_item)
            table = FoundItemTable(found_items)
    elif items:
        table = ItemTable(items)

    if table:
        RequestConfig(request).configure(table)
        context['table'] = table
    return context
Example #5
0
def clear_search():
    search = Search.query.get(1)
    if search is None:
        search = Search(search_key = '')
        db.session.add(search)
        db.session.commit()
    else:
        search.search_key = ''
        db.session.commit()
    return redirect('/index')
Example #6
0
def index():

    sortForm=SortForm()
    if sortForm.validate_on_submit():
        newSort = int(sortForm.sort_by.data)
        if (newSort == 4): 
            items=Item.query.order_by(Item.posted_on.desc())
        elif (newSort == 3): 
            items=Item.query.order_by(Item.rating.desc())
        elif (newSort == 2):
            items=Item.query.order_by(Item.price.asc())
        elif (newSort == 1): 
            items=Item.query.order_by(Item.price.desc())
        else: 
            items = Item.query.order_by(Item.item_name.desc())
        item_list = items.all()
    else:    
        items = Item.query.order_by(Item.item_name.desc())
        item_list = items.all()

    searchForm = SearchForm()
    if searchForm.validate_on_submit():
        search = Search.query.get(1)
        if search is None:
            search = Search(search_key = searchForm.search_key.data)
            db.session.add(search)
            db.session.commit()
        else:
            search.search_key = searchForm.search_key.data
            db.session.commit()

    search = Search.query.get(1)
    if search is None:
        search = Search(search_key = '')
        db.session.add(search)
        db.session.commit()

    search_key = search.search_key
    searchForm.search_key.data = search_key

    if search_key != '':
        for item in items:
            item_name = re.split(', |_| |-|!|\.|\n', item.item_name)
            if not search_key in item_name:
                item_description = re.split(', |_| |-|!|\.|\n', item.item_description)
                if not search_key in item_description:
                    item_list.remove(item)

    return render_template('index.html', searchForm=searchForm, sortForm=sortForm, title="Covid Commerce", items=item_list, current_user = current_user)
Example #7
0
def search(request):
    query_string = str(request.GET.get('query_string', None))
    try:
        object_list = Search.build_search(query_string)
        results = []
        for item in object_list:
            object_type = getattr(item, 'type')
            object_id = getattr(item, 'id') % 1000000
            if object_type == Search.SEARCH_RESULT_CONTACT:
                element = build_contact_search_element(object_id)
            elif object_type == Search.SEARCH_RESULT_EVENT:
                element = build_event_search_element(object_id)
            elif object_type == Search.SEARCH_RESULT_RESOURCE:
                element = build_resource_search_element(object_id)
            if element is not None:
                results.append(element)

        search_log = SearchLog()
        search_log.query = query_string
        search_log.total = len(results)
        search_log.save()

        return HttpResponse(status=200,
                            content=json.dumps(results),
                            content_type='application/json')
    except:
        return HttpResponse(status=400,
                            content=sys.exc_info(),
                            content_type='application/json')
Example #8
0
def startSession():
    if 'android_id' in request.args:
        android_id = request.args.get('android_id')
        if android_id in []:
            return jsonify({'debug': 'True', 'ip': '52.74.20.228'})

    # VERSION SPECIFIC
    app_version = int(request.headers.get(
        'App-Version')) if 'App-Version' in request.headers else 0

    # Search().getContentData(key="recommendations")
    # Search().getContentData(key="most_searched")

    reading_multiplier = webapp.config[
        'NEW_READING_RATE'] if app_version >= 6030000 else webapp.config[
            'NEW_READING_RATE'] - 0.01
    data = {
        'most_searched': Collection(4).getObj()['items'],
        'recommendations': Collection(5).getObj()['items'],
        'categories': Search.getSearchCategoriesForApp(),
        'return_days': webapp.config['DEFAULT_RETURN_DAYS'],
        'reading_multiplier': reading_multiplier,
        'time_slots': Order.getTimeSlotsForOrder(),
        'user_model': None
    }

    if 'user_id' in request.args:
        user_id = request.args.get('user_id')
        if user_id and int(user_id) > -1:
            user = User(user_id)
            user.getOrderSlots()
            data['user_model'] = user.getObj()
            user.logMetadata(app_version)
    return jsonify(data)
Example #9
0
 def removeItem(item_id):
     from app.models import Search
     conn = mysql.connect()
     cursor = conn.cursor()
     cursor.execute("""UPDATE items SET active = 0 WHERE item_id = %s""",
                    (item_id, ))
     conn.commit()
     Search(item_id).unindexItem()
    def fetchSearchResults(query, search_type, page):
        from app.models import Search

        user_info = {'user_id': -1, 'uuid': 'web:-1', 'gcm_id': None}
        user_data = session.get('_user', None)
        if user_data:
            user_info['user_id'] = user_data['user_id'] 
            user_info['uuid'] = 'web:'+str(user_data['user_id']) 

        search = Search(query, user_info)
        page = page - 1
        if search_type == 'category':
            results = search.categorySearch(page)
        elif search_type == 'collection':
            results = search.collectionsSearch(page)
        else: 
            results = search.basicSearch(page, source='web')
        results['items'] = WebUtils.extendItemWebProperties(results['items'])
        return results 
Example #11
0
def searchFail():
    #NOTE deprecated. Done directly from backend
    return jsonify(status='true')

    user_id = Utils.getParam(request.form, 'user_id', 'int')
    q = Utils.getParam(request.form, 'q')
    q_type = Utils.getParam(request.form, 'type')
    flow = Utils.getParam(request.form, 'flow', default='borrow')

    Search(q, {'user_id': user_id}, flow).reportFail(True, True, q_type)
    return jsonify(status='true')
Example #12
0
def searchString():
    response = {'status': 'False'}
    results = {}

    query = Utils.getParam(request.args, 'q')
    page = Utils.getParam(request.args, 'page', var_type='int', default=1)
    search_type = Utils.getParam(request.args, 'type', default='free')
    user_id = Utils.getParam(request.args, 'userId', 'int')
    flow = Utils.getParam(request.args, 'flow', default='borrow')
    gcm_id = Utils.getParam(request.args, 'gcm_id', default=None)
    uuid = Utils.getParam(request.args, 'distinct_id', default=None)
    ref = Utils.getParam(request.args, 'ref', default='mobile')

    if not query:
        return Utils.errorResponse(response, 'HTTP_STATUS_CODE_DATA_MISSING')

    if ref == 'web':
        return json.dumps(WebUtils.fetchSearchResults(query, search_type,
                                                      page))

    user_info = {'user_id': user_id, 'gcm_id': gcm_id, 'uuid': uuid}
    search = Search(query, user_info, flow)
    if search_type == 'free':
        results = search.basicSearch(page=page - 1)
    elif search_type == 'category':
        results = search.categorySearch(page=page - 1)
    elif search_type == 'collections':
        results = search.collectionsSearch(page=page - 1)
    elif search_type == 'isbn':
        results = search.isbnSearch(page=page - 1)
    elif search_type == 'auto':
        results = search.autoComplete()
    elif search_type == 'custom':
        results = search.customQuery()
        return results
    #log
    if user_id not in Utils.getAdmins():
        Search.logSearch({_: request.args.get(_)
                          for _ in request.args}, search_type)

    return jsonify(results) if flow != 'admin' else jsonp(results)
Example #13
0
def search():
    types = ('film', 'person', 'user')
    page = request.args.get('page', '1')
    title = request.args.get('query', '')
    srch_type = request.args.get('type', 'film')
    if srch_type not in types:
        srch_type = 'film'
    search = Search()
    if srch_type == 'film':
        films, page, lenght = search.search_film(title, page)
        pages = ceil(lenght/app.config['ITEMS_PER_PAGE'])
        return render_template('srch_film.html', films=films, pageCount=pages,
                               p=page, q=title, lenght=lenght)
    elif srch_type == 'person':
        persons, page, lenght = search.search_person(title, page, [1, 2])
        pages = ceil(lenght/app.config['ITEMS_PER_PAGE'])
        return render_template('srch_per.html', persons=persons,
                               pageCount=pages, p=page, q=title, lenght=lenght)
    else:
        users = search.search__user(title)
        return render_template('srch_user.html', users=users, q=title)
Example #14
0
def search(page=1):
    keywords = request.args.get("keywords", '').strip()

    if not keywords:
        return redirect(url_for("home.index"))

    s = Search.query.filter_by(words=keywords).first()
    if s:
        #org.update({"words":keywords, "times":org.times + 1 })
        s.times = s.times + 1
        s.save()
    else:
        n = Search()
        n.words = keywords
        n.times = 1
        n.save()

    page_obj = Post.query.search(keywords).as_list().\
        paginate(page, per_page=Post.PER_PAGE)
    if page_obj.total == 1:
        post = page_obj.items[0]
        return redirect(post.url)
    page_url = lambda page: url_for(
        'home.search', page=page, keywords=keywords)

    return render_template("home/search.html",
                           page_obj=page_obj,
                           page_url=page_url,
                           keywords=keywords)
Example #15
0
    def test_follow_searches(self):
        # create four users
        u1 = User(username='******', email='*****@*****.**')
        u2 = User(username='******', email='*****@*****.**')
        u3 = User(username='******', email='*****@*****.**')
        u4 = User(username='******', email='*****@*****.**')
        db.session.add_all([u1, u2, u3, u4])

        # create four search posts
        now = datetime.utcnow()
        p1 = Search(keyword="test1", author=u1,
                    timestamp=now + timedelta(seconds=1))
        p2 = Search(keyword="test2", author=u2,
                    timestamp=now + timedelta(seconds=4))
        p3 = Search(keyword="test3", author=u3,
                    timestamp=now + timedelta(seconds=3))
        p4 = Search(keyword="test4", author=u4,
                    timestamp=now + timedelta(seconds=2))
        db.session.add_all([p1, p2, p3, p4])
        db.session.commit()

        # setup the followers
        u1.follow(u2)  # john follows susan
        u1.follow(u4)  # john follows david
        u2.follow(u3)  # susan follows mary
        u3.follow(u4)  # mary follows david
        db.session.commit()

        # check the followed searches of each user
        f1 = u1.followed_searches().all()
        f2 = u2.followed_searches().all()
        f3 = u3.followed_searches().all()
        f4 = u4.followed_searches().all()

        self.assertEqual(f1, [p2, p4, p1])
        self.assertEqual(f2, [p2, p3])
        self.assertEqual(f3, [p3, p4])
        self.assertEqual(f4, [p4])
        self.assertIsNot(f1, [p2, p3])
Example #16
0
def getRelatedItemsApi():
    client = MongoClient(webapp.config['MONGO_DB'])
    db = client.ostrich

    item_id = Utils.getParam(request.args, 'item_id', 'int')

    related_items_cursor = db.related_item_ids.find({'_id': item_id})
    related_item_ids = [_ for _ in related_items_cursor]

    if len(related_item_ids) == 0:
        #check redis queue
        getRelatedItemsAsyncWrapper(item_id)
        return jsonify({'status': 'wait', 'message': 'Crawling in progress'})

    related_item_ids = related_item_ids[0]['item_ids']
    items = Search().getById(related_item_ids)
    return json.dumps(items)
Example #17
0
def hidden():
    # Handled within request
    tags = request.args.get("tags") or "trap"
    try:
        page = int(request.args.get("page") or 1)
    except (TypeError, ValueError):
        return '"page" parameter must be Integer.<br>Invalid "page" parameter: "{}"'.format(
            request.args.get("page"))
    # Handled within building
    try:
        count = int(request.args.get("count") or 50)
    except (TypeError, ValueError):
        return '"count" parameter must be Integer.<br>Invalid "count": "{}"'.format(
            request.args.get("count"))
    base64 = boolparse(request.args.get("base64"))
    # Handled within Jinja template
    showfull = boolparse(request.args.get("showfull"))
    showtags = boolparse(request.args.get("showtags"))
    # Request, Parse & Build Data
    data = build_data(tags, page - 1, count, base64, showfull)
    # Handling for limiters
    if base64:
        if showfull:
            count = min(25, count)
        else:
            count = min(50, count)
    search = Search(
        user_id=current_user.id,
        exact_url=str(request.url),
        query_args=json.dumps(request.args.to_dict()),
    )
    db.session.add(search)
    db.session.commit()
    return render_template(
        "hidden.html",
        title="Gelbooru Browser",
        data=data,
        tags=tags,
        page=page,
        count=count,
        base64=base64,
        showfull=showfull,
        showtags=showtags,
    )
Example #18
0
def index():
    form = InputForm()
    if form.validate_on_submit():
        user_search = Search(user_id=current_user.id,
                             keyword=form.keyword.data, limit=form.limit.data)
        db.session.add(user_search)
        db.session.commit()
        keyword = form.keyword.data
        limit = form.limit.data
        flash("Search complete!")
        return redirect(url_for('results', name=keyword, limit=limit))
    page = request.args.get('page', 1, type=int)
    searches = current_user.followed_searches().paginate(
        page, app.config['POSTS_PER_PAGE'], False)
    next_url = url_for('index', page=searches.next_num) \
        if searches.has_next else None
    prev_url = url_for('index', page=searches.prev_num) \
        if searches.has_prev else None
    return render_template('index.html', title='Home', form=form,
                           searches=searches.items, next_url=next_url,
                           prev_url=prev_url)
Example #19
0
def getCategories():
    categories = Search.getSearchCategoriesForApp()
    return json.dumps(categories)
Example #20
0
def resources(request, **kwargs):
    searched_location = request.POST.get('location')
    resource = request.POST.getlist('resource')
    type_ = request.POST.get('type')
    radius = request.POST.get('radius')

    if not type_:
        type_ = request.GET.get('type')

    if not type_:
        type_ = kwargs.get('type')

    try:
        radius = int(radius)
        assert 10 < radius < 150
    except:
        radius = RADIUS_DISTANCE

    if not searched_location and not resource: # neither
        return render(request, 'resources.html', { 'type': type_ })
    elif searched_location and resource: # both
        # Save the search
        search = Search(**{
                'location': searched_location,
                'resource': resource
            })
        search.save()

        coords = find_search_coordinates(searched_location)
    elif not searched_location:
        coords = False

    if not coords:
        cdnt_find_loc_error_msg = _("Sorry, I couldn't find that location. Please try again. You can also search by city or by zipcode.")
        messages.error(request, cdnt_find_loc_error_msg)
        if type_:
            return HttpResponseRedirect(reverse('resources', kwargs={'type': type_}))
        else:
            return HttpResponseRedirect(reverse('resources'))

    try:
        if len(resource) == 1:
            resource = [Resource.objects.get(name=resource[0].lower())]
        elif len(resource) > 1:
            resource = Resource.objects.filter(name__in=[res.lower() for res in resource])
        else:
            raise ValueError
    except:
        cdnt_find_res_error_msg = _("Please choose a resource and try again.")
        messages.error(request, cdnt_find_res_error_msg)
        if type_:
            return HttpResponseRedirect(reverse('resources', kwargs={'type': type_}))
        else:
            return HttpResponseRedirect(reverse('resources'))
    else:
        locations = Location.objects.select_related('provider').exclude(provider__approved=False)

        if len(resource) == 1: # Just one resource chosen
            locations = locations.filter(resources_available=resource[0])
        elif len(resource) > 1:
            locations = locations.filter(resources_available__in=resource)
            
        preferred_orgs = False
        within_radius = []
        for location in locations:
            dist = vincenty(
                (location.latitude, location.longitude), 
                (coords['latitude'], coords['longitude'])
            ).miles
            if dist <= radius:
                within_radius.append((location,round(dist,1)))
                if location.provider.preferred:
                    preferred_orgs = True

        within_radius.sort(key=lambda tup: (not(tup[0].provider.preferred), tup[1]))
        #sorts the location/distance tuples by dist with preferred ones first
        
        
        #passing a sorted list of tuples with (orgname, distance)
        

    context = {
        'within_radius': within_radius,
        'radius':radius,
        'preferred_orgs':preferred_orgs,
        'location': searched_location,
        'resource': resource,
        'search_from': coords,
        'type': type_
    }

    return render(request, 'resources.html', dictionary=context)
Example #21
0
 def make_search(self, data):
     return Search(**data)
Example #22
0
def resources(request):
    searched_location = request.POST.get('location')
    resource = request.POST.get('resource')

    if not searched_location and not resource:
        return render(request, 'resources.html')

    if searched_location and resource:
        # Save the search
        search = Search(**{
            'location': searched_location,
            'resource': resource
        })
        search.save()

    coords = False

    try:
        searched_location = int(searched_location[:5])

        # Zero-pad New England zipcodes
        if len(str(searched_location)) == 4:
            searched_location = '0{0}'.format(searched_location)
    except:
        try:
            geolocator = GoogleV3()
            address, (latitude,
                      longitude) = geolocator.geocode(searched_location)
        except:
            pass
        else:
            coords = {
                'latitude': latitude,
                'longitude': longitude,
            }
    else:
        try:
            zipcode_coords = ZipcodeCoordinates.objects.get(
                zipcode=searched_location)
        except:
            # If this zipcode has not yet been searched, create a new one
            zipcode_coords = ZipcodeCoordinates(zipcode=searched_location)
            zipcode_coords.save()
        finally:
            coords = {
                'latitude': zipcode_coords.latitude,
                'longitude': zipcode_coords.longitude
            }

    if not coords:
        messages.error(
            request,
            "Sorry, I couldn't find that location. Please try again. You can also search by city or by zipcode."
        )
        return HttpResponseRedirect('/app/resources')

    try:
        resource = Resource.objects.get(name=resource.lower())
    except:
        messages.error(request, "Please choose a resource and try again.")
        return HttpResponseRedirect('/app/resources')
    else:
        locations = Location.objects.select_related('provider').filter(
            resources_available=resource).exclude(provider__approved=False)
        within_radius = []
        for location in locations:
            if vincenty((location.latitude, location.longitude),
                        (coords['latitude'],
                         coords['longitude'])).miles <= RADIUS_DISTANCE:
                within_radius.append(location)

    context = {
        'within_radius': within_radius,
        'location': searched_location,
        'resource': resource,
        'search_from': coords,
    }

    print context

    return render(request, 'resources.html', dictionary=context)
Example #23
0
def recommended():
    return json.dumps(Search([]).mostRecommended())
Example #24
0
def resources(request):

    searched_location = request.POST.get('location')
    resource = request.POST.get('resource')

    if not searched_location and not resource:
        return render(request, 'resources.html')

    if searched_location and resource:
        # Save the search
        search = Search(**{
                'location': searched_location,
                'resource': resource
            })
        search.save()

    coords = False

    try:
        searched_location = int(searched_location[:5])

        # Zero-pad New England zipcodes
        if len(str(searched_location)) == 4:
            searched_location = '0{0}'.format(searched_location)
    except:
        try:
            geolocator = GoogleV3()
            address, (latitude, longitude) = geolocator.geocode(searched_location)
        except:
            pass
        else:
            coords = {
                'latitude': latitude,
                'longitude': longitude,
            }
    else:
        try:
            zipcode_coords = ZipcodeCoordinates.objects.get(zipcode=searched_location)
        except:
            # If this zipcode has not yet been searched, create a new one
            zipcode_coords = ZipcodeCoordinates(zipcode=searched_location)
            zipcode_coords.save()
        finally:
            coords = {
                'latitude': zipcode_coords.latitude,
                'longitude': zipcode_coords.longitude
            }

    if not coords:
        messages.error(request, "Sorry, I couldn't find that location. Please try again. You can also search by city or by zipcode.")
        return HttpResponseRedirect('/app/resources')

    try:
        resource = Resource.objects.get(name=resource.lower())
    except:
        messages.error(request, "Please choose a resource and try again.")
        return HttpResponseRedirect('/app/resources')
    else:
        locations = Location.objects.select_related('provider').filter(
            resources_available=resource).exclude(provider__approved=False)
        within_radius = []
        for location in locations:
            if vincenty(
                (location.latitude, location.longitude), 
                (coords['latitude'], coords['longitude'])
            ).miles <= RADIUS_DISTANCE:
                within_radius.append(location)

    context = {
        'within_radius': within_radius,
        'location': searched_location,
        'resource': resource,
        'search_from': coords,
    }

    print context

    return render(request, 'resources.html', dictionary=context)
Example #25
0
def mostSearched():
    return json.dumps(Search([]).mostSearched())
Example #26
0
def index():
    if not current_user.is_authenticated:
        return redirect(url_for('auth.login'))

    form = SearchForm()
    search = None
    results = []

    if form.validate_on_submit():
        try:
            journeys = eval(current_user.journeys)
            if journeys[0]['travel_address'] == '':
                flash('Please set up journeys in "Edit Journeys!"')
                return redirect(url_for('main.edit_profile'))

        except:
            current_app.logger.info(
                f"Failed to evaluate {journeys}. by {current_user.username}")
            return redirect(url_for('main.index'))

        potential_house = form.potential_house.data
        try:
            house_coordinates = get_coordinates(potential_house)
        except:
            flash(
                'Address could not be found. Please double-check the address!')
            return redirect(url_for('main.index'))

        for journey in journeys:
            label = journey['label']
            direction = journey['direction']
            if direction == "to":
                origin = potential_house
                destination = journey['travel_address']
            elif direction == "from":
                origin = journey['travel_address']
                destination = potential_house

            in_json_results = []
            for mode in journey['travel_modes']:
                duration = calculate_route(origin, destination, mode)
                directions_url = generate_directions_url(
                    origin, destination, mode)
                in_json_result = {
                    "mode": mode,
                    "duration": duration,
                    "directions_url": directions_url
                }
                in_json_results.append(in_json_result)

            search = {
                'label': label,
                'direction': direction,
                "arrive_by": "",
                "potential_house": potential_house,
                "house_lat": str(house_coordinates['lat']),
                "house_lng": str(house_coordinates['lng']),
                "travel_address": journey['travel_address'],
                "results": in_json_results
            }

            results.append(search)

        search = Search(searches=results, author=None)
        db.session.add(search)
        db.session.commit()

    return render_template('index.html',
                           title='Home',
                           search=search,
                           form=form)