def adhoc_search(): return_dict = {"adhocResults": {}} request = request_dict.data_create("") start_date = datetime.date.fromisoformat( request["start_date"].split("T")[0]) end_date = datetime.date.fromisoformat(request["end_date"].split("T")[0]) region_id = int(request["region"]) region_name = region_services.get_name_from_id(region_id) return_dict["adhocResults"] = {"name": region_name, "parks": []} available_parks = scrape_searches_adhoc(start_date=start_date, end_date=end_date, region_id=region_id) # available_parks = { # 1: "Amnicon Falls", # 2: "Aztalan", # 3: "Big Bay", # 4: "Big Foot Beach", # 5: "Black River", # } wanted_parks = set(search_services.deserialize_park_list(request["parks"])) intersection = wanted_parks.intersection(available_parks.keys()) for park_id in intersection: return_dict["adhocResults"]["parks"].append({ "name": available_parks[park_id], "url": park_services.create_URL_from_id(park_id, start_date, end_date), }) return jsonify(return_dict)
def submit_search(): vm = IndexViewModel() # feature is temporarily disabled: if True == True: return {} # feature before: if vm.user_id == None: return {} request = request_dict.data_create("") owner_id = vm.user_id start_date = datetime.date.fromisoformat( request["start_date"].split("T")[0]) end_date = datetime.date.fromisoformat(request["end_date"].split("T")[0]) regions = request["regions"] parks_dict = request["parks"] parks = search_services.parse_parks_from_frontend(parks_dict) is_active = True search = search_services.create_search(owner_id, start_date, end_date, regions, parks, is_active) if not search: return jsonify(status="error") success = search_services.add_search(search) return jsonify(success)
def toggle_search_status(): vm = IndexViewModel() if not vm.user_id: return flask.redirect("account/login") request = request_dict.data_create("") success = search_services.toggle_search_status(request["id"], request["is_active"]) if not success: return jsonify({"status": "could not find search"}) return jsonify({"status": "success"})
def toggle_setting_status(): vm = IndexViewModel() if not vm.user_id: return flask.redirect("account/login") request = request_dict.data_create("") success = user_service.update_setting(vm.user, request["setting"], request["is_checked"]) if not success: return jsonify({"status": "could not update setting"}) return jsonify({"status": "success"})
def load_distances_from_origin(): request = request_dict.data_create("") if map_services.validate_zip_code(request.zip) == False: return {'error': 'Zip is not valid'} zip_response = asyncio.run(map_services.get_zip_distance_data(request.zip)) return jsonify(zip_response)