GitPython – Diff between two branches

My dear brother started his own blog on Airflow, Python, PostgreSQL and Javascript!!!

Congrats, Ilia!

Илья Катигариди's avatarIlia's Airflow, Python, PostgreSQL, Javascript Journey

Code:

import os
from pathlib import Path 
from git import Repo

# path to repo folder
path = Path(os.path.dirname(os.path.abspath(__file__)))

# repo variable
repo = Repo(path)

# Your last commit of the current branch
commit_feature = repo.head.commit.tree

# Your last commit of the dev branch
commit_origin_dev = repo.commit("origin/dev")
new_files = []
deleted_files = []
modified_files = []

# Comparing 
diff_index = commit_origin_dev.diff(commit_feature)

# Collection all new files
for file in diff_index.iter_change_type('A'):
    new_files.append(file)

# Collection all deleted files
for file in diff_index.iter_change_type('D'):
    deleted_files.append(file)

# Collection all modified files
for file in diff_index.iter_change_type('M'):
    modified_files.append(file)

Analyze:

Let’s imagine the situation:

You are before code review and you need to get all changes between feature and develop with GitPython.
First you need to get last commits from two branches:

# Your last commit of the current branch
commit_dev = repo.head.commit.tree

# Your last commit of the dev branch
commit_origin_dev = repo.commit("origin/dev")

Then get your changes:

View original post 81 more words

Google Drive API with Python – Upload & Download a file

For how to authenticate yourself please go watch this video.

You will need a token.json with this content in the root of your project:

{
  "token": "generated_access_token",
  "refresh_token": "generated_refresh_token",
  "token_uri": "https://oauth2.googleapis.com/token",
  "client_id": "your_client_id",
  "client_secret": "your_client_secret",
  "scopes": [
    "https://www.googleapis.com/auth/drive"
  ]
}

I will be using Google’s Quickstart as a foundation for what I am doing.

Read More »