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 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')
def create(): new_trip = Trip.create(trip_name=request.form['trip_name'], parent_user=request.form['user_id'], trip_desc=request.form['trip_desc'], trip_img_url="") if 'trip_img' in request.files: uploaded_img = request.files['trip_img'] upload_to_s3(uploaded_img, S3_BUCKET, f'trip_display_imgs/{new_trip.id}') new_trip.trip_img_url = f'{new_trip.id}/{uploaded_img.filename}' new_trip.save() result = jsonify({'status': True, 'data': new_trip.as_dict()}) return result
def map(query): response = geocoder.forward(query) first = response.geojson()['features'][0] latitude = response.geojson()['features'][0]['center'][0] longitude = response.geojson()['features'][0]['center'][1] truncated_address = textwrap.shorten(first['place_name'], width=60, placeholder="...") trips = Trip.select().order_by(Trip.created_at.desc()) return render_template('map.html', truncated_address=truncated_address, response=response, latitude=latitude, longitude=longitude, first=first, trips=trips)
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 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 post(self): trip = Trip.get_by_id(int(self.request.get("trip_key"))) if users.get_current_user().email() != trip.owner: self.redirect("/trips/manage?message=e71c6822d05dees5s9a5t76c6e6429af3") else: # Get related collaborations collaborations = list(Collaboration.query(Collaboration.trip_key == int(self.request.get("trip_key")))) # Delete collaborations for c in collaborations: c.delete() ndb.Key(Collaboration, int(c.key.id())).delete() # Delete wanted trip if ndb.Key(Trip, int(self.request.get("trip_key"))).delete(): self.redirect("/trips/manage?message=e55b6b2240ad2e55s9453t765v6v29a53") else: self.redirect("/trips/manage?message=sdc5552978b5eea6cbc607611e7f4025b")
def post(self): request = to_json(self.request.body) # Verify the token on the Google servers url = "https://www.googleapis.com/oauth2/v3/tokeninfo?id_token={}".format(request.get('token')) result = urlfetch.fetch(url=url, method=urlfetch.GET, ) if result.status_code == 200: content = to_json(result.content) # Need to check the 'aud' property once we have a user to actually test this stuff with. # For now we'll just assume everything worked and return a formatted new user user = User.query(User.email==content.get('email')).get() if user is None: # Need to create a new user user = User() user.email = content.get('email') user.put() self.response.status_int = 200 self.response.headers['Access-Control-Allow-Origin'] = "http://www.myvoyagr.co" self.response.write(user.format()) else: # Get all the trips associated with the user and add it to the response trips = {} trip_qry = Trip.query(ancestor=user.key).fetch() for trip in trip_qry: trips[trip.name] = trip.key.id() self.response.status_int = 200 self.response.headers['Access-Control-Allow-Origin'] = "http://www.myvoyagr.co" self.response.write({'user': user.format(), 'trips' : trips}) return else: self.response.status_int = 400 self.response.headers['Access-Control-Allow-Origin'] = "http://www.myvoyagr.co" self.response.write({'error': 'There was an error authenticating the user'}) return
def post(self): new_amount = self.request.get("amount") if new_amount == "": self.redirect("/trips/browse?message=ed0a1033d7809c256156d8bf0eb4673de") elif not new_amount.isdigit(): self.redirect("/trips/browse?message=e4fcba5c5c609b4800a1fa6513ba42bd8") else: new_amount = int(new_amount) # Update wanted trip trip = Trip.get_by_id(int(self.request.get("trip_key"))) past_amount = trip.collectedAmount trip.collectedAmount = past_amount + new_amount trip.put() collaboration = Collaboration(trip_key=int(self.request.get("trip_key")), amount=new_amount, user=users.get_current_user().email()) if collaboration.put(): self.redirect("/trips/browse?message=se71c6824d014ee17a9dfc77cae0928af") else: self.redirect("/trips/browse?message=e61b6b2d40ad234d5svd1f26v6d7y9a53")
def get(self): user = users.get_current_user() user_email = user.email() message_type = "" message = "" message_code = self.request.get("message") if message_code and Message.message.__contains__(message_code): message = Message.message[message_code] if message_code.startswith("e"): message_type = "error" else: message_type = "success" access_link = users.create_logout_url("/") trips = list(Trip.query(Trip.owner == user_email).order(Trip.start)) all_collaborations = dict() for t in trips: trip_collaborations = list( Collaboration.query(Collaboration.trip_key == t.key.id()).order(Collaboration.date)) all_collaborations[t.key.id()] = trip_collaborations template_values = { "info": AppInfo, "user_email": user_email, "access_link": access_link, "trips": trips, "section": "manage", "collaborations": all_collaborations, "message_type": message_type, "message": message } jinja = jinja2.get_jinja2(app=self.app) self.response.write(jinja.render_template("views/trips/manage.html", **template_values))
def get(self, user_id): if user_id is None: self.response.status_int = 400 self.response.write({'error': 'Missing user id'}) return user = ndb.Key(urlsafe=user_id).get() if user is None: self.response.status_int = 400 self.response.write({'error': 'No user exists with that ID'}) return # Get all the trips associated with the user and add it to the response trips = {} trip_qry = Trip.query(ancestor=user.key).fetch() for trip in trip_qry: trips[trip.name] = trip.key.urlsafe() self.response.status_int = 200 self.response.headers['Access-Control-Allow-Origin'] = "https://www.myvoyagr.co" self.response.write({'user': user.format(), 'trips' : trips}) return
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 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")
triplist = [{ 'trip_name': 'Working in Europe', 'parent_user': User.select().first().id }, { 'trip_name': 'Guy Things', 'parent_user': User.select().first().id + 1 }, { 'trip_name': 'Heroic Things', 'parent_user': User.select().first().id + 1 }, { 'trip_name': 'Florida Trip', 'parent_user': User.select().first().id + 2 }] for t in triplist: if Trip.get_or_none(Trip.trip_name == t['trip_name']) == None: Trip.create(trip_name=t['trip_name'], parent_user=t['parent_user']) # Trip Events from models.trip_event import TripEvent from datetime import datetime tripevent_list = [{ 'parent_trip': Trip.select().first().id, 'date_time': datetime(2019, 8, 12), 'location': 'Berlin' }, { 'parent_trip': Trip.select().first().id, 'date_time': datetime(2019, 7, 23), 'location': 'Frankfurt' }, {
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)
from models.user import User from models.trip import Trip from models.trip_event import TripEvent from models.file_attachment import FileAttachment from models.photo_attachment import PhotoAttachment from models.payment import Payment from models.subscription import Subscription FileAttachment.delete().execute() PhotoAttachment.delete().execute() Subscription.delete().execute() Payment.delete().execute() User.delete().execute() Trip.delete().execute() TripEvent.delete().execute()
def show(id): trip = Trip.get_or_none(Trip.id == id) trip_found = trip != None result = jsonify({'status': trip_found, 'data': trip.as_dict()}) return result
def start_trip(self, trip): """Set the given trip as active""" data = trip.full_data() self.set(data) return Trip(**data)
choices=[filter_name for filter_name in PlaceType.__members__], help="Filter the results") args = parser.parse_args() if (args.command == "trains"): dep_station = Station.find_station(args.dep_station) if (args.arr_station != ""): arr_station = Station.find_station(args.arr_station) if (arr_station is None): print("Unknown arrival station") sys.exit(1) else: arr_station = None trip = Trip.next_trains(dep_station, arr_station, args.handicap) for train in trip.nextTrainsList: print(train) elif (args.command == "search"): list_station = Station.search_list_places(args.query, args.filter) list_attr = [ attr for attr in PlaceType.__members__ if attr != PlaceType.no_filter.name ] table = [["Name", "Station name"] + [attr[0].upper() + attr[1:] for attr in list_attr]] for station in list_station: table_station = [station['name'], station["shortName"]] for attr in list_attr: table_station += ["X" if station[attr] else ""] table.append(table_station)