特定のフォルダー内のすべてのファイルをダウンロードする Pydrive スクリプトを作成しました。
ドキュメントは、MIME タイプが「text/plain」の「sampleTitle.md」としてダウンロードされます。
その後、それらは単にコミットされ、私のレポにプッシュされます。
pydrive の私の python コードは次のとおりです。
def checkFile(arg):
if arg['mimeType'] in mimetypes:
downloadFile(arg)
print('The file ' + str(arg['title']) + ' has a mimetype of ' + arg['mimeType'] + ' and will be downloaded')
return
if arg['mimeType'] in folder:
enterFolder(arg['id'])
print('The file ' + str(arg['title']) + ' has a mimetype of ' + arg['mimeType'] + ' and will be entered')
return
def enterFolder(query):
file_list = drive.ListFile({'q': '\'' + query + '\' in parents and trashed=false'}).GetList()
for file1 in file_list:
checkFile(file1)
return
def downloadFile(arg):
download_mimetype = None
download_mimetype = mimetypes[arg['mimeType']]
arg.GetContentFile(arg['title'], mimetype=download_mimetype)
print(arg['title'] + 'got downloaded')
return
import sys
sys.path.insert(1, '/Library/Python/2.7/site-packages')
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.
from pydrive.drive import GoogleDrive
mimetypes = {
# Drive Document files as plain text.
'application/vnd.google-apps.document': 'text/plain'
# etc.
}
folder = {
# Comparing for folder.
'application/vnd.google-apps.folder': 'true'
# etc.
}
# Create GoogleDrive instance with authenticated GoogleAuth instance.
drive = GoogleDrive(gauth)
# Auto-iterate through all files that matches this query
enterFolder('starfolder')
コードが機能し、ファイルがダウンロードされます。
Google ドキュメントでは、ファイルの先頭は次のようになります。
---
layout: post
title: title
---
jekyll および github ページに必要な YAML フロント マターです。
ファイルをダウンロードしてリポジトリにプッシュすると、次のようになります。
·---
layout: post
title: title
---
その中央のドットがどこに入力されるのか本当にわかりません。これは github にのみ表示され、すべてのエディター (Atom、Textwrangler、Brackets、TextEdit、VisualStudio Code) では非表示になっています。エディターでドットがあるはずの場所でバックスペースを押すと、非表示のドットが削除されるようです。Nano では空白として表示されます。
マークダウン形式が乱れるため、何らかの形で空白を削除する必要があります。効果的な解決策はありますか?
編集
ドキュメントの先頭に設定されている BOM が原因であることがわかりました。シェルコマンドを使用して削除しようとしましたが、機能するものが見つかりません。次の例を試しました:
awk '{if(NR==1)sub(/^\xef\xbb\xbf/,"");print}' text.md > text.md
sed '1 s/\xEF\xBB\xBF//' < text.md > text.md
BOM だけでなく、ファイルの内容全体を削除します。
他の誰もがコマンドを機能させているように見えるので、コマンドラインで私が間違っていることを誰かが知っていますか。