[英]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. 我有存储在Amazon S3中的mp3文件,并且我有一个带有名为Songs的表的MySQL数据库。 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.
我想运行一个Python脚本,该脚本通过转到Amazon S3更新数据库,检索mp3文件的详细信息(例如,使用ID3),然后在数据库中填充Songs表。 I'm using Django.
我正在使用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?
有什么方法可以让我通过单击“更新库”按钮(例如通过Django管理面板)简单地运行此脚本? Also, is it possible to run it on a schedule?
另外,是否可以按计划运行它?
PS I'm new to both Django and Amazon S3 PS我是Django和Amazon S3的新手
EDIT : I wrote a small script that grabs meta tags from mp3 files in my local machine. 编辑 :我写了一个小脚本,可以从本地计算机中的mp3文件中获取元标记。 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. 我想找到一种方法,即使ti是本地的,也可以在Django上运行此脚本。 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. 您需要查看Boto以及django-storage,以获取有关如何执行所需操作的想法。 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.
django-storages使替换Django的FileStorage机制变得非常简单,因此您可以在S3将imaes /文件直接上传到存储桶。
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. 从S3读取和更新数据库对象只是相反的工作流程,但是Boto使连接到存储桶和读取信息变得简单。
Hope that helps you out. 希望对您有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.