-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging alan-django, ready for merge to master
- Loading branch information
Showing
81 changed files
with
955 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
# Welcome to CSE442 | ||
This is to create a file so that your repo has a place to start. | ||
# Instructions on how to run the application (Ubuntu only possibly) | ||
|
||
1. Download and extract zip file to directory | ||
2. Enter terminal and cd into directory where it was extracted | ||
3. Install python on your machine (resources online) | ||
4. Enter "pip install django" into terminal (follow prompts if need to install pip first) | ||
5. Enter "python manage.py runserver" and it should be running on the localhost server (go to browser -> url is localhost:8000) |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
""" | ||
Django settings for django_project project. | ||
Generated by 'django-admin startproject' using Django 2.2.6. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/2.2/topics/settings/ | ||
For the full list of settings and their values, see | ||
https://docs.djangoproject.com/en/2.2/ref/settings/ | ||
""" | ||
|
||
import os | ||
|
||
# Build paths inside the project like this: os.path.join(BASE_DIR, ...) | ||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
# Quick-start development settings - unsuitable for production | ||
# See https://docs.djangoproject.com/en/2.2/howto/deployment/checklist/ | ||
|
||
# SECURITY WARNING: keep the secret key used in production secret! | ||
SECRET_KEY = 'd-)mzbqy*ui&)&s$puiv&s@pp+65j-36#rb-2oh+2((&*4z3uh' | ||
|
||
# SECURITY WARNING: don't run with debug turned on in production! | ||
DEBUG = True | ||
|
||
ALLOWED_HOSTS = [] | ||
|
||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = [ | ||
'spotify.apps.SpotifyConfig', | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
ROOT_URLCONF = 'django_project.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'django_project.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/2.2/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
|
||
# Password validation | ||
# https://docs.djangoproject.com/en/2.2/ref/settings/#auth-password-validators | ||
|
||
AUTH_PASSWORD_VALIDATORS = [ | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', | ||
}, | ||
{ | ||
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', | ||
}, | ||
] | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/2.2/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/2.2/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""django_project URL Configuration | ||
The `urlpatterns` list routes URLs to views. For more information please see: | ||
https://docs.djangoproject.com/en/2.2/topics/http/urls/ | ||
Examples: | ||
Function views | ||
1. Add an import: from my_app import views | ||
2. Add a URL to urlpatterns: path('', views.home, name='home') | ||
Class-based views | ||
1. Add an import: from other_app.views import Home | ||
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') | ||
Including another URLconf | ||
1. Import the include() function: from django.urls import include, path | ||
2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) | ||
""" | ||
from django.contrib import admin | ||
from django.urls import path, include | ||
|
||
urlpatterns = [ | ||
path('admin/', admin.site.urls), | ||
path('', include('spotify.urls')) | ||
] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for django_project project. | ||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
For more information on this file, see | ||
https://docs.djangoproject.com/en/2.2/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') | ||
|
||
application = get_wsgi_application() |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/usr/bin/env python | ||
"""Django's command-line utility for administrative tasks.""" | ||
import os | ||
import sys | ||
|
||
|
||
def main(): | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'django_project.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError as exc: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) from exc | ||
execute_from_command_line(sys.argv) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class SpotifyConfig(AppConfig): | ||
name = 'spotify' |
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import sys | ||
import spotipy | ||
from spotipy.oauth2 import SpotifyOAuth as OAuth | ||
import webbrowser | ||
|
||
''' this module allows users to login to the main page | ||
and either gets or provides a token to allow access to | ||
a users spotify information | ||
''' | ||
|
||
|
||
class NoTokenError(Exception): | ||
""" there exists no token currently cached on this account""" | ||
pass | ||
class Login: | ||
def __init__(self): | ||
''' sets redirect page to the home page''' | ||
self.REDIRECT_URI = 'http://localhost:8000/home/' | ||
self.clientId='9f78b7eb1de54f6eb13701d07a891506' | ||
self.Secret='563e75870871424f9a26bb2bb66897bb' | ||
self.scope='user-read-email user-top-read playlist-modify-public user-library-read user-read-playback-state user-read-currently-playing streaming user-read-private user-modify-playback-state' | ||
self.authentication=(OAuth(self.clientId,self.Secret,self.REDIRECT_URI,state=None,scope=self.scope)) | ||
''' checks to see if there is already a token in the system if not | ||
check the if there is one URL to see if there is one in the url''' | ||
def getToken(self,url=None): | ||
token=self.authentication.get_cached_token() | ||
if token is not None: | ||
return token | ||
else: | ||
if url is not None: | ||
try: | ||
return self.authentication.get_access_token(self.authentication.parse_response_code(url)) | ||
except spotipy.oauth2.SpotifyOauthError: | ||
raise NoTokenError | ||
else: | ||
raise NoTokenError | ||
''' this will be the method called when the connect with spotify button is pressed | ||
on the login screen | ||
if loggedOut is true it will show dialogue for having a user log back in | ||
''' | ||
def login(self,loggedOut=False): | ||
dialogue="" | ||
if(loggedOut is True): | ||
dialogue="&show_dialog=true" | ||
webbrowser.open(self.authentication.get_authorize_url()+dialogue) | ||
def logout(self, token=None): | ||
token=None | ||
self.login(True) | ||
if __name__== "__main__": | ||
loggingIn=Login() | ||
try: | ||
token=loggingIn.getToken(loggingIn.REDIRECT_URI) | ||
except NoTokenError: | ||
loggingIn.login() | ||
print("please enter the url in the redirected page") | ||
url=input() | ||
token=loggingIn.getToken(url) | ||
|
||
|
||
|
||
print("\n"+str(token)) | ||
|
||
''' for testing purpose the tester will have to manually input the redirect uri | ||
but in the application should be handled by framework ''' | ||
|
||
print("\n here is the user information:\n") | ||
sp=spotipy.client.Spotify(auth=token['access_token']) | ||
print(str(sp.current_user())) | ||
|
||
|
||
print("\n here are the user's top artists:\n") | ||
results=sp.current_user_top_artists() | ||
artistList=[] | ||
for item in results['items']: | ||
artistList.append(str(item['name'])) | ||
print(str(artistList)) | ||
print("\n here are the user's top tracks:\n") | ||
results=sp.current_user_top_tracks() | ||
for item in results['items']: | ||
songList=[] | ||
for artist in item['artists']: | ||
songList.append(artist['name']) | ||
print(str(item['name'])+" from: "+str(item['album']['name'])+" by "+str(songList)) | ||
|
||
|
||
print("\n\n testing that logging out provides a new token") | ||
print("\noriginal token:\n"+str(token['access_token'])+"\n") | ||
print("\n press enter to logout") | ||
input() | ||
loggingIn.logout(token) | ||
print("please enter the url in the redirected page") | ||
url=input() | ||
token=loggingIn.getToken(url) | ||
print("\nnewtoken:\n"+str(token['access_token'])+"\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# -*- coding: utf-8 -*- | ||
# Generated by Django 1.11.24 on 2019-10-07 07:27 | ||
from __future__ import unicode_literals | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Post', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('playlist_name', models.CharField(max_length=100)), | ||
('songs_from_playlist', models.TextField()), | ||
('date_generated', models.DateTimeField(default=django.utils.timezone.now)), | ||
('requester', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
] |
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+164 Bytes
django_project/spotify/migrations/__pycache__/__init__.cpython-36.pyc
Binary file not shown.
Binary file added
BIN
+169 Bytes
django_project/spotify/migrations/__pycache__/__init__.cpython-37.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"keras_version": "2.2.4", "class_name": "Sequential", "backend": "tensorflow", "config": {"layers": [{"class_name": "Dense", "config": {"use_bias": true, "activation": "relu", "bias_initializer": {"class_name": "Zeros", "config": {}}, "bias_regularizer": null, "activity_regularizer": null, "units": 512, "kernel_regularizer": null, "batch_input_shape": [null, 10000], "dtype": "float32", "kernel_initializer": {"class_name": "VarianceScaling", "config": {"seed": null, "distribution": "uniform", "mode": "fan_avg", "scale": 1.0}}, "name": "dense_1", "bias_constraint": null, "trainable": true, "kernel_constraint": null}}, {"class_name": "Dropout", "config": {"noise_shape": null, "seed": null, "rate": 0.5, "name": "dropout_1", "trainable": true}}, {"class_name": "Dense", "config": {"use_bias": true, "activation": "sigmoid", "bias_initializer": {"class_name": "Zeros", "config": {}}, "bias_regularizer": null, "activity_regularizer": null, "units": 256, "kernel_regularizer": null, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"seed": null, "distribution": "uniform", "mode": "fan_avg", "scale": 1.0}}, "name": "dense_2", "bias_constraint": null, "trainable": true, "kernel_constraint": null}}, {"class_name": "Dropout", "config": {"noise_shape": null, "seed": null, "rate": 0.5, "name": "dropout_2", "trainable": true}}, {"class_name": "Dense", "config": {"use_bias": true, "activation": "softmax", "bias_initializer": {"class_name": "Zeros", "config": {}}, "bias_regularizer": null, "activity_regularizer": null, "units": 2, "kernel_regularizer": null, "kernel_initializer": {"class_name": "VarianceScaling", "config": {"seed": null, "distribution": "uniform", "mode": "fan_avg", "scale": 1.0}}, "name": "dense_3", "bias_constraint": null, "trainable": true, "kernel_constraint": null}}], "name": "sequential_1"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
Binary file not shown.
Oops, something went wrong.