Browse Source

Fix duplicate key bug, set root url to login

master
Kevin Mok 6 years ago
parent
commit
89432834f6
Signed by: Kevin-Mok GPG Key ID: AEA75288DC135CF5
  1. 2
      README.md
  2. 41
      api/utils.py
  3. 40
      requirements.txt
  4. 27
      scripts/requirements.txt
  5. 3
      scripts/update-history.sh
  6. 0
      scripts/upgrade-pip-reqs.sh
  7. 2
      spotifyvis/urls.py
  8. 0
      static/todo.md

2
README.md

@ -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 {{{ -->

41
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.core import serializers
from django.core.exceptions import ObjectDoesNotExist
from django.db import IntegrityError 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.http import JsonResponse
from django.core import serializers
from django.utils import timezone 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 . import views
from .models import *
from login.models import User 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' 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(
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 # 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

40
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.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

27
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 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-tables2==2.0.5
django-sass-processor==0.7.3
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
psycopg2-binary==2.7.7
openpyxl==2.6.2
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
PyYAML==3.13
pytz==2019.1
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

3
scripts/update-history.sh

@ -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
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

0
upgrade-pip-reqs.sh → scripts/upgrade-pip-reqs.sh

2
spotifyvis/urls.py

@ -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")),
] ]

0
todo.md → static/todo.md

Loading…
Cancel
Save