Suffix

py

School

Stony Brook University *

*We aren’t endorsed by this school

Course

114

Subject

Computer Science

Date

Jan 9, 2024

Type

py

Pages

2

Uploaded by MinisterScience5603

Report
import os import re from sqlalchemy import and_, func from sqlalchemy import create_engine, Column, Integer, String, func from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker DATABASE_URL = "sqlite:///sites_crawled(123).db3" Base = declarative_base() # SitesCrawled Table class SitesCrawled(Base): __tablename__ = 'sites_crawled' id = Column(Integer, primary_key=True) site = Column(String(1024)) # DoctorScrapedInfo Table class DoctorScrapedInfo(Base): __tablename__ = 'scraped_doctors_info' id = Column(Integer, primary_key=True) site_crawled_id = Column(Integer, nullable=False) site = Column(String(1024), nullable=False) website = Column(String(1024)) name = Column(String(1024)) title = Column(String(1024)) first_name = Column(String(1024)) middle_name = Column(String(1024)) last_name = Column(String(1024)) personal_suffix = Column(String(1024)) clinical_suffix = Column(String(1024)) specialty = Column(String(1024)) university = Column(String(1024)) street = Column(String(1024)) street_internal = Column(String(1024)) city = Column(String(1024)) state = Column(String(1024)) zip_code = Column(String(1024)) phone_number = Column(String(1024)) # MultipleAddresses Table class MultipleAddresses(Base): __tablename__ = 'multiple_addresses' id = Column(Integer, primary_key=True, autoincrement=True) # Auto-incrementing id doctor_scraped_info_id = Column(Integer, nullable=False) street = Column(String(1024)) street_internal = Column(String(1024)) city = Column(String(1024)) state = Column(String(1024)) zip_code = Column(String(1024)) phone_number = Column(String(1024)) # Setting up the connection and session engine = create_engine(DATABASE_URL) Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine) session = Session() suffixes = ["DDS", "OD", "PsyD", "RNP", "DMD"] for doctor in session.query(DoctorScrapedInfo).all(): # Checking if the last name contains any of the suffixes for suffix in suffixes: if doctor.last_name and suffix in doctor.last_name: # Striping out the suffix from the last name and place it in the clinical_suffix column doctor.last_name = doctor.last_name.replace(suffix, "").strip() doctor.clinical_suffix = suffix # Moving the information from the middle_name column to the last_name column if doctor.middle_name: doctor.last_name = doctor.middle_name doctor.middle_name = None break session.commit()
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help