# 3 - create a new session session = Session() # 4 - create movies bourne_identity = Movie('The Bourne Identity', date(2002, 10, 11)) furious_7 = Movie('Furious 7', date(2015, 4, 2)) pain_and_gain = Movie('Pain & Gain', date(2013, 8, 23)) # 5 - creates actors matt_damon = Actor('Matt Damon', date(1970, 10, 8)) dwayne_johnson = Actor('Dwayne Johnson', date(1972, 5, 2)) mark_wahlberg = Actor('Mark Wahlberg', date(1971, 6, 5)) # 6 - add actors to movies bourne_identity.actors = [matt_damon] furious_7.actors = [dwayne_johnson] pain_and_gain.actors = [dwayne_johnson, mark_wahlberg] # 7 - add contact details to actors matt_contact = ContactDetails('415 555 2671', 'Burbank, CA', matt_damon) dwayne_contact = ContactDetails('423 555 5623', 'Glendale, CA', dwayne_johnson) dwayne_contact_2 = ContactDetails('421 444 2323', 'West Hollywood, CA', dwayne_johnson) mark_contact = ContactDetails('421 333 9428', 'Glendale, CA', mark_wahlberg) # 8 - create stuntmen matt_stuntman = Stuntman('John Doe', True, matt_damon) dwayne_stuntman = Stuntman('John Roe', True, dwayne_johnson) mark_stuntman = Stuntman('Richard Roe', True, mark_wahlberg)
#create movies movie_1 = Movie("Movie 1 Name", date(2018, 8, 28)) movie_2 = Movie("Movie 2 Name", date(2006, 8, 22)) movie_3 = Movie("Movie 3 Name", date(2008, 1, 12)) movie_4 = Movie("Movie 4 Name", date(2014, 8, 8)) movie_5 = Movie("Movie 5 Name", date(2010, 12, 1)) #create actors actor_1 = Actor("Actor 1 Name", date(1950, 8, 28)) actor_2 = Actor("Actor 2 Name", date(1960, 8, 22)) actor_3 = Actor("Actor 3 Name", date(1970, 1, 12)) actor_4 = Actor("Actor 4 Name", date(1980, 8, 8)) actor_5 = Actor("Actor 5 Name", date(1990, 12, 1)) #add actors to movies movie_1.actors = [actor_1] movie_2.actors = [actor_2] movie_3.actors = [actor_3] movie_4.actors = [actor_4] movie_5.actors = [actor_5, actor_1] #add contact details to actors actor_1_contact = ContactDetails("12 1234 1234", "Address 1", actor_1) actor_2_contact = ContactDetails("12 1234 1234", "Address 2", actor_2) actor_3_contact = ContactDetails("12 1234 1234", "Address 3", actor_3) actor_4_contact = ContactDetails("12 1234 1234", "Address 4", actor_4) actor_5_contact = ContactDetails("12 1234 1234", "Address 5", actor_5) #create stuntmen actor_1_stuntman = Stuntman("Stuntman 1", True, actor_1) actor_2_stuntman = Stuntman("Stuntman 2", True, actor_2)
Base.metadata.create_all(engine) session = Session() #create movies bourne_identity = Movie('The Bourne Identity', date(2002, 10, 11)) furious_7 = Movie('Furious 7', date(2001, 10, 2)) # create actors matt_damon = Actor('Matt Damon', date(1970, 10, 8)) dwayne_johnson = Actor('Dwayne Johnson', date(1972, 10, 10)) #adding actors to movie bourne_identity.actors = [matt_damon] furious_7.actors = [dwayne_johnson, matt_damon] matt_contact = ContactDetails('23-12323', 'kathmandu', matt_damon) dwayne_contact = ContactDetails('234-125545', 'lalitpur', dwayne_johnson) dwayne_contact2 = ContactDetails('234-125545', 'chabahil', dwayne_johnson) matt_stuntman = StuntMan('John Doe', True, matt_damon) dwayne_stuntman = StuntMan('John Roe', True, dwayne_johnson) session.add(bourne_identity) session.add(furious_7) session.add(matt_contact) session.add(dwayne_contact) session.add(dwayne_contact2)
# ui-slide-content tags = soup.find_all('li', class_="ui-slide-item") movies = [] for tag in tags: # print("=========================") # print(tag) # soup.select('li[data-actors]') # print(tag.li) movie = Movie() # 主演 movie.actors = tag.attrs['data-actors'] # 导演 movie.director = tag.attrs['data-director'] # 时长 movie.duration = tag.attrs['data-duration'] # 豆瓣评分 movie.rate = tag.attrs["data-rate"] # 发布地区 movie.region = tag.attrs["data-region"] # 发布时间 movie.release = tag.attrs["data-release"] # 电影名称 movie.title = tag.attrs["data-title"] # 相关视频地址 movie.trailer = tag.attrs["data-trailer"] # 电影封面
# Create movies born_funny = Movie("Born Looking Funny", date(200, 12, 2)) catchy = Movie("Catchy Catchy Cats", date(2012, 3, 16)) making_soda = Movie("Cooking Baking Soda", date(2003, 10, 30)) # Create actors skim_phew = Actor("Skim Phew", date(2000, 6, 9)) stop_theft = Actor("Stop Theft", date(1999, 10, 10)) short_face = Actor("Short Face", date(2004, 2, 29)) longer_nose = Actor("Longer Nose", date(1999, 4, 20)) # Add actors to movies born_funny.actors = [skim_phew] catchy.actors = [short_face] making_soda.actors = [short_face, longer_nose, stop_theft] # Add contact details to actors skim_contact = ContactDetails("29 29 29", "Front Street 3", skim_phew) stop_contact = ContactDetails("42 40 65 44", "Cool Desert 96", stop_theft) short_contact = ContactDetails("47 85 03 64", "Empty Waters 32", short_face) longer_contact = ContactDetails("84 43 58 00", "Empty Waters 32", longer_nose) stop_contact1 = ContactDetails("92 84 83 54", "Hidden Houses 54", stop_theft) # Create stuntman skim_stunt = Stuntman("Jumping Tree", True, skim_phew) stop_stunt = Stuntman("Fallen Roof", True, stop_theft)