Skip to content

Instantly share code, notes, and snippets.

@felipemeres
Last active February 5, 2023 19:50
Show Gist options
  • Save felipemeres/41a0491a0a53dcfa8a207b86733a6a59 to your computer and use it in GitHub Desktop.
Save felipemeres/41a0491a0a53dcfa8a207b86733a6a59 to your computer and use it in GitHub Desktop.
Python script to export Ditto's clipboard database to a markdown file
# Change the database path to match your system, you can find it in Ditto's settings.
import sqlite3
import datetime
# Connect to the database file
conn = sqlite3.connect(r'C:\path\to\Ditto.db')
cursor = conn.cursor()
# Execute a SELECT statement to retrieve both the mText and lDate columns
cursor.execute("SELECT mText, lDate FROM main")
rows = cursor.fetchall()
# Write the retrieved data to a markdown file
with open('markdown_file.md', 'w', encoding='utf-8') as f:
for row in rows:
# Convert the timestamp to a date string
date = datetime.datetime.fromtimestamp(row[1]).strftime('%Y-%m-%d %H:%M:%S')
f.write('```\n')
f.write('Date: {}\n'.format(date))
for line in row[0].splitlines():
f.write('{}\n'.format(line))
f.write('```\n')
# Close the database connection
conn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment