龙卷风网络服务器文件下载问题

时间:2015-05-27 16:14:48

标签: python tornado

我正在python中创建一个转换软件,我将它作为龙卷风网络服务器。我的计划是从服务器下载转换后的文件。我在网上找到了一些示例代码。我的主要问题是这是我第一次使用龙卷风而且我对自己所做的事情知之甚少。

以下是示例代码。

def post(self,filename):
    print('i download file handler : ',filename)

    ifile  = open(filename+".csv", "r")
    self.set_header ('Content-Type', 'text/csv')
    self.set_header ('Content-Disposition', 'attachment; filename='+filename+'')
    self.write (ifile.read())

这是我的代码:

import tornado.ioloop
import tornado.web
import os

print "If at any point you wish to quit the program hit Ctrl + C"

filetype = raw_input("What kind of file would you like to convert? Audio, Image, Video or Document: ")

if filetype == "Document":
   path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
   os.chdir(path[1:-2])
   filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
   Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. txt: ")
   from subprocess import check_call
   check_call(["unoconv", "-f", Fileextension, filename])

elif filetype == "Audio":
   path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
   os.chdir(path[1:-2])
   filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
   Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. mp3: ")
   body, ext = os.path.splitext("filename")
   from subprocess import check_call
   check_call(["ffmpeg" ,"-i", filename, body + "." + Fileextension])

elif filetype == "Video":
   path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
   os.chdir(path[1:-2])
   filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
   Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. mp4: ")
   body, ext = os.path.splitext("filename")
   from subprocess import check_call
   check_call(["ffmpeg" ,"-i", filename, body + "." + Fileextension])

elif filetype == "Image":
   path = raw_input("Please drag and drop the directory in which the file is stored into the terminal:")
   os.chdir(path[1:-2])
   filename = raw_input("Please enter the name of the file you would like to convert, including the file-type. e.g. test.txt, however please do make sure that the file-name does not have any spaces:")
   Fileextension = raw_input("What filetype would you like the program to convert your file to. E.g. JPG: ")
   body, ext = os.path.splitext("filename")
   from subprocess import check_call    
   check_call(["ffmpeg" ,"-i", filename, body + "." + Fileextension])

if __name__ == "__main__":
    application.listen(7777)
try:
    tornado.ioloop.IOLoop.instance().start()
except KeyboardInterrupt:
    tornado.ioloop.IOLoop.instance().stop()

如果有人有解决方案,这将是伟大的。示例代码最好,但此时任何内容都会有用。

0 个答案:

没有答案