특정 폴더의 모든 파일을 다운로드하는 Pydrive 스크립트를 작성했습니다.일반 텍스트 PYdrive가 포함 된 Google 문서 도구에서 Github에 가운데 점이 있습니다.
문서는 mimetype이 'text/plain'인 'sampleTitle.md'로 다운로드됩니다.
그들은 단순히 커밋되고 내 리포에 푸시됩니다.
여기 내 pydrive에 대한 파이썬 코드 :
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')
코드 작품과 파일이 다운로드됩니다. 파일의 구글 문서 도구 sthe 시작에서
은 다음과 같습니다
---
layout: post
title: title
---
그것의 YAML을 서문 내가 지킬와 GitHub의 페이지를 필요로한다. 내가 파일을 다운로드 및 REPO에 누르면
그것은 다음과 같습니다
·---
layout: post
title: title
---
난 정말 그 중심에 도트가 입력됩니다 위치를 잘 모릅니다. 그것은 github에만 나타나며 편집자들 모두에게 숨겨져 있습니다 (Atom, Textwrangler, Brackets, TextEdit, VisualStudio Code). 점이 편집자에 있어야하는 백 스페이스를 누르면 숨겨진 점이 제거되는 것 같습니다. 나노에서는 공백으로 표시됩니다.
공백을 제거해야하는 이유는 내 markdown 형식을 방해하기 때문입니다. 효과적인 솔루션이 있습니까?
편집
나는 범인의 문서의 시작 부분에 설정됩니다 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의 파일의 전체 내용을 제거합니다.
다른 사람들은 내가 명령 행에서 잘못된 점을 알고 있습니다. 다른 모든 사람이 명령을 수행하는 것처럼 보이기 때문입니다.
가능한 복제 (HTTP : // 유래.com/questions/1068650/awk-to-remove-the-byte-order-mark) – Waylan
내일 awk 일은 단순히 내 파일을 지우므로 약간 다른 버전이 작동하는지 확인해 보겠습니다. – Opaldes
내 스크립트 확장자가없는 파일을 다운로드 한 후 위의 명령을 사용하여 이후에 확장자를 추가 한 후 작동합니다. – Opaldes