简体   繁体   English

运行Python脚本以从Amazon S3检索文件链接

[英]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.

相关问题 从 Amazon S3 版本中的先前版本文件中检索数据 - Retrieve data from previous version of file in Amazon S3 Version 如何从python或ruby将Excel文件保存到Amazon S3 - How to save excel file to amazon s3 from python or ruby 从 FTP 检索文件,解压缩文件,将提取文件保存到 Amazon S3 存储桶 - Retrieve file from FTP, unzip file, save extract file to Amazon S3 bucket 如何从 EMR Pyspark 生成的 Amazon S3 中检索 output 文件回 Flask - How to retrieve the output file from Amazon S3 generated from EMR Pyspark back into Flask Django - 从亚马逊 S3 中删除文件 - Django - Delete file from amazon S3 如何使用Boto在Amazon S3上使用python脚本将文件从一个存储桶复制到另一个存储桶 - How to use python script to copy files from one bucket to another bucket at the Amazon S3 with boto 在 S3 文件上运行 Python 脚本 - Run a Python script on S3 Files 实时将Json文件存储到Amazon S3的Python脚本 - Python script to store Json files in real time to amazon S3 使用python从AWS S3到PostgreSQL Amazon RDS的CSV文件 - CSV-File from AWS S3 into PostgreSQL Amazon RDS using python 如何在Google App Engine中使用Python(和boto)通过浏览器从Amazon S3下载文件? - How to download a file via the browser from Amazon S3 using Python (and boto) at Google App Engine?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM