def handle_noargs(self, **options): try: 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) # .filter(upload_date__lte=datetime.today() - timedelta(days=180)) \ mixes = ( Mix.objects.exclude(archive_path__isnull=False) .annotate(num_plays=Count("activity_plays")) .order_by("num_plays") ) for mix in mixes: if os.path.isfile(mix.get_absolute_path()): print "Uploading file for: %s" % mix.slug file_name = "%s.%s" % (mix.uid, mix.filetype) archive_path = url_path_join(settings.AZURE_ITEM_BASE_URL, settings.AZURE_CONTAINER, file_name) with open(mix.get_absolute_path(), "rb") as iterator: obj = driver.upload_object_via_stream( iterator=iterator, container=container, object_name=file_name ) print "Uploaded" mix.archive_path = archive_path mix.save() expired_path = join(settings.MEDIA_ROOT, "mixes/archived") new_file = os.path.join(expired_path, basename(iterator.name)) os.rename(iterator.name, new_file) print "done- file is %s" % mix.archive_path except Exception, ex: print "Debug exception: %s" % ex.message
def get_stream_url(self): if self.archive_path in [None, '']: ret = url_path_join(settings.STREAM_URL, "{0}.{1}".format(self.uid, self.filetype)) else: return "{0}{1}.{2}".format(settings.AUDIO_URL, self.uid, self.filetype) return ret
def handle_noargs(self, **options): try: 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) #.filter(upload_date__lte=datetime.today() - timedelta(days=180)) \ mixes = Mix.objects \ .exclude(archive_path__isnull=False) \ .annotate(num_plays=Count('activity_plays')) \ .order_by('num_plays') for mix in mixes: if os.path.isfile(mix.get_absolute_path()): print("Uploading file for: %s" % mix.slug) file_name = "%s.%s" % (mix.uid, mix.filetype) archive_path = url_path_join(settings.AZURE_ITEM_BASE_URL, settings.AZURE_CONTAINER, file_name) with open(mix.get_absolute_path(), 'rb') as iterator: obj = driver.upload_object_via_stream( iterator=iterator, container=container, object_name=file_name) print("Uploaded") mix.archive_path = archive_path mix.save() expired_path = join(settings.MEDIA_ROOT, "mixes/archived") new_file = os.path.join(expired_path, basename(iterator.name)) os.rename(iterator.name, new_file) print("done- file is %s" % mix.archive_path) except Exception as ex: print("Debug exception: %s" % ex.message)
def get_stream_path(self): if self.archive_path in [None, '']: ret = url_path_join(localsettings.STREAM_URL, "%s.mp3" % self.uid) else: ret = self.archive_path return ret