1. Marc Condon
  2. Simply Rocking The Future

Commits

Marc Condon  committed 3f4c529

integrated get_music_bucket list to s3songs app, commands

  • Participants
  • Parent commits 692109b
  • Branches default

Comments (0)

Files changed (5)

File sfgeek/apps/s3songs/lib/__init__.py

View file
+__author__ = 'marc'

File sfgeek/apps/s3songs/management/__init__.py

View file
+__author__ = 'marc'

File sfgeek/apps/s3songs/management/commands/__init__.py

View file
+__author__ = 'marc'

File sfgeek/apps/s3songs/management/commands/get_music_bucket_list.py

View file
+__author__ = 'marc'
+# this breaks print
+#from __future__ import print_function
+import pytz
+from datetime import datetime, timedelta
+from django.core.management.base import BaseCommand, CommandError
+import os
+import sys
+import re
+import json
+import getopt
+__author__ = 'marc'
+import boto
+from garage.logger import logger
+
+from s3songs.lib.data_sources.files import music_json_filename
+
+AWS_ACCESS_KEY_ID = 'AKIAJAXY4LMFNR2GTLEA'
+AWS_SECRET_ACCESS_KEY = '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'
+
+BUCKET_NAME = 'music.sfblur.com'
+conn = boto.connect_s3(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY)
+
+class Command(BaseCommand):
+    """
+    pull down bucketlist from s3
+    """
+    args = ''
+    help = ''
+    def handle(self, *args, **options):
+
+        print '----- bucket location -----'
+        bucket = conn.get_bucket(BUCKET_NAME)
+
+        print '----- listing bucket -----'
+        dir_list = bucket.list()
+
+        dictionary = map(lambda x: x.key, dir_list)
+
+        clean_dictionary = []
+        for key in dictionary:
+
+            pattern = '[A-Za-z -\/0-9&()]*\.[Mm][Pp]3'
+            match = re.search(pattern, key)
+            if match:
+                hello_key = bucket.get_key(key)
+                hello_url = hello_key.generate_url(0, query_auth=False, force_http=True)
+
+                newkey = {
+                    'key': re.sub('\.[Mm][Pp]3', '', key.encode('ascii', 'ignore')),
+                    'value': hello_url.replace('.s3.amazonaws.com', ''),
+                }
+                clean_dictionary.append(newkey)
+            else:
+                print 'no match' + key.encode('ascii', 'ignore')
+
+
+        f = open(music_json_filename(), 'w')
+        f.write(json.dumps(clean_dictionary))
+        f.close()
+

File sfgeek/apps/s3songs/tests/tests_user_source_filenames_urls.py

View file
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+import re
+import os
+
+from django.test import TestCase
+
+from django.conf import settings
+
+from django.contrib.auth.models import User
+
+# data service urls
+
+from s3songs.lib.data_sources.files import music_json_filename
+
+
+class SimpleTest(TestCase):
+    u = User()
+    def test_music_json_filename(self):
+        """
+        S3songs App - check music.json constant
+        :return:
+        """
+        self.assertEqual(os.path.join(settings.STATIC_ROOT, 'music.json'),
+                         music_json_filename())