Added extra logging to social redirect

This commit is contained in:
Fergal Moran
2015-07-01 20:38:43 +01:00
parent 4a13fd4b0f
commit e3f9b8b791
8 changed files with 84 additions and 56 deletions

5
clean_thumbnails Executable file
View File

@@ -0,0 +1,5 @@
python manage.py thumbnail cleanup
python manage.py thumbnail clear
python manage.py thumbnail clear_delete_referenced
python manage.py thumbnail clear_delete_all

View File

@@ -12,8 +12,6 @@ def upload_to_azure(in_file, filetype, uid):
if os.path.isfile(in_file):
print "Uploading file for: %s" % in_file
file_name = "%s.%s" % (uid, filetype)
archive_path = url_path_join(settings.AZURE_ITEM_BASE_URL, settings.AZURE_CONTAINER, file_name)
cls = get_driver(Provider.AZURE_BLOBS)
driver = cls(settings.AZURE_ACCOUNT_NAME, settings.AZURE_ACCOUNT_KEY)
container = driver.get_container(container_name=settings.AZURE_CONTAINER)

View File

@@ -29,7 +29,7 @@ DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': DATABASE_NAME,
'ADMINUSER': DATABASE_USER,
'ADMINUSER': 'postgres',
'USER': DATABASE_USER,
'PASSWORD': DATABASE_PASSWORD,
'HOST': DATABASE_HOST,

View File

@@ -1,10 +1,18 @@
from django.core.management.base import NoArgsCommand
from django.core.management.base import NoArgsCommand, BaseCommand
from core.utils.cdn import upload_to_azure
from spa.models import Mix
class Command(NoArgsCommand):
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument(
'--delete',
action='store_true',
dest='delete',
default=False,
help='Delete poll instead of closing it')
def handle_noargs(self, **options):
try:
mixes = Mix.objects.filter(archive_updated=False)
@@ -16,3 +24,6 @@ class Command(NoArgsCommand):
except Exception, ex:
print "Fatal error, bailing. {0}".format(ex.message)
def handle(self, *args, **options):
pass

View File

@@ -0,0 +1,23 @@
def download_file( url, file_name):
import urllib2
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
file_buffer = u.read(block_sz)
if not file_buffer:
break
file_size_dl += len(file_buffer)
f.write(file_buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status += chr(8) * (len(status) + 1)
print status,
f.close()

View File

@@ -1,6 +1,7 @@
from optparse import make_option
import os
from django.core.management.base import NoArgsCommand, BaseCommand
from spa.management.commands import helpers
from spa.models.mix import Mix
from core.tasks import create_waveform_task
@@ -18,20 +19,30 @@ class Command(BaseCommand):
@staticmethod
def _get_file(mix):
#Check for file in mix directory
processed_file = ""
try:
processed_file = mix.get_absolute_path()
if not os.path.isfile(processed_file):
processed_file = mix.get_cache_path()
if mix.archive_updated:
print "Mix is archived: boo hoo"
file_name = "/tmp/%s.mp3" % mix.uid
url = mix.get_stream_url()
print "Downloading: %s To: %s" % (url, file_name)
helpers.download_file(url, file_name)
if not os.path.isfile(file_name):
print "File failed to download"
else:
return file_name
else:
processed_file = mix.get_absolute_path()
if not os.path.isfile(processed_file):
print "File for [%s] not found tried\n\t%s\n\t%s" % (mix.title, processed_file, processed_file)
return ""
processed_file = mix.get_cache_path()
if not os.path.isfile(processed_file):
print "File for [%s] not found tried\n\t%s\n\t%s" % (mix.title, processed_file, processed_file)
return ""
return processed_file
except Exception, ex:
print "Error generating waveform: %s" % ex.message
return processed_file
return ""
def handle(self, *args, **options):
print "Scanning for missing waveforms"

View File

@@ -3,32 +3,9 @@ from django.core.management.base import NoArgsCommand
from core.utils.waveform import generate_waveform
from dss import settings
from spa.models.mix import Mix
import helpers
class Command(NoArgsCommand):
def _download_file(self, url, file_name):
import urllib2
u = urllib2.urlopen(url)
f = open(file_name, 'wb')
meta = u.info()
file_size = int(meta.getheaders("Content-Length")[0])
print "Downloading: %s Bytes: %s" % (file_name, file_size)
file_size_dl = 0
block_sz = 8192
while True:
file_buffer = u.read(block_sz)
if not file_buffer:
break
file_size_dl += len(file_buffer)
f.write(file_buffer)
status = r"%10d [%3.2f%%]" % (file_size_dl, file_size_dl * 100. / file_size)
status += chr(8) * (len(status) + 1)
print status,
f.close()
def _convert_remote(self):
mixes = Mix.objects.exclude(waveform_version=2)
@@ -38,7 +15,7 @@ class Command(NoArgsCommand):
file_name = "/tmp/%s.mp3" % mix.uid
url = mix.get_stream_url()
print "Downloading: %s To: %s" % (url, file_name)
self._download_file(url, file_name)
helpers.download_file(url, file_name)
if not os.path.isfile(file_name):
print "File failed to download"
else:

View File

@@ -16,7 +16,6 @@ from spa.models import Playlist
from spa.models.mix import Mix
from spa.models.userprofile import UserProfile
logger = logging.getLogger(__name__)
"""
@@ -38,22 +37,25 @@ def facebook_mix(request, slug):
except Mix.DoesNotExist:
raise Http404
image = mix.get_image_url('400x400')
mix_url = mix.get_absolute_url()
default = _getPayload(request)
extras = {
"description": mix.description.replace('<br />', '\n'),
"title": mix.title,
"image_url": image,
"mix_url": 'http://%s%s' % (Site.objects.get_current().domain, mix_url)
}
payload = dict(default.items() + extras.items())
response = render_to_response(
'social/facebook/mix.html',
payload,
context_instance=RequestContext(request)
)
return response
try:
image = mix.get_image_url('400x400')
mix_url = mix.get_absolute_url()
default = _getPayload(request)
extras = {
"description": mix.description.replace('<br />', '\n'),
"title": mix.title,
"image_url": image,
"mix_url": 'http://%s%s' % (Site.objects.get_current().domain, mix_url)
}
payload = dict(default.items() + extras.items())
response = render_to_response(
'social/facebook/mix.html',
payload,
context_instance=RequestContext(request)
)
return response
except Exception, ex:
logger.error(ex.message)
def playlist(request, args):
@@ -156,7 +158,8 @@ def post_like(request, mix):
def delete_like(request, uid):
try:
tokens = SocialToken.objects.filter(account__user=request.user, account__provider='facebook')
tokens = SocialToken.objects.filter(account__user=request.user,
account__provider='facebook')
for token in tokens:
url = "https://graph.facebook.com/%s" % uid
values = {