def get_active_trip(self): """Get the trip that the authenticated user is currently traveling on""" val = self.val() if val is not None: return Trip(**val) else: return None
def select(id): sql = "SELECT * FROM trips WHERE id = %s" values = [id] result = run_sql(sql, values)[0] if result is not None: user = user_repo.select(result['user_id']) city = city_repo.select(result['city_id']) trip = Trip(user, result['name'], city, result['date'], result['duration'], result['review'], result['id']) return trip
def select_all(): trips = [] sql = "SELECT * FROM trips" results = run_sql(sql) for row in results: user = user_repo.select(row['user_id']) city = city_repo.select(row['city_id']) trip = Trip(user, row['name'], city, row['date'], row['duration'], row['review']) trips.append(trip) return trips
def get_user_trips(self): """Return all trips created by the authenticated user""" trips = [] for item in self.list(): try: trip = Trip(**item.val()) trip._id = item.key() trips.append(trip) except Exception: Logger.exception("get_user_trips") return trips
def save_location(query): response = geocoder.forward(query) latitude = response.geojson()['features'][0]['center'][0] longitude = response.geojson()['features'][0]['center'][1] first = response.geojson()['features'][0] address = first['place_name'] new_event = Trip(longitude=longitude, latitude=latitude, address=address) if new_event.save(): print('Successfully Saved Trip to DB') return redirect(url_for('map', query=query, first=first)) else: print('Failed to Save') return redirect(url_for('map', query=query, first=first))
def fetch_predictions_and_trips(self, route_ids, stop_id): params = { "filter[stop]": stop_id, "filter[direction_id]": 0, "filter[route]": ",".join(route_ids), "include": "trip", } predictions, included = self.fetch(path="predictions", params=params) if predictions: trips_by_id = {} for t in included: trip = Trip(t) trips_by_id[trip.id] = trip return [Prediction(p) for p in predictions], trips_by_id else: return [], {}
def callback(*args): """Callback to update the trip""" app = App.get_running_app() trip_manager = app.backend.trip_manager try: # create new trip trip = Trip(name=args[1], days=1) # add to data cloud trip_manager.add_trip(trip) # update the local data app.trips.append(trip) self.reload() except Exception as e: Logger.exception('add trip') Alert(title=app.name, text=str(e))
def get_by_url(self, url, validation=None): """Get the object given in the URL, which is generated by 'share_url' method""" r = urlparse(url) if r.netloc == config.BACKEND_DOMAIN: if r.query == 'trip': # path to access the trip _, uid, trip_id = r.path.split('/') if validation is not None and validation == 'trip': return True # Query the Trip object at given path data = self.val(uid, 'trips', trip_id) return Trip(_id=trip_id, **data) elif r.query == 'destination': # path to access the destination _, uid, trip_id, destination_id = r.path.split('/') if validation is not None and validation == 'destination': return True # Query the Destination object at given path data = self.val(uid, 'trips', trip_id, 'destinations', destination_id) return Destination(_id=destination_id, **data) elif r.query == 'note': # path to access the note _, uid, trip_id, destination_id, note_id = r.path.split('/') if validation is not None and validation == 'note': return True # Query the Note object at given path data = self.val(uid, 'trips', trip_id, 'destinations', destination_id, 'notes', note_id) return Note(_id=note_id, **data) raise ValueError, 'invalid url'
def post(self): place = self.request.get("place") start = self.request.get("start") end = self.request.get("end") if place == "": self.redirect('/trips/add?message=edc5552973b5eea2cbc6d76s1e6fs025b') elif start == "" or end == "": self.redirect('/trips/add?message=e71c6825d054ee15a9d5c77cae0428af3') else: start = datetime.datetime.strptime(start, '%Y-%m-%d') end = datetime.datetime.strptime(end, '%Y-%m-%d') user = users.get_current_user() user_email = user.email() trip = Trip(start=start, end=end, place=place, owner=user_email) if trip.put(): self.redirect('/trips/manage?message=s7870eca52ddbc23d27daacc15505718a') else: self.redirect('/trips/add?message=e71b6b22d0ad2es5s945t76cve6v29af3')
from models.trip import Trip driver = webdriver.Chrome(executable_path='/home/diego/Programs/chromedriver') driver.get('https://riders.uber.com/') start_date = datetime.datetime(2018, 3, 26) end_date = datetime.datetime(2018, 4, 25) while "trips" not in driver.current_url: time.sleep(5) element = driver.find_element_by_class_name('trip-expand__origin') element.click() lst = [] trip = Trip() stop = False page = 1 canceladas = 0 while stop == False: trips_table = driver.find_element_by_id('trips-table') trs = driver.find_elements_by_xpath( '//*[@id="trips-table"]/tbody/tr[@class = "trip-expand__origin collapsed"]' ) for tr in trs: pickup = tr.find_elements_by_tag_name('td')[1].text.replace('""', '')[:8] pickup = datetime.datetime.strptime(pickup, '%m/%d/%y') if pickup > end_date:
country_repo.save(country_3) city_1 = City('Belfast', country_3) city_repo.save(city_1) city_2 = City('London', country_2) city_repo.save(city_2) city_3 = City('Edinburgh', country_1) city_repo.save(city_3) city_4 = City('Glasgow', country_1) city_repo.save(city_4) trip_1 = Trip( user_1, "COVID GETAWAY", city_2, 16072020, 7, "Hated it. Too many people wearing masks. I like when I can see people's faces." ) trip_repo.save(trip_1) trip_2 = Trip( user_1, "Northern Irish Xmas Trip", city_1, 20122019, 7, "Too Christmassy and I couldn't understand a word anyone was saying. My husband couldn't make it though so that was a bonus." ) trip_repo.save(trip_2) trip_3 = Trip( user_3, "Christmas Hook Up", city_3, 21122019, 5, "Was great at first, away from my wife over the Christmas holidays, but the person I went to meet was not as happy to see me as I'd hoped she would be." ) trip_repo.save(trip_3)
def start_trip(self, trip): """Set the given trip as active""" data = trip.full_data() self.set(data) return Trip(**data)
def create_trip(): name = request.form["new_trip_name"] age = request.form["new_trip_age"] new_trip = Trip(name, age) trip_repo.save(new_trip) return render_template("/trips")