Devadutta Ghat's Blog

Day 2: Backup your SQLite database to GitHub – ChatGPT vs. Claude

Today, I got access to Anthropic’s Claude so why not use that to solve a problem I have?


Can you write a python backup script to commit and push a sqllite db into git using the github access tokens? I actually only want to commit and push the file if it has changed since the last time I committed it. can you just use requests and the github rest api?


import requests
import os
import datetime

# GitHub access token 
access_token = 'YOUR_ACCESS_TOKEN'

# Repository name 
repo_name = 'YOUR_REPO_NAME'

# Database file path
db_path = 'database.sqlite'

# Get last commit SHA for the database file
url = f'{repo_name}/contents/{db_path}'
headers = {'Authorization': f'token {access_token}'}
response = requests.get(url, headers=headers)
last_sha = response.json()['sha']

# Get latest commit for the database file 
latest_commit = os.stat(db_path).st_mtime
timestamp = datetime.datetime.fromtimestamp(latest_commit)

# Check if the database file has changed since last commit
if timestamp > datetime.datetime.strptime(last_sha, '%Y-%m-%d %H:%M:%S'):
    # Read the database file
    with open(db_path, 'rb') as f:
        content =
    # Commit and push the changes 
    url = f'{repo_name}/contents/{db_path}'
    payload = {'message': f'Commit as of {timestamp}', 
               'content': content.decode('utf-8'), 
               'sha': last_sha}
    headers = {'Authorization': f'token {access_token}'}
    response = requests.put(url, json=payload, headers=headers)

ChatGPT vs. Claude?

When I asked ChatGPT the same question, it came out with a more verbose answer. Probably Claude is default prompted to be more succinct code writer to save on tokens outputted, maybe because they don’t want a slack bot to put in a wall of text. Maybe.

Number of lines
ChatGPT ▏   62 █████████████████████████
 Claude ▏   36 ██████████████▌
Number of words
ChatGPT ▏  174 █████████████████████████
 Claude ▏  124 █████████████████▊

So yeah, in my totally unscientific test, Claude outputted 41% shorter code, but I think I will stick to ChatGPT for now as the whole style of writing code function by function has so many advantages that you’ll see in future examples with langchain.