def setUp(self): create_engine('sqlite:///:memory:?check_same_thread=False', echo=True) create_schema() session = Session() self.user = User("username", "password", "fullname", "*****@*****.**", "5555555555", "5555555556") session.add(self.user) session.commit()
def setUp(self): create_engine('sqlite:///:memory:?check_same_thread=False', echo=True) create_schema() session = Session() self.user = User("username", "password", "fullname", "*****@*****.**", "5555555555", "5555555556") session.add(self.user) session.commit()
def setUp(self): create_engine('sqlite:///:memory:?check_same_thread=False', echo=True) create_schema() time = datetime.now() self.timeStr = time.strftime('%Y-%m-%d %H:%M:%S') session = Session() self.appointment = Appointment(1, 'Test Appointment 1', self.timeStr, self.timeStr) session.add(self.appointment) session.commit()
def setUp(self): create_engine('sqlite:///:memory:?check_same_thread=False', echo=True) create_schema() time = datetime.now() self.timeStr = time.strftime('%Y-%m-%d %H:%M:%S') session = Session() self.appointment = Appointment(1, 'Test Appointment 1', self.timeStr, self.timeStr) session.add(self.appointment) session.commit()
def parse_house_page(self, house_url): content = self.client.get_content(house_url) if not content: return soup = BeautifulSoup(content) rent_house = RentHouse() rent_house.title = soup.html.head.title.string.strip() rent_house.source = 1 # 1:58 rent_house.url = house_url rent_house.city = self.city price_list = soup.findAll('div', {'class': 'house-pay-way f16'}) rent_house.price = int(price_list[0].findAll( 'b', {'class': 'f36'})[0].string) info_list = soup.find('ul', {'class': 'f14'}).findAll('li') for info in info_list: if str(info).find('租赁方式') != -1: rent_house.rent_type = info.findAll('span')[1].string elif str(info).find('房屋类型') != -1: rent_house.house_type = info.findAll('span')[1].string elif str(info).find('所在小区') != -1: rent_house.house_name = info.findAll('span')[1].a.string time_pattern = '\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}' rent_house.update_time = re.search( time_pattern, str(soup.find('p', {'class': 'house-update-info c_888 f12'}))).group(0) rent_house.description = '.'.join( soup.find('ul', { 'class': 'introduce-item' }).findAll(text=True)).replace(' ', '') db_session = Session() try: db_session.add(rent_house) db_session.flush() db_session.commit() except Exception, e: pass