def _process_new_sites_chunked(domains_ranked: dict) -> None: for domain in domains_ranked.keys(): site = models.Site(domain=str(domain), current_rank = domains_ranked[domain]) db_session.add(site) logger.debug("Adding site: {}".format(domain)) db_session.commit() logger.info("New site chunk updated")
def _process_new_site(domain: bytes, new_rank: int) -> None: site = db_session.query(models.Site).filter_by(domain=domain).first() if site: site.current_rank = new_rank else: site = models.Site(domain=str(domain), current_rank=new_rank) db_session.add(site) logger.debug("Adding site: {}".format(domain)) db_session.commit()
def _seed_sites(filename): with open(filename, 'r') as file: csv_reader = csv.DictReader(file) for row in csv_reader: site = models.Site(current_rank=int(row['rank']), domain=row['site']) db_session.add(site) db_session.commit()