Browse Source

Run on server, update dependencies

master
Kevin Mok 5 years ago
parent
commit
96b7a4a98c
Signed by: Kevin-Mok GPG Key ID: AEA75288DC135CF5
  1. 4
      .gitignore
  2. 16
      README.md
  3. 6
      login/views.py
  4. 40
      requirements.txt
  5. 2
      scripts/create_user.sql
  6. 8
      scripts/queries/history.sql
  7. 0
      scripts/queries/most-played.sql
  8. 40
      scripts/requirements.txt
  9. 21
      scripts/reset_db.sh
  10. 4
      scripts/reset_db.sql
  11. 8
      spotifyvis/settings.py
  12. 1
      spotifyvis/urls.py
  13. 1
      static/todo.md

4
.gitignore

@ -3,8 +3,12 @@
*/migrations/* */migrations/*
media/history/* media/history/*
spotifyvis/static/graphs/sass/* spotifyvis/static/graphs/sass/*
static/admin/
static/django_tables2/
static/graphs/
*.bak *.bak
*.css
*.log *.log
*.map *.map
*.orig *.orig

16
README.md

@ -19,35 +19,35 @@ Before starting the setup, make sure Python 3 and PostgreSQL is installed on you
``` ```
pip install --user pipenv pip install --user pipenv
``` ```
2. Create a virtual environment. 2. Create a virtual environment.
``` ```
python3 -m venv /path/to/new/virtual/environment python3 -m venv /path/to/new/virtual/environment
``` ```
3. `cd` into the directory you just created a virtual environment in, and clone the GitHub repo:
3. `cd` into the directory you just created a virtual environment in,
and clone the GitHub repo:
``` ```
cd /path/to/new/virtual/environment
git clone https://github.com/Kevin-Mok/spotify-lib-vis git clone https://github.com/Kevin-Mok/spotify-lib-vis
``` ```
4. Activate the virtual environment from the command line. 4. Activate the virtual environment from the command line.
``` ```
# activate.fish if you're using fish shell
source bin/activate source bin/activate
``` ```
5. `cd` into the repository root directory and install all dependencies using `pip`.
5. `cd` into the repository root directory and install all
dependencies using `pip`.
``` ```
cd spotify-lib-vis
pip install -r requirements.txt pip install -r requirements.txt
``` ```
6. Run `reset_db.sh` to create the database and start the server. 6. Run `reset_db.sh` to create the database and start the server.
``` ```
cd src && ./reset_db.sh
./scripts/reset_db.sh
``` ```
<!--- }}} installation steps --> <!--- }}} installation steps -->

6
login/views.py

@ -16,6 +16,8 @@ from .utils import *
TIME_FORMAT = '%Y-%m-%d-%H-%M-%S' TIME_FORMAT = '%Y-%m-%d-%H-%M-%S'
TRACKS_TO_QUERY = 200 TRACKS_TO_QUERY = 200
AUTH_SCOPE = ['user-library-read', 'user-read-recently-played', ] AUTH_SCOPE = ['user-library-read', 'user-read-recently-played', ]
# ROOT_URL = 'http://localhost:8000'
ROOT_URL = 'http://spotify-lib-vis.ml'
# index {{{ # # index {{{ #
@ -37,7 +39,7 @@ def spotify_login(request):
payload = { payload = {
'client_id': os.environ['SPOTIFY_CLIENT_ID'], 'client_id': os.environ['SPOTIFY_CLIENT_ID'],
'response_type': 'code', 'response_type': 'code',
'redirect_uri': 'http://localhost:8000/login/callback',
'redirect_uri': ROOT_URL + '/login/callback',
'state': state_str, 'state': state_str,
'scope': " ".join(AUTH_SCOPE), 'scope': " ".join(AUTH_SCOPE),
'show_dialog': False 'show_dialog': False
@ -64,7 +66,7 @@ def callback(request):
payload = { payload = {
'grant_type': 'authorization_code', 'grant_type': 'authorization_code',
'code': code, 'code': code,
'redirect_uri': 'http://localhost:8000/login/callback',
'redirect_uri': ROOT_URL + '/login/callback',
'client_id': os.environ['SPOTIFY_CLIENT_ID'], 'client_id': os.environ['SPOTIFY_CLIENT_ID'],
'client_secret': os.environ['SPOTIFY_CLIENT_SECRET'], 'client_secret': os.environ['SPOTIFY_CLIENT_SECRET'],
} }

40
requirements.txt

@ -0,0 +1,40 @@
astroid==2.2.5
backports.csv==1.0.7
certifi==2019.6.16
chardet==3.0.4
defusedxml==0.6.0
Django==2.2.4
django-appconf==1.0.3
django-compressor==2.3
django-crispy-forms==1.7.2
django-filter==2.2.0
django-sass-processor==0.7.3
django-tables2==2.1.0
djangorestframework==3.10.2
et-xmlfile==1.0.1
idna==2.8
isort==4.3.21
jdcal==1.4.1
lazy-object-proxy==1.4.2
libsass==0.19.2
mccabe==0.6.1
odfpy==1.4.0
openpyxl==2.6.3
psycopg2==2.8.3
psycopg2-binary==2.8.3
pylint==2.3.1
python-dateutil==2.8.0
pytz==2019.2
PyYAML==5.1.2
rcssmin==1.0.6
requests==2.22.0
rjsmin==1.1.0
six==1.12.0
sqlparse==0.3.0
tablib==0.13.0
typed-ast==1.4.0
unicodecsv==0.14.1
urllib3==1.25.3
wrapt==1.11.2
xlrd==1.2.0
xlwt==1.3.0

2
scripts/create_user.sql

@ -0,0 +1,2 @@
DROP ROLE IF EXISTS spotifyvis_user;
CREATE ROLE spotifyvis_user LOGIN PASSWORD 'spotifyvis_user';

8
scripts/history.sql → scripts/queries/history.sql

@ -1,5 +1,6 @@
-- select t.name as track, a.name as artist -- select t.name as track, a.name as artist
select timestamp, substring(t.name for 50) as track, a.name as artist
select distinct on (1)
timestamp, substring(t.name for 50) as track, a.name as artist
from api_history as h from api_history as h
join api_track as t join api_track as t
on h.track_id = t.id on h.track_id = t.id
@ -7,5 +8,6 @@ join api_track_artists ta
on ta.track_id = t.id on ta.track_id = t.id
join api_artist a join api_artist a
on a.id = ta.artist_id on a.id = ta.artist_id
-- limit 10;
;
order by timestamp desc
-- ;
limit 20;

0
scripts/most-played.sql → scripts/queries/most-played.sql

40
scripts/requirements.txt

@ -1,40 +0,0 @@
astroid==2.2.5
backports.csv==1.0.7
certifi==2019.3.9
chardet==3.0.4
defusedxml==0.5.0
Django==2.2
django-appconf==1.0.3
django-compressor==2.2
django-crispy-forms==1.7.2
django-filter==2.1.0
django-sass-processor==0.7.3
django-tables2==2.0.6
djangorestframework==3.9.2
et-xmlfile==1.0.1
idna==2.8
isort==4.3.17
jdcal==1.4
lazy-object-proxy==1.3.1
libsass==0.18.0
mccabe==0.6.1
odfpy==1.4.0
openpyxl==2.6.2
psycopg2==2.8.2
psycopg2-binary==2.8.2
pylint==2.3.1
python-dateutil==2.8.0
pytz==2019.1
PyYAML==5.1
rcssmin==1.0.6
requests==2.21.0
rjsmin==1.1.0
six==1.12.0
sqlparse==0.3.0
tablib==0.13.0
typed-ast==1.3.1
unicodecsv==0.14.1
urllib3==1.24.1
wrapt==1.11.1
xlrd==1.2.0
xlwt==1.3.0

21
scripts/reset_db.sh

@ -1,15 +1,16 @@
# check if in virtual environment
# https://stackoverflow.com/questions/15454174/how-can-a-shell-function-know-if-it-is-running-within-a-virtualenv/15454916
#!/bin/bash
# python -c 'import sys; print(sys.real_prefix)' 2>/dev/null && INVENV=1 || INVENV=0
# INVENV=$(python -c 'import sys; print ("1" if hasattr(sys, "real_prefix") else "0")')
# check if in virtual environment
# https://stackoverflow.com/a/15454284/8811872
[[ "$VIRTUAL_ENV" == "" ]]; INVENV=$?
# if $INVENV is 1, then in virtualenv # if $INVENV is 1, then in virtualenv
# echo $INVENV # echo $INVENV
# if [ $INVENV -eq 1 ]; then
if [ $INVENV -eq 1 ]; then
rm login/migrations/0* api/migrations/0* rm login/migrations/0* api/migrations/0*
sudo -u postgres psql -f reset_db.sql
python manage.py makemigrations login api
python manage.py migrate --fake
python manage.py runserver
# fi
sudo -u postgres psql -f ./scripts/reset_db.sql
python3 manage.py makemigrations login api
python3 manage.py migrate --fake
python3 manage.py runserver
fi

4
scripts/reset_db.sql

@ -1,3 +1,3 @@
DROP DATABASE spotifyvis;
DROP DATABASE IF EXISTS spotifyvis;
CREATE DATABASE spotifyvis; CREATE DATABASE spotifyvis;
GRANT ALL PRIVILEGES ON DATABASE spotifyvis TO django;
GRANT ALL PRIVILEGES ON DATABASE spotifyvis TO spotifyvis_user;

8
spotifyvis/settings.py

@ -25,7 +25,7 @@ SECRET_KEY = 'm(gh1&063)haj#^t+h-qh@o6#%w=ruqi_#=6yzi=#@q6#0p*gv'
# SECURITY WARNING: don't run with debug turned on in production! # SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True DEBUG = True
ALLOWED_HOSTS = []
ALLOWED_HOSTS = ['spotify-lib-vis.ml']
# Application definition # Application definition
@ -86,8 +86,8 @@ DATABASES = {
'default': { 'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2', 'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'spotifyvis', 'NAME': 'spotifyvis',
'USER': 'django',
'PASSWORD': 'django',
'USER': 'spotifyvis_user',
'PASSWORD': 'spotifyvis_user',
'HOST': 'localhost', 'HOST': 'localhost',
'PORT': '', 'PORT': '',
} }
@ -130,7 +130,7 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images) # Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.0/howto/static-files/ # https://docs.djangoproject.com/en/2.0/howto/static-files/
STATIC_URL = '/static/' STATIC_URL = '/static/'
STATIC_ROOT = os.path.join(BASE_DIR, "spotifyvis/static")
STATIC_ROOT = os.path.join(BASE_DIR, "static/")
STATICFILES_DIRS = [ STATICFILES_DIRS = [
os.path.join(BASE_DIR, "static/"), os.path.join(BASE_DIR, "static/"),
] ]

1
spotifyvis/urls.py

@ -19,6 +19,7 @@ from django.urls import path, include
urlpatterns = [ urlpatterns = [
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('', include('login.urls', namespace="main")), path('', include('login.urls', namespace="main")),
path('login/', include('login.urls', namespace="main")),
path('api/', include('api.urls', namespace="api")), path('api/', include('api.urls', namespace="api")),
path('graphs/', include('graphs.urls', namespace="graphs")), path('graphs/', include('graphs.urls', namespace="graphs")),
] ]

1
static/todo.md

@ -5,3 +5,4 @@
- loading/progress indicator - loading/progress indicator
- change js tabs to 2 spaces - change js tabs to 2 spaces
- Heroku? - Heroku?
- send out weekly email for history stats
Loading…
Cancel
Save