def insert(self, ad: Ad): cursor = self.db.cursor() cursor.execute( '''REPLACE INTO ads( id, title, url, description, postedTime, price, rooms, isNothingIncluded, score, isLate, isBasement, isWasherMentioned, closestMetro, closestMetroDistance ) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', (ad.get_id(), ad.get_title_components()[0], ad.get_url(), ad.get_description(), int( datetime.strptime( ad.get_posted_date(), '%Y-%m-%d %H:%M:%S').timestamp()), ad.get_price(), ad.get_size(), ad.is_nothing_included(), ad.get_score(), ad.is_too_late(), ad.is_basement(), ad.is_washer_mentioned(), ad.get_closest_station()[0], ad.get_closest_station()[1])) self.db.commit()
def write_csv(self, ad: Ad): metro = ad.get_closest_station() self.writer.writerow({ 'id': ad.get_id(), 'url': ad.get_url(), 'has_washer': 'yes' if ad.is_washer_mentioned() else 'no', 'metro station': metro[0], 'metro distance': metro[1], 'title': ad.get_title_components()[0], 'score': ad.get_score(), 'price': ad.get_price(), 'date': ad.get_posted_date() })