def get_rent_collections(): qs = Rent.objects() entries = [] for rent in qs: entries.append({ 'id': '{}/{}'.format(request.base_url, rent.lga_name), 'lga_name': rent.lga_name, 'one_bed': rent.one_bed, 'annual_rate_one_bed': rent.annual_rate_one_bed, 'two_bed': rent.two_bed, 'annual_rate_two_bed': rent.annual_rate_two_bed, 'three_bed': rent.three_bed, 'annual_rate_three_bed': rent.annual_rate_three_bed, 'four_bed': rent.four_bed, 'annual_rate_four_bed': rent.annual_rate_four_bed }) return jsonify(title='NSW Rent Data', id=request.base_url, entry=entries), 200
def get_rent_by_lga(lga_name): qs = Rent.objects(lga_name=lga_name) if qs.count() != 0: rent = qs[0] xml_dict = { 'id': '{}/{}'.format(request.base_url, rent.lga_name), 'lga_name': rent.lga_name, 'one_bed': rent.one_bed, 'annual_rate_one_bed': rent.annual_rate_one_bed, 'two_bed': rent.two_bed, 'annual_rate_two_bed': rent.annual_rate_two_bed, 'three_bed': rent.three_bed, 'annual_rate_three_bed': rent.annual_rate_three_bed, 'four_bed': rent.four_bed, 'annual_rate_four_bed': rent.annual_rate_four_bed } return jsonify(xml_dict), 200 else: return "LGA name not found.", 404
def show_book_borrow(ISBN, book_name, student_id, student_name, begin_date, end_date, is_return, is_rent, book_number): try: db.session.begin(subtransactions=True) rent = Rent(ISBN=ISBN, book_name=book_name, student_id=student_id, student_name=student_name, begin_date=begin_date, end_date=end_date, is_return=is_return) number1 = Student.query.filter( Student.student_id == student_id).update( {"book_number": book_number}) number2 = Book.query.filter(Book.ISBN == ISBN).update( {"is_rent": is_rent}) db.session.add(rent) db.session.commit() return True except Exception as e: db.session.rollback() print(e) return False
def create_rent(): auth_token = request.args.get('access_token') try: keys = bu.decode_auth_token(auth_token) except jwt.ExpiredSignatureError: return jsonify({'message': 'Signature expired. Please log in again.'}), 401 except jwt.InvalidTokenError: return jsonify({'message': 'Invalid token. Please log in again.'}), 401 admin = keys[0] id = keys[1] if admin == 1: return jsonify({'response': "You are not a user"}), 403 data = request.get_json() if not data: return jsonify({"response": "No input data provided"}), 400 try: result = RentSchema().load(data) except Exception: return jsonify({'response': "Invalid input"}), 403 if db.session.query( Car.carId).filter_by(carId=result["car_id"]).scalar() is None: return jsonify({'response': "Invalid car ID found"}), 404 rent = Rent(owner_id=id, car_id=result["car_id"], startT=result["startTime"], endT=result["endTime"]) db.session.add(rent) db.session.commit() return jsonify({'response': "Success"}), 201
def get(self, id): books = Rent.query.filter_by(book_id=id) existBook = Book.query.filter_by(id=id).first() if not hasattr(existBook, 'id'): return "Livro não encontrado." response = [] for book in books: tempbook = {'id': book.id, 'dateReservation': book.dateReservation} response.append(tempbook) reservedBook = [b['dateReservation'] for b in response] if not reservedBook: #Se livro ainda não foi reservado newDate = datetime.now() + timedelta(days=3) newReserve = Rent(book_id=id, dateReservation=newDate) newReserve.save() msg = "Reservado de: " + datetime.now().strftime( '%d-%b-%y') + " a " + newDate.strftime('%d-%b-%y') return msg else: #se livro está reservado verifica se já foi entregue para definir a data da reserva lastDate = max(reservedBook) print(lastDate) if lastDate <= datetime.now(): newDate = datetime.now() + timedelta(days=3) newReserve = Rent(book_id=id, dateReservation=newDate) newReserve.save() msg = "Reservado de: " + datetime.now().strftime( '%d-%b-%y') + " a " + newDate.strftime('%d-%b-%y') else: newDate = lastDate + timedelta(days=3) newReserve = Rent(book_id=id, dateReservation=newDate) newReserve.save() msg = "Reservado de: " + lastDate.strftime( '%d-%b-%y') + " a " + newDate.strftime('%d-%b-%y') existBook.reserved = True existBook.save() return msg
def insertRent(): rent = Rent(client_id=1, book_id=1, dateReservation=datetime(2020, 10, 11)) rent.save() rent1 = Rent(client_id=1, book_id=2, dateReservation=datetime(2020, 10, 11)) rent1.save() rent2 = Rent(client_id=1, book_id=3, dateReservation=datetime(2020, 10, 11)) rent2.save()
class FangtianxiaRentPipeline(object): def __init__(self): self.session = DBSession() def process_item(self, item, spider): # 写入小区房价 if isinstance(item, FangtianxiaRentItem): db_house = self.session.query(House).filter( House.house_name == item['name']).filter( House.city_name == item['city_name']).first() if db_house: if db_house.property_corp == u'暂无数据': db_house.property_corp = item['property_corp'] if db_house.developers == u'暂无数据': db_house.developers = item['developers'] if db_house.building_date == u'暂无数据': db_house.building_date = item['building_date'] if db_house.building_date == u'暂无数据': db_house.building_date = item['building_date'] # 需要添加判断, 以防同一个价格数据插入多次 p = Price(price=item['price'], origin=item['origin'], months=item['months'], crawl_time=item['crawl_date'], uid=db_house.id) db_house.price.append(p) else: house = House(house_name=item['name'], city_name=item['city_name'], url=item['url'], latitude=item['latitude'], longitude=item['longitude'], address=item['location'], building_date=item['building_date'], building_type=item['building_type'], property_corp=item['property_corp'], developers=item['developers'], district=item['district']) price = Price(price=item['price'], origin=item['origin'], months=item['months'], crawl_time=item['crawl_date']) house.price.append(price) self.session.add(house) try: self.session.commit() except Exception, e: print e self.session.rollback() return item # 写入小区租金 elif (isinstance(item, RentItem)): h_id = item['h_id'] house = self.session.query(House).filter(House.id == h_id).first() print house.id rent = Rent(rent_price=item['rent_price'], rent_origin=item['origin'], publish_date=item['publish_time'], rent_crawl_time=item['crawl_date'], rent_type=item['rent_type'], house_type=item['house_type'], rent_floor=item['floor'], rent_url=item['url'], rent_title=item['title'], rent_area=item['area']) house.rent_info.append(rent) self.session.add(house)
def test_company(self): my_company = Company() #Creating Bikes for i in range(17): my_company.add_bike(i) #Creating Rents my_company.add_rent(15,"hours",1) my_company.add_rent(15,"days",2) my_company.add_rent(15,"weeks",3) #Creating Promotions my_company.add_promotion([Rent(10,"hours",4),Rent(10,"hours",5),Rent(10,"hours",6),Rent(5,"hours",7)]) my_company.add_promotion([Rent(10,"days",11),Rent(10,"days",10),Rent(10,"days",9),Rent(5,"days",8)]) my_company.add_promotion([Rent(10,"weeks",12),Rent(10,"weeks",13),Rent(10,"weeks",14),Rent(5,"weeks",15)]) my_company.add_promotion([Rent(10,"hours",18),Rent(10,"days",17),Rent(10,"weeks",16)]) #Verify coverage self.assertLess(85, my_company.coverage())
def create_rent(): json = request.get_json() Rent.create(json['renter'], json['tile'], json['crop']) return jsonify({'status': 'success'})