Skip to content

Instantly share code, notes, and snippets.

@jag3773
Created August 26, 2023 16:56
Show Gist options
  • Save jag3773/5db13c90befff5697d6711a7d1287f6c to your computer and use it in GitHub Desktop.
Save jag3773/5db13c90befff5697d6711a7d1287f6c to your computer and use it in GitHub Desktop.
Google Drive File List to Obsidian
#!/usr/bin/env python3
#
# First, install File Cabinet by Awesome Table plugin. Follow their [instructions](https://support.awesome-table.com/hc/en-us/articles/360004223619--Part-2-Use-Files-Cabinet-to-display-Google-Drive-contents) to list all of your Google Drive files + metadata. You should end up with a Google Sheet that has all of your files listed on one or more sheets.
# Second, download the sheet(s) from the above Google Sheet as CSV files (into your Downloads directory).
# Third, modify 'outputdir' (line 11) and the path to your CSV file at the bottom (line 38)
# Fourth, run this script
import csv
from datetime import datetime
outputdir = '/path/to/your/vault/resources/gdrive/'
def csvToMD(inputcsv):
inputdictionary = csv.DictReader(open(inputcsv))
for row in inputdictionary:
if not row['Creation date'].startswith('Date'):
title = row.pop('Title')
cdate = datetime.strptime(row['Creation date'], '%m/%d/%Y')
outfilename = cdate.strftime('%Y-%m-%d') + ' ' + title
sanitizedname = ''.join([c for c in outfilename if c.isalpha() or c.isdigit() or c in '.-_ ']).strip()
outfilepath = outputdir + sanitizedname + '.md'
#print(outfilepath)
row.pop('Id')
row.pop('Creation date')
row.pop('Owner Infos')
row.pop('Owner')
content = '---\n'
for k,v in row.items():
if v:
content += '{0}: "{1}"\n'.format(k,v)
content += '---'
outfile = open(outfilepath, 'w')
outfile.write(content.strip())
outfile.close()
#break
if __name__ == '__main__':
csvToMD('/your/home/Downloads/GDrive All Files.csv')
print('Finished importing')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment