Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Miscellaneous
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
practice problem folder
Miscellaneous
Commits
78a04f6d
Commit
78a04f6d
authored
1 month ago
by
Duncan Holmes
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
cfa97c66
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
lab on ORM/movies_installer.py
+108
-0
108 additions, 0 deletions
lab on ORM/movies_installer.py
with
108 additions
and
0 deletions
lab on ORM/movies_installer.py
0 → 100644
+
108
−
0
View file @
78a04f6d
from
shlex
import
quote
from
sys
import
stderr
from
datetime
import
date
from
sqlalchemy.exc
import
SQLAlchemyError
from
movies
import
MovieDatabase
,
Movie
,
Genre
,
Review
from
sqlalchemy.sql
import
text
def
add_starter_data
(
session
):
biography
=
Genre
(
name
=
'
Biography
'
)
drama
=
Genre
(
name
=
'
Drama
'
)
history
=
Genre
(
name
=
'
History
'
)
action
=
Genre
(
name
=
'
Action
'
)
adventure
=
Genre
(
name
=
'
Adventure
'
)
sci_fi
=
Genre
(
name
=
'
SciFi
'
)
session
.
add
(
biography
)
session
.
add
(
drama
)
session
.
add
(
history
)
session
.
add
(
action
)
session
.
add
(
adventure
)
session
.
add
(
sci_fi
)
# Hidden Figures (Biography, Drama, History)
# 2016 October 15
# Budget: $25,000,000
# Gross Revenue: $206,000,000
# Sample review from IMDB:
# "★★★★★★★★★☆ In the opinion of this reviewer, an extraordinary achievement."
hidden_figures
=
Movie
(
title
=
'
Hidden Figures
'
,
budget
=
25000000
,
gross_revenue
=
206000000
,
opening_date
=
date
(
2016
,
10
,
15
),
genres
=
[
biography
,
drama
,
history
])
session
.
add
(
hidden_figures
)
extraordinary_achievement
=
Review
(
movie
=
hidden_figures
,
score
=
9
,
comments
=
'
In the opinion of this reviewer, an extraordinary achievement.
'
)
session
.
add
(
extraordinary_achievement
)
# Avengers: Infinity War (Action, Adventure)
# 2018 April 27
# Budget: $300,000,000
# Gross Revenue: $2,048,000,000
# Sample reviews from IMDB:
# "★★★★★★★★★★ A summer film that IS even better than the hype."
# "★★★★★★☆☆☆☆ Bordering on a comedy, "Infinity War" is overhyped, lacked direction, but at times impressed."
infinity_war
=
Movie
(
title
=
'
Avengers: Infinity War
'
,
budget
=
300000000
,
gross_revenue
=
2048000000
,
opening_date
=
date
(
2018
,
4
,
27
),
genres
=
[
action
,
adventure
])
session
.
add
(
infinity_war
)
better_than_hype
=
Review
(
movie
=
infinity_war
,
score
=
10
,
comments
=
'
A summer film that IS even better than the hype.
'
)
bordering_on_comedy
=
Review
(
movie
=
infinity_war
,
score
=
6
,
comments
=
'
Bordering on a comedy,
"
Infinity War
"
is overhyped, lacked direction, but
'
'
at times impressed.
'
)
session
.
add
(
better_than_hype
)
session
.
add
(
bordering_on_comedy
)
def
main
():
try
:
url
=
(
MovieDatabase
.
construct_mysql_url
(
'
localhost
'
,
3306
,
'
movies
'
,
'
root
'
,
#roh moment. I HATE EVERY LAB CREATED ON MY LIFE.
#MAY THE NEXT GENERATION NOT KNOW MY FURY
#MAY THE CONSTRUCTOR OF THIS BULL SUFFER WITH RETRIBUTION
# since i'm using @ & % which are specail cahracters you have to encode them
# good thing NOBODY TOLD ME THAT .
'
FunNyMeMe123!%40%23
'
))
movie_database
=
MovieDatabase
(
url
)
movie_database
.
ensure_tables_exist
()
"""
session_reviews = movie_database.create_session()
session_reviews.execute(text(
"
DROP TABLE IF EXISTS reviews
"
))
session_reviews.commit()
session_reviews.close()
session_movie_genres = movie_database.create_session()
session_movie_genres.execute(text(
"
DROP TABLE IF EXISTS movie_genres
"
))
session_movie_genres.commit()
session_movie_genres.close()
session_genres = movie_database.create_session()
session_genres.execute(text(
"
DROP TABLE IF EXISTS genres
"
))
session_genres.commit()
session_genres.close()
session_movies = movie_database.create_session()
session_movies.execute(text(
"
DROP TABLE IF EXISTS movies
"
))
session_movies.commit()
session_movies.close()
"""
print
(
'
Tables created.
'
)
session_movies
=
movie_database
.
create_session
()
add_starter_data
(
session_movies
)
session_movies
.
commit
()
print
(
'
Records created.
'
)
except
SQLAlchemyError
as
exception
:
print
(
'
Database setup failed!
'
,
file
=
stderr
)
print
(
f
'
Cause:
{
exception
}
'
,
file
=
stderr
)
exit
(
1
)
if
__name__
==
'
__main__
'
:
main
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment