Fix duplicate key bug, set root url to login
This commit is contained in:
@@ -8,7 +8,7 @@ These instructions will get you a copy of the project up and running on your loc
|
|||||||
|
|
||||||
### Prerequisites
|
### 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.
|
||||||
|
|
||||||
<!--- installation steps {{{ -->
|
<!--- installation steps {{{ -->
|
||||||
|
|
||||||
|
|||||||
45
api/utils.py
45
api/utils.py
@@ -4,19 +4,22 @@ import math
|
|||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from django.db.models import Count, F, Max
|
|
||||||
from django.db import IntegrityError
|
|
||||||
from django.http import JsonResponse
|
|
||||||
from django.core import serializers
|
from django.core import serializers
|
||||||
from django.utils import timezone
|
from django.core.exceptions import ObjectDoesNotExist
|
||||||
from .models import *
|
from django.db import IntegrityError
|
||||||
from . import views
|
from django.db.models import Count, F, Max
|
||||||
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 import FloatField
|
||||||
from django.db.models.functions import Cast
|
from django.db.models.functions import Cast
|
||||||
|
from django.http import JsonResponse
|
||||||
|
from django.utils import timezone
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
from dateutil.parser import parse
|
||||||
|
from pprint import pprint
|
||||||
|
|
||||||
|
from . import views
|
||||||
|
from .models import *
|
||||||
|
from login.models import User
|
||||||
|
|
||||||
HISTORY_ENDPOINT = 'https://api.spotify.com/v1/me/player/recently-played'
|
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 = []
|
track_artists = []
|
||||||
for artist_dict in track_dict['artists']:
|
for artist_dict in track_dict['artists']:
|
||||||
artist_obj, artist_created = Artist.objects.get_or_create(
|
try:
|
||||||
id=artist_dict['id'],
|
artist_obj, artist_created = Artist.objects.get_or_create(
|
||||||
name=artist_dict['name'],)
|
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
|
# 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)
|
track_artists.append(artist_obj)
|
||||||
|
|
||||||
return track_artists
|
return track_artists
|
||||||
|
|||||||
@@ -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
|
|
||||||
@@ -1,34 +1,37 @@
|
|||||||
astroid==2.2.4
|
astroid==2.2.5
|
||||||
certifi==2018.11.29
|
backports.csv==1.0.7
|
||||||
|
certifi==2019.3.9
|
||||||
chardet==3.0.4
|
chardet==3.0.4
|
||||||
defusedxml==0.5.0
|
defusedxml==0.5.0
|
||||||
Django==2.1.7
|
Django==2.2
|
||||||
django-appconf==1.0.3
|
django-appconf==1.0.3
|
||||||
django-compressor==2.2
|
django-compressor==2.2
|
||||||
django-crispy-forms==1.7.2
|
django-crispy-forms==1.7.2
|
||||||
django-filter==2.1.0
|
django-filter==2.1.0
|
||||||
django-sass-processor==0.7.2
|
django-sass-processor==0.7.3
|
||||||
django-tables2==2.0.5
|
django-tables2==2.0.6
|
||||||
djangorestframework==3.9.2
|
djangorestframework==3.9.2
|
||||||
et-xmlfile==1.0.1
|
et-xmlfile==1.0.1
|
||||||
idna==2.8
|
idna==2.8
|
||||||
isort==4.3.12
|
isort==4.3.17
|
||||||
jdcal==1.4
|
jdcal==1.4
|
||||||
lazy-object-proxy==1.3.1
|
lazy-object-proxy==1.3.1
|
||||||
libsass==0.17.0
|
libsass==0.18.0
|
||||||
mccabe==0.6.1
|
mccabe==0.6.1
|
||||||
odfpy==1.4.0
|
odfpy==1.4.0
|
||||||
openpyxl==2.6.1
|
openpyxl==2.6.2
|
||||||
psycopg2-binary==2.7.7
|
psycopg2==2.8.2
|
||||||
|
psycopg2-binary==2.8.2
|
||||||
pylint==2.3.1
|
pylint==2.3.1
|
||||||
python-dateutil==2.8.0
|
python-dateutil==2.8.0
|
||||||
pytz==2018.9
|
pytz==2019.1
|
||||||
PyYAML==3.13
|
PyYAML==5.1
|
||||||
rcssmin==1.0.6
|
rcssmin==1.0.6
|
||||||
requests==2.21.0
|
requests==2.21.0
|
||||||
rjsmin==1.1.0
|
rjsmin==1.1.0
|
||||||
six==1.12.0
|
six==1.12.0
|
||||||
tablib==0.12.1
|
sqlparse==0.3.0
|
||||||
|
tablib==0.13.0
|
||||||
typed-ast==1.3.1
|
typed-ast==1.3.1
|
||||||
unicodecsv==0.14.1
|
unicodecsv==0.14.1
|
||||||
urllib3==1.24.1
|
urllib3==1.24.1
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
#!/bin/bash
|
#!/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
|
/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
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from django.urls import path, include
|
|||||||
|
|
||||||
urlpatterns = [
|
urlpatterns = [
|
||||||
path('admin/', admin.site.urls),
|
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('api/', include('api.urls', namespace="api")),
|
||||||
path('graphs/', include('graphs.urls', namespace="graphs")),
|
path('graphs/', include('graphs.urls', namespace="graphs")),
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user