简体   繁体   中英

Run Python script to retrieve file links from Amazon S3

I have mp3 files stored in Amazon S3 and I have a MySQL database with a table called Songs. I want to run a Python script that updates my database by going to Amazon S3, retrieves details of the mp3 files (using ID3 for example) and then fills the Songs table in my database. I'm using Django. Is there any way that allows me to run this script by a simple click on an "update library" button for example through the Django admin panel? Also, is it possible to run it on a schedule?

PS I'm new to both Django and Amazon S3

EDIT : I wrote a small script that grabs meta tags from mp3 files in my local machine. Here is the code for it :

import eyeD3
import sys
import urllib
import os

class Track():
    def __init__(self, audioFile):
        self.title = audioFile.getTag().getTitle()
        self.artist = audioFile.getTag().getArtist()
        self.year = audioFile.getTag().getYear()
    self.genre = audioFile.getTag().getGenre()
    self.length = audioFile.getPlayTimeString()
    self.album = audioFile.getTag().getAlbum()

def main():
    for root, dirs, files in os.walk('.'):
        for f in files:
            if eyeD3.isMp3File(f):
                audioFile = eyeD3.Mp3AudioFile(root+'/'+f)
                t = Track(audioFile)
                print t.artist," ",t.title, " ", t.length, " ", t.album, " ", t.genre    




if __name__ == '__main__':
    main()

I would like to find a way to run this script on Django even if ti's locally. I hope my point is clearer.

Thanks in advance !

You need to have a look at Boto and also django-storages for ideas on how to do what you'd like. django-storages makes it dead-simple to replace Django's FileStorage mechanism so you can upload imaes/files directly to your bucket(s) at S3.

Reading from S3 and updating your database objects is just the opposite workflow, but Boto makes it simple to get connected to the bucket(s) and read information.

Hope that helps you out.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM