Skip to content

Kate-Branch #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 58 additions & 0 deletions App/controllers/testingfunctions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

apiKey = 'AIzaSyAa3sah23VK9X4r0hxsC4xHvWTUeLurpv8'
youtube = build('youtube', 'v3', developerKey=apiKey)

class Video:
def __init__(self, title, image_url, video_url, description, video_id):
self.title = title
self.image_url = image_url
self.video_url = video_url
self.description = description
self.video_id = video_id


def get_video_url(video_id):
return f"https://www.youtube.com/watch?v={video_id}"

def search_by_keyword(api_key, keyword, max_results):
youtube = build("youtube", "v3", developerKey=api_key)

try:
request = youtube.search().list(
part="id,snippet",
q=keyword,
maxResults=max_results
)
response = request.execute()
videos = []
if "items" in response:
for item in response["items"]:
if item["id"].get("kind") == "youtube#video":
video_id = item["id"]["videoId"]
video_url = get_video_url(video_id)
title = item["snippet"]["title"]
image = item["snippet"]["thumbnails"]["default"]["url"]
description = item["snippet"]["description"]
video = Video(title, image, video_url, description, video_id)
videos.append(video)
else:
print("This item is not a video.")
else:
print("No videos found.")

except HttpError as e:
print("An HTTP error occurred:")
print(e.content)

return videos

def home():
videos = search_by_keyword("AIzaSyAa3sah23VK9X4r0hxsC4xHvWTUeLurpv8", "fitness", 30)
print(videos)

home()



52 changes: 52 additions & 0 deletions App/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from flask_cors import CORS
from werkzeug.utils import secure_filename
from werkzeug.datastructures import FileStorage
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError

from App.database import init_db
from App.config import load_config
Expand All @@ -15,6 +17,14 @@

from App.views import views

class Video:
def __init__(self, title, image_url, video_url, description, video_id):
self.title = title
self.image_url = image_url
self.video_url = video_url
self.description = description
self.video_id = video_id

def add_views(app):
for view in views:
app.register_blueprint(view)
Expand All @@ -38,3 +48,45 @@ def custom_unauthorized_response(error):
app.app_context().push()
return app

def get_video_url(video_id):
return f"https://www.youtube.com/watch?v={video_id}"

def search_by_keyword(api_key, keyword, max_results):
youtube = build("youtube", "v3", developerKey=api_key)

try:
request = youtube.search().list(
part="id,snippet",
q=keyword,
maxResults=max_results
)
response = request.execute()
videos = []
if "items" in response:
for item in response["items"]:
if item["id"].get("kind") == "youtube#video":
video_id = item["id"]["videoId"]
video_url = get_video_url(video_id)
title = item["snippet"]["title"]
image = item["snippet"]["thumbnails"]["default"]["url"]
description = item["snippet"]["description"]
video = Video(title, image, video_url, description, video_id)
videos.append(video)
else:
print("This item is not a video.")
else:
print("No videos found.")

except HttpError as e:
print("An HTTP error occurred:")
print(e.content)

return videos

app = create_app() # Create the app object

@app.route('/home')
def home():
videos = search_by_keyword("AIzaSyAa3sah23VK9X4r0hxsC4xHvWTUeLurpv8", "fitness", 30)
return render_template('index.html', videos=videos)

22 changes: 22 additions & 0 deletions App/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String, nullable=False, unique=True)
password = db.Column(db.String(120), nullable=False)
height = db.Column(db.Double, nullable=True)
weight = db.Column(db.Double, nullable=True)
videos = db.relationship('Video', backref='user', lazy=True, cascade="all, delete-orphan")

def __init__(self, username, password):
self.username = username
Expand All @@ -24,3 +27,22 @@ def check_password(self, password):
"""Check hashed password."""
return check_password_hash(self.password, password)

class Video(db.Model):
id = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
title = db.Column(db.String(120))
image = db.Column(db.String(120))
description = db.Column(db.String(120))
url = db.Column(db.String(120))

def __init__(self, title, image, description, url, user_id):
self.title = title
self.image = image
self.description = description
self.url = url
self.user_id = user_id





148 changes: 148 additions & 0 deletions App/static/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/* Index CSS */
.search-bar {
margin-bottom: 10px;
overflow: hidden;
}

.search-bar input[type="text"] {

float: left;
}

.search-bar button {
float: right;
}

/* Side menu (index.html) */
.vertical-menu {
/* Your side menu styling */
width: 200px;
float: left;
background-color: #f8f9fa;
border-right: 1px solid #ccc;
}

.vertical-menu a {
display: block;
padding: 10px;
text-decoration: none;
}

/* active link (index.html) */
.vertical-menu a.active {
background-color: #ccc;
}

/* Grid menu contents (index.html) */
.grid-container {
overflow: hidden;
}

.grid-item {

background-color: #f0f0f0;
padding: 20px;
text-align: center;
float: left;
width: calc(33.33% - 20px);
margin: 10px;
box-sizing: border-box;
}

/* Logo CSS*/


/*Profile CSS*/

.emp-profile{
padding: 3%;
margin-top: 3%;
margin-bottom: 3%;
border-radius: 0.5rem;
background: #fff;
}
.profile-img{
text-align: center;
}
.profile-img img{
width: 70%;
height: 100%;
}
.profile-img .file {
position: relative;
overflow: hidden;
margin-top: -20%;
width: 70%;
border: none;
border-radius: 0;
font-size: 15px;
background: #212529b8;
}
.profile-img .file input {
position: absolute;
opacity: 0;
right: 0;
top: 0;
}
.profile-head h5{
color: #333;
}
.profile-head h6{
color: #0062cc;
}
.profile-edit-btn{
border: none;
border-radius: 1.5rem;
width: 70%;
padding: 2%;
font-weight: 600;
color: #6c757d;
cursor: pointer;
}
.proile-rating{
font-size: 12px;
color: #818182;
margin-top: 5%;
}
.proile-rating span{
color: #495057;
font-size: 15px;
font-weight: 600;
}
.profile-head .nav-tabs{
margin-bottom:5%;
}
.profile-head .nav-tabs .nav-link{
font-weight:600;
border: none;
}
.profile-head .nav-tabs .nav-link.active{
border: none;
border-bottom:2px solid #0062cc;
}
.profile-work{
padding: 14%;
margin-top: -15%;
}
.profile-work p{
font-size: 12px;
color: #818182;
font-weight: 600;
margin-top: 10%;
}
.profile-work a{
text-decoration: none;
color: #495057;
font-weight: 600;
font-size: 14px;
}
.profile-work ul{
list-style: none;
}
.profile-tab label{
font-weight: 600;
}
.profile-tab p{
font-weight: 600;
color: #0062cc;
}
50 changes: 44 additions & 6 deletions App/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,50 @@
{% block title %}Flask MVC App{% endblock %}
{% block page %}Flask MVC App{% endblock %}

{{ super() }}

{% block content %}
<h1>Flask MVC</h1>
<h1>TBD Workout Planner</h1>
{% if is_authenticated %}
<p> Welcome {{current_user.username}} </p>
<p>Welcome {{ current_user.username }}</p>
{% endif %}
<p>This is a boileplate flask application which follows the MVC pattern for structuring the project.</p>
{% endblock %}
<p>This is a boilerplate Flask application which follows the MVC pattern for structuring the project.</p>

<div class="search-bar">
<!-- search bar -->
<form action="/search" method="GET">
<input type="text" name="keyword" placeholder="Search...">
<button type="submit">Search</button>
</form>
<div class="clearfix"></div>
</div>

<div class="main-container">


<div class="grid-container">
<!-- YouTube videos go here -->
{% for video in videos %}
<div class="grid-item">
<div class="card">
<div>
<img src="{{video.image_url}}">
</div>
<div class="card-body">
<h6 class="card-title">{{ video.title }}</h6>
<p class="card-text">{{ video.description }}</p>
<a href="{{ video.video_url }}" class="btn btn-primary">Watch Video</a>
{% if is_authenticated %}
<form action="/add" method="POST">
<input type="hidden" name="title" value="{{ video.title }}">
<input type="hidden" name="image" value="{{ video.image_url }}">
<input type="hidden" name="description" value="{{ video.description }}">
<input type="hidden" name="url" value="{{ video.video_url }}">
<button type="submit" class="btn btn-primary">Add to Playlist</button>
</form>
{%endif%}
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endblock %}
Loading