python [从Yaml文件将Podcast元数据导入Bookend] #podcast #bookends #import #reference
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python [从Yaml文件将Podcast元数据导入Bookend] #podcast #bookends #import #reference相关的知识,希望对你有一定的参考价值。
#!/usr/local/bin/python
# encoding: utf-8
"""
import-podcasts-into-bookends.py
================================
:Summary:
Import Podcasts into Bookends from import folder
:Author:
David Young
:Date Created:
February 9, 2016
:dryx syntax:
- ``_someObject`` = a 'private' object that should only be changed for debugging
:Notes:
- If you have any questions requiring this script/module please email me: d.r.young@qub.ac.uk
Usage:
import-podcasts-into-bookends
-h, --help show this help message
-v, --version show version
-s, --settings the settings file
:Tasks:
@review: when complete pull all general functions and classes into dryxPython
"""
## USER DEFINED VARIABLES - ONLY PLACE THIS SCRIPT NEEDS MODIFIED ##
pathToImportsFolder = "/Users/Dave/Dropbox/notes/thespacedoctor-wiki/projects/Podcast-Workflow/Importing-Podcasts-Into-Bookends/bookends_imports/podcasts"
################# GLOBAL IMPORTS ####################
import sys
import os
os.environ['TERM'] = 'vt100'
import readline
import glob
import docopt
import yaml
from datetime import datetime, date, time
from subprocess import Popen, PIPE, STDOUT
from dryxPython.projectsetup import setup_main_clutil
def main(arguments=None):
"""
The main function used when ``import-podcasts-into-bookends.py`` is run as a single script from the cl, or when installed as a cl command
"""
# setup the command-line util settings
su = setup_main_clutil(
arguments=arguments,
docString=__doc__,
logLevel="DEBUG",
options_first=False,
projectName="lv"
)
arguments, settings, log, dbConn = su.setup()
basePath = pathToImportsFolder
for d in os.listdir(basePath):
if os.path.isdir(os.path.join(basePath, d)):
parentFolder = os.path.join(basePath, d)
yamlFile = parentFolder + "/metadata.yaml"
exists = os.path.exists(yamlFile)
if exists:
stream = file(yamlFile, 'r')
metadata = yaml.load(stream)
stream.close()
# UNPACK METADATA VALUES TO LOCAL()
for arg, val in metadata.iteritems():
varname = arg
if isinstance(val, str) or isinstance(val, unicode):
exec(varname + ' = """%s""" ' % (val,))
else:
exec(varname + " = %s" % (val,))
log.debug('%s = %s' % (varname, val,))
now = datetime.now()
now = now.strftime("%Y")
print parentFolder
applescript = u"""
tell application "Bookends"
open "/Users/Dave/Library/Application Support/Bookends/Library1.bdb"
return «event ToySADDA» "%(parentFolder)s" given «class RIST»:"TY - %(ttype)s" & return & "T1 - %(title)s" & return & "PY - %(now)s" & return & "UR - %(url)s" & return & "KW - %(tags)s" & return & "AV - nice to meet
you
today" & return & "AU - %(author)s" & return
end tell
""" % locals()
print applescript
sys.exit(0)
cmd = "\n".join(["osascript << EOT", applescript, "EOT"])
p = Popen(cmd, stdout=PIPE, stdin=PIPE, shell=True)
output = p.communicate()[0]
log.debug('output: %(output)s' % locals())
output = output.split("\n")
refID = None
try:
refID = int(output[0])
except:
pass
print refID
return
if __name__ == '__main__':
main()
以上是关于python [从Yaml文件将Podcast元数据导入Bookend] #podcast #bookends #import #reference的主要内容,如果未能解决你的问题,请参考以下文章
Postman、Python 以及将图像和元数据传递给 Web 服务
如何在 Python 中使用 ruamel.yaml 从 YAML 文件中获取注释?