Data Structure Write Up
Collections
-
Blog Python API code and use of List and Dictionaries.
-
This is code that initializes our own database to store the images
def initSongs():
with app.app_context():
db.create_all()
songs_data = [
{'name': 'FEIN', 'url': '/audios/FEIN.mp3', 'description': 'Travis Scott_', 'uri': 'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBxAOEg8PDw8VFREQEBAQERIWEBAVEBUSFRUWFhUVExgZHSggGBomGxcWITEtMSkrLi4yFx8zODMtNyk5LisBCgoKDg0NFRAQFi0eHR0tLSstLSstLS0rKy0rLSsrLSsrKysrLS0tLS0tLS0tLS0tNysrLS0tNy0rLS03LSsrK//AABEIAOEA4QMBIgACEQEDEQH/xAAcAAEAAQUBAQAAAAAAAAAAAAAABQECAwQGBwj/xAA9EAACAQMCAwcABgYLAQAAAAAAAQIDESEEEgUxQQYTIlFhcYEUMpGhsdEHQlLB4fAjM1NicpKToqPS8Rb/xAAXAQEBAQEAAAAAAAAAAAAAAAAAAQID/8QAHBEBAQEAAgMBAAAAAAAAAAAAAAEREkECITFR/9oADAMBAAIRAxEAPwDxMAFUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVSvZLm3ZF7p7W1Lna/zbCMZk3XSVsq/2eQFokg15CQFoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAFUygAuDKBAUAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAVCACKzjZlpnqRuk+qMAUAAAAAAAAAMkKMpZS/ADGDK9NNZ2P4V/wMbVsMCgAAAAAAAAAAAAAAAAAAAAAVKFQNjTtcmXa3SuFpLk8P0ZhguR02m06r0tr6pr13Iiz25QGTUUXTlKEucXb+JjKgAAABUAZ6M7dL/BgsZ47oxUk2pX6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RIuKyqUFygUBm0ekqV5d3Sg5Tcak9qtfbThKc3nyjGT+DZpcE1M9u2hJ7p6emsxS36iHeUVl43RyBHg3J8K1EYqbpNRlShXjmN5Upz7uMoq95XnjGTFrNDVoNKrBxbdSKvbnTk4TWPKSa+ANcAAAAAAAAAAAAAAAAFTY0lGMpf0ktsVl2+s/ReQGukd7wDT0aGiTrxU4ajc3DdOF2lZuTi08bkl7S53OOr14KVqa8CthopGvKKcdz2yd4vyd0/z+0hK9o7P9sZ1dPrqDlFWh3jqwioz22alCUXe7tFPcr4ksWV35BX19SN0qkbQbsn4pNtO+Grc2+fXLNTT6xwVRXxNWasld2lFXt6SkYKNRwanG14vF1fz+AanqPFa219/HFvC793N38Lh4Pq3XWyxjqRGvk3Pfs2KUYtLo/CrtNc/wCJjU8rx2u919t9rbzueL4zi6z6ss71rck/C8Wa6Lli7s/nBUU3Sd+efdiK5/zn+blrK2tz8k182/dcC4FAAAAV6B+ibhtPUPVuWnVaUZ6CC8Lk40alfbqeXR0d6fuek0ez0bprSO0fptTc6U09+mnSp6S3LMVOSg/Knh9X8/8ADNWqFWFWVKFVRU13c0nB7oSirpp8r3+ESVPtBTUnJ6DTO+1W7uG3wt2xt8mk/OxEe1cQ7O0k0qWibcIcWhGX0aolFae09JGDcfDFTfh/aabW61zmf0o8DhR4dHUSoqM3U0EovY1KM61KpPU5fWU0m/VHnWm49Tp0o0voGnlJQ2upKnF1Hmnm+3n4H/nkaXF+Ix1Dg46elRUE1anCMd2Iq8rJXePvYGgACgAAoAAAAAAAAAANvhf9YvZmDU817AAYzL+p8oqAjCEAAAABl9X9X/BH8AALQAAAAVQAAAAEAAB//9k=', 'tokens':'1'},
{'name':'Creepin', 'url':'/audios/CREEP.mp3', 'description':'The Weeknd', 'uri':'https://i1.sndcdn.com/artworks-sWl8wb2Zk1xthx3m-39RYRQ-t500x500.jpg', 'tokens':'2'},
{'name':'Role Model', 'url':'', 'description':' Brent Fiaiyaz', 'uri':'https://i1.sndcdn.com/artworks-O2SRR9SCgyRq4u4v-eAojjA-t500x500.jpg', 'tokens':'4'},
{'name':'Right my Wrongs', 'url':'', 'description':' Bryson Tiller', 'uri':'https://i.scdn.co/image/ab67616d0000b273d5f3cea8affdca01a0dc754f', 'tokens':'5'},
{'name':'Roar', 'url':'', 'description':' Katy Perry', 'uri':'https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcT_Y92S1N976xSO57PbyPinyoJ8IVnqGPFhLQ&usqp=CAU', 'tokens':'6'},
{'name':'Shake it Off', 'url':'/audios/SHAKE.mp3', 'description':' Taylor Swift', 'uri':'https://pyxis.nymag.com/v1/imgs/2d9/6f5/3f8dbd63613637b7843e4653ff548503b9-tay--.w710.jpg', 'tokens':'9'},
{'name':'Often', 'url':'/audios/OFTEN.mp3', 'description':' The Weeknd_', 'uri':'https://cdns-images.dzcdn.net/images/cover/eea9f7fc913300e40307a0ff70dc73cf/350x350.jpg', 'tokens':'8'},
{'name':'Thank God', 'url':'', 'description':' Travis Scott', 'uri':'data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAkGBw0NDQ0NDg0NDQ0NDQ4NDQ0ODQ8ODQ0OFhEWFhURFRUYHSghGBomGxUVITEhJSkrLi4uFx8zODMwNygtLysBCgoKDg0OFxAQFy0eHR0rKy0rKy0tLS0rKy0rLS0rLS0tLSstLS0tLS0tLS0tLSstLS0rLTctLSstLS0tLSs3K//AABEIAOEA4QMBIgACEQEDEQH/xAAbAAEBAAIDAQAAAAAAAAAAAAAAAQMFAgQGB//EAD0QAAICAQMCBAMEBggHAAAAAAABAgMRBBIhBTETQVFhBiJxMkJSgRQjkbHR8AczYnKCk6HBFRZDVKKy0v/EABcBAQEBAQAAAAAAAAAAAAAAAAABAgP/xAAcEQEBAQACAwEAAAAAAAAAAAAAARESQQIhMVH/2gAMAwEAAhEDEQA/APigAKoAQCgAAAAAAAAACFIUAAQCgEAFAAAAAAAAAAAAAQAAUAAAAAAAAAAAAAAAAhQABAK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qCmnVak657oOPzLHK5z+Rs18RQTjJdP0SlFLD8OPOOIv7Pol+fPsQfZuofD9aWKdE3OEesUwl+iYjCFKlZpFFuviMbFXtTTUnn7eFI81/Sf0WFXSI6mVEIWyu6c4vwtk6526eyepWcfesWX7nzzS/EEKqY1f8P0M5KLi7Z1Rc38kI98f2W/PmUvU6PVOoLUOGKKaFBf9KKTl+rrhmWEst+G5N+s5AdEAFVSAAAABSAAUEAFBAB2+l/1q+jMGo7r6AAYzM/6v/EgAjCEABCgAGcp91/dh/6IACFIAKQAAAABAAoAAj//2Q==', 'tokens':'9'},
{'name':'God Did ', 'url':'', 'description':' DJ Khalid', 'uri':'https://upload.wikimedia.org/wikipedia/en/0/0a/DJ_Khaled_-_God_Did.png', 'tokens':'10'},
{'name':'Badtameez Dil', 'url':'', 'description':' Yeh Jawaani Hai Deewani', 'uri':'https://m.media-amazon.com/images/M/MV5BNWIxZWU1YzAtYTc4NS00NTM4LWJmODgtYzEwNTE0NmJiYzI4XkEyXkFqcGdeQXVyODk2ODI3MTU@._V1_UX200_CR0,0,200,200_AL_.jpg', 'tokens':'11'},
{'name':'Same Old Love', 'url':'', 'description':' Selena Gomez', 'uri':'https://upload.wikimedia.org/wikipedia/en/b/b3/Same_Old_Love_by_Selena_Gomez.png', 'tokens':'12'},
{'name':'Waka Waka ', 'url':'', 'description':' Shakira', 'uri':'https://photos.prnewswire.com/prnfull/20100901/NY58538-a', 'tokens':'13'},
{'name':'Swim', 'url':'', 'description':' Chase Atlantic ', 'uri':'https://i.ytimg.com/vi/ykP640XEjSQ/maxresdefault.jpg', 'tokens':'14'},
{'name':'Fireside', 'url':'', 'description':' Arctic Monkeys', 'uri':'https://i.ytimg.com/vi/PG8yTUeptFU/maxresdefault.jpg', 'tokens':'15'},
{'name':'Daddy Issues', 'url':'', 'description':' The Neighborhood', 'uri':'https://i.scdn.co/image/ab67616d0000b2733066581d697fbdee4303d685', 'tokens':'16'},
{'name':'Art Deco', 'url':'', 'description':'Lana Del Rey ', 'uri':'https://i1.sndcdn.com/artworks-000144834419-kkxrj8-t500x500.jpg', 'tokens':'17'},
{'name':'The Color Violet', 'url':'/audios/COLOR.mp3', 'description':' Tory Lanez ', 'uri':'https://i1.sndcdn.com/artworks-XTdw6XGAR3WX-0-t500x500.jpg', 'tokens':'18'},
{'name':'Light it Up', 'url':'', 'description':' Major Lazer', 'uri':'https://i.ytimg.com/vi/r2LpOUwca94/maxresdefault.jpg', 'tokens':'19'},
{'name':'Maneater', 'url':'', 'description':' Nelly Furtado ', 'uri':'https://upload.wikimedia.org/wikipedia/en/5/56/Maneater_%28Nelly_Furtado_single_-_cover_art%29.png', 'tokens':'20'},
{'name':'Dark Horse', 'url':'', 'description':' Katy Perry ', 'uri':'https://static.independent.co.uk/s3fs-public/thumbnails/image/2014/02/26/10/katy-perry-dark-horse-v2.jpg', 'tokens':'21'},
{'name':'Watch', 'url':'', 'description':' Billie Eilish ', 'uri':'https://thomasbleach.files.wordpress.com/2017/07/billie.jpg', 'tokens':'22'},
{'name':'Eyes Without Face', 'url':'', 'description':' Billy Idol ', 'uri':'https://i.ytimg.com/vi/e7U1YZNgwnY/maxresdefault.jpg', 'tokens':'23'},
{'name':'Good Days', 'url':'', 'description':' SZA', 'uri':'https://upload.wikimedia.org/wikipedia/en/7/7c/SZA_-_Good_Days.png', 'tokens':'24'},
{'name':'sdp interlude', 'url':'', 'description':'Travis Scott ', 'uri':'https://i.scdn.co/image/ab67616d0000b273f54b99bf27cda88f4a7403ce', 'tokens':'25'},
{'name':'Mary', 'url':'', 'description':' Alex G ', 'uri':'https://i.scdn.co/image/ab67616d0000b273c85ca3b845a922baff3041c7', 'tokens':'26'},
{'name':'Flashing Lights', 'url':'', 'description':'Kanye West ', 'uri':'https://i.scdn.co/image/ab67616d0000b27326f7f19c7f0381e56156c94a', 'tokens':'27'},
{'name':'Trust issues', 'url':'', 'description':'Drake', 'uri':'https://i1.sndcdn.com/artworks-QHAz47bKkwaj-0-t500x500.jpg', 'tokens':'28'},
{'name':'Gods Plan', 'url':'', 'description':'Drake ', 'uri':'https://i.ytimg.com/vi/m1a_GqJf02M/maxresdefault.jpg', 'tokens':'29'},
{'name':'Time to Pretend', 'url':'', 'description':'MGMT ', 'uri':'https://i.scdn.co/image/ab67616d0000b2738b32b139981e79f2ebe005eb', 'tokens':'30'},
{'name':'Sensei Wu', 'url':'/audios/WU.mp3', 'description':' Ian Wu Father ', 'uri':'https://m.media-amazon.com/images/I/51Zl1Tdk3YL._AC_UF894,1000_QL80_.jpg', 'tokens':'31'},
]
# iterate
for song_data in songs_data:
existing_song = Song.query.filter_by(_name=song_data['name']).first()
# If user exists, print a message and update user data
if existing_song:
print(f"User with _uid '{song_data['name']}' already exists. Updating user data.")
existing_song.update(
name=song_data['name'],
url=song_data['url'],
uri=song_data['uri'],
)
# If user does not exist, create a new user and add to the database
else:
new_song = Song(
name=song_data['name'],
url=song_data['url'],
description=song_data['description'],
uri=song_data['uri'],
tokens=song_data['tokens']
)
db.session.add(new_song)
db.session.commit()
- From VSCode using SQLite3 Editor, show your unique collection/table in database, display rows and columns in the table of the SQLite database.
- This is the data table of all of the stored songs
- From VSCode model, show your unique code that was created to initialize table and create test data.
- Uses two normal and 1 admin account as instructed
# Builds working data for testing
def initUsers():
with app.app_context():
"""Create database and tables"""
db.create_all()
"""Tester data for table"""
u1 = User(name='erox', uid='1', password='123erox', points="0", usertype="Admin")
u2 = User(name='saaras', uid='2', password='123saaras', points="0", usertype="User")
u3 = User(name='sri', uid='3', password='123sri', points="0", usertype="User")
u4 = User(name='austin', uid='4', password='123austin', points="0", usertype="User")
users = [u1, u2, u3, u4]
"""Builds sample user/note(s) data"""
for user in users:
try:
'''add a few 1 to 4 notes per user'''
for num in range(randrange(1, 4)):
note = "#### " + user.name + " note " + str(num) + ". \n Generated by test data."
user.posts.append(Post(id=user.id, note=note, image='ncs_logo.png'))
'''add user/post data to table'''
user.create()
except IntegrityError:
'''fails with bad or duplicate data'''
db.session.remove()
print(f"Records exist, duplicate email, or error: {user.uid}")
- In VSCode using Debugger, show a list as extracted from database as Python objects.
- This shows the user data object being extracted in the debugger after a postman request
- In VSCode use Debugger and list, show two distinct example examples of dictionaries, show Keys/Values using debugger.
-
This is the data for the spotify songs
-
This is the data for the users that are allowed to login
-
APIS and JSON
Blog Python API code and use of Postman to request and respond with JSON.
- In VSCode, show Python API code definition for request and response using GET, POST, UPDATE methods. Discuss algorithmic condition used to direct request to appropriate Python method based on request method.
- The API has many CRUD definitions for GET POST and UPDATE responses for modifiying objects
- A resource needs to be defined in order to create enpoints
- This code is defining the end point for the user api that allows for GET POST and PUT responses
# building RESTapi endpoint
api.add_resource(_CRUD, '/')
api.add_resource(_Security, '/authenticate')
- In VSCode, show algorithmic conditions used to validate data on a POST condition.
- Algorithmic requirements guarantee the validity of input data. The condition integrated into the user code validates the password’s security by cheking its minimum length and confirming the presence of both a name and a password.
# validate name
name = body.get('name')
if name is None or len(name) < 2:
return {'message': f'Name is missing, or is less than 2 characters'}, 400
# validate uid
uid = body.get('uid')
if uid is None or len(uid) < 2:
return {'message': f'User ID is missing, or is less than 2 characters'}, 400
- In Postman, show URL request and Body requirements for GET, POST, and UPDATE methods.
- In Postman, show the JSON response data for 200 success conditions on GET, POST, and UPDATE methods.
-
The 200 GET Request:
-
The 200 POST Request
-
- In Postman, show the JSON response for error for 400 when missing body on a POST request.
- When the body is missing, there is no JSON data to send which is the point of a POST
- The 404 PUT Request
- When the song id can’t be found, a 404 error is returned with a message informing the user that the song wasn’t found
Frontend
-
In Chrome inspect, show response of JSON objects from fetch of GET, POST, and UPDATE methods.
-
In the Chrome browser, show a demo (GET) of obtaining an Array of JSON objects that are formatted into the browsers screen.
- This formats all the json objects into squares (the songs)
- See code down below
async function fetchData() {
try {
const response = await fetch('http://127.0.0.1:8086/api/song/all');
const songsData = await response.json();
const container = document.getElementById("albumList");
// Map through the list and create song cards
songsData.forEach((song) => {
const itemBlock = createItemBlock(song);
container.appendChild(itemBlock);
});
} catch (error) {
console.error('Error fetching data:', error);
}
}
##################################### END OF GET DATA #####################################################
function createItemBlock(data) {
const item = document.createElement("div");
item.classList.add("item");
const img = document.createElement("img");
img.src = data._uri;
item.appendChild(img);
const play = document.createElement("div");
play.classList.add("play");
const playIcon = document.createElement("span");
playIcon.classList.add("fa", "fa-play");
let isPlaying = false;
let audioPlayer;
playIcon.addEventListener("click", () => {
console.log(data._uri)
}
- In JavaScript code, describe fetch and method that obtained the Array of JSON objects.
- The Top Function:
- A request is sent out to the URL containing the dictionary of songs
- The dictionary is piped into a variable, and the dictionary is iterated through creating a itemblock for each item
- The Bottom function
- Just a demonstration of how the blocks are created via JQuery
- A div is created, and within the div is an image and icon which is clickable
- The Top Function:
- In the Chrome browser, show a demo (POST or UPDATE) gathering and sending input and receiving a response that show update. Repeat this demo showing both success and failure.
- Before song upload (POST) command:
- After song upload (POST) command:
async function fetchData() {
try {
const response = await fetch('http://127.0.0.1:8086/api/song/all');
const songsData = await response.json();
const container = document.getElementById("albumList");
// Map through the list and create song cards
songsData.forEach((song) => {
const itemBlock = createItemBlock(song);
container.appendChild(itemBlock);
});
} catch (error) {
console.error('Error fetching data:', error);
}
}
let loggedIn = sessionStorage.getItem("loggedIn") || "0";
// Function to toggle the display of the login button
function toggleLoginButton() {
const loginButton = document.getElementById("loginButton");
loginButton.style.display = loggedIn === "1" ? "none" : "block";
}
// Call the function on page load to set the initial state
// Load data when the page is loaded
window.onload = function () {
toggleLoginButton();
fetchData();
document.getElementById("albumList").addEventListener("click", redirectToSongPageContainer);
};
function redirectToSongPage(songName, songUrl, songDescription, data) { //THIS IS THE FUNCTIOANSDIJAISJDOIAJSDIO
// Store the song name and URL in sessionStorage
sessionStorage.setItem('currentSongName', songName);
sessionStorage.setItem('currentSongUrl', songUrl);
sessionStorage.setItem('currentSongDescription', songDescription);
console.log(songName)
console.log(songDescription)
// Log the data to the console
// Redirect to the song.html page
window.location.href = 'song.html';
}
- In JavaScript code, show and describe code that handles success. Describe how code shows success to the user in the Chrome Browser screen.
- In the case that the backend successfully adds the text to the image, the frontend will display the song blocks, indicating success
- The user will additionally be able to play the songs
- In JavaScript code, show and describe code that handles failure. Describe how the code shows failure to the user in the Chrome Browser screen.
- If something goes wrong with the API, the user is alerted with the error raised by the Backend