diff --git a/README.md b/README.md index b20be0e..39f539a 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ These instructions will get you a copy of the project up and running on your loc ### Prerequisites -Before starting the setup, make sure Python 3.6 and PostgreSQL is installed on your system. +Before starting the setup, make sure Python 3 and PostgreSQL is installed on your system. diff --git a/api/utils.py b/api/utils.py index 6ae7b7e..df53702 100644 --- a/api/utils.py +++ b/api/utils.py @@ -4,19 +4,22 @@ import math import os import json -from django.db.models import Count, F, Max +from django.core import serializers +from django.core.exceptions import ObjectDoesNotExist from django.db import IntegrityError +from django.db.models import Count, F, Max +from django.db.models import FloatField +from django.db.models.functions import Cast from django.http import JsonResponse -from django.core import serializers from django.utils import timezone -from .models import * + +from datetime import datetime +from dateutil.parser import parse +from pprint import pprint + from . import views +from .models import * from login.models import User -from pprint import pprint -from dateutil.parser import parse -from datetime import datetime -from django.db.models import FloatField -from django.db.models.functions import Cast HISTORY_ENDPOINT = 'https://api.spotify.com/v1/me/player/recently-played' @@ -247,15 +250,21 @@ def save_track_artists(track_dict, artist_genre_queue, user_headers): """ track_artists = [] for artist_dict in track_dict['artists']: - artist_obj, artist_created = Artist.objects.get_or_create( - id=artist_dict['id'], - name=artist_dict['name'],) + try: + artist_obj, artist_created = Artist.objects.get_or_create( + id=artist_dict['id'], + name=artist_dict['name'],) + if artist_created: + artist_genre_queue.append(artist_obj) + if len(artist_genre_queue) == views.ARTIST_LIMIT: + add_artist_genres(user_headers, artist_genre_queue) + artist_genre_queue[:] = [] + # artist changed name but same id + except IntegrityError as e: + artist_obj = Artist.objects.get(id=artist_dict['id']) + artist_obj.name = artist_dict['name'] + artist_obj.save() # only add/tally up artist genres if new - if artist_created: - artist_genre_queue.append(artist_obj) - if len(artist_genre_queue) == views.ARTIST_LIMIT: - add_artist_genres(user_headers, artist_genre_queue) - artist_genre_queue[:] = [] track_artists.append(artist_obj) return track_artists diff --git a/requirements.txt b/requirements.txt deleted file mode 100644 index 43a76ab..0000000 --- a/requirements.txt +++ /dev/null @@ -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.0.12 -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 diff --git a/scripts/requirements.txt b/scripts/requirements.txt index 23301ac..5c55b86 100644 --- a/scripts/requirements.txt +++ b/scripts/requirements.txt @@ -1,34 +1,37 @@ -astroid==2.2.4 -certifi==2018.11.29 +astroid==2.2.5 +backports.csv==1.0.7 +certifi==2019.3.9 chardet==3.0.4 defusedxml==0.5.0 -Django==2.1.7 +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.2 -django-tables2==2.0.5 +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.12 +isort==4.3.17 jdcal==1.4 lazy-object-proxy==1.3.1 -libsass==0.17.0 +libsass==0.18.0 mccabe==0.6.1 odfpy==1.4.0 -openpyxl==2.6.1 -psycopg2-binary==2.7.7 +openpyxl==2.6.2 +psycopg2==2.8.2 +psycopg2-binary==2.8.2 pylint==2.3.1 python-dateutil==2.8.0 -pytz==2018.9 -PyYAML==3.13 +pytz==2019.1 +PyYAML==5.1 rcssmin==1.0.6 requests==2.21.0 rjsmin==1.1.0 six==1.12.0 -tablib==0.12.1 +sqlparse==0.3.0 +tablib==0.13.0 typed-ast==1.3.1 unicodecsv==0.14.1 urllib3==1.24.1 diff --git a/scripts/update-history.sh b/scripts/update-history.sh index cabf955..a9508d4 100755 --- a/scripts/update-history.sh +++ b/scripts/update-history.sh @@ -1,4 +1,3 @@ #!/bin/bash -# /home/kevin/coding/spotify-lib-vis/bin/python /home/kevin/coding/spotify-lib-vis/src/manage.py update-history >> /home/kevin/coding/spotify-lib-vis/src/api/management/commands/update-history.log 2>&1 -python /home/kevin/coding/spotify-lib-vis/src/manage.py update-history >> /home/kevin/coding/spotify-lib-vis/src/api/management/commands/update-history.log 2>&1 +/home/kevin/coding/spotify-lib-vis/bin/python /home/kevin/coding/spotify-lib-vis/src/manage.py update-history >> /home/kevin/coding/spotify-lib-vis/src/api/management/commands/update-history.log 2>&1 diff --git a/upgrade-pip-reqs.sh b/scripts/upgrade-pip-reqs.sh similarity index 100% rename from upgrade-pip-reqs.sh rename to scripts/upgrade-pip-reqs.sh diff --git a/spotifyvis/urls.py b/spotifyvis/urls.py index 08ed113..ec4528d 100644 --- a/spotifyvis/urls.py +++ b/spotifyvis/urls.py @@ -18,7 +18,7 @@ from django.urls import path, include urlpatterns = [ path('admin/', admin.site.urls), - path('login/', include('login.urls', namespace="login")), + path('', include('login.urls', namespace="main")), path('api/', include('api.urls', namespace="api")), path('graphs/', include('graphs.urls', namespace="graphs")), ] diff --git a/todo.md b/static/todo.md similarity index 100% rename from todo.md rename to static/todo.md