new_row_on_github_csv.py
Je Sian Keith Herman November 27, 2022 #Python #Scripting #CSV #Data ExtractionReading a csv file on GitHub, appending a new row to it, and committing it back again to GitHub.1
# Import packages
# For .env files
# import base64
# Do `pip install pygithub` first: https://stackoverflow.com/a/50072113
# dotenv.load_dotenv()
# Make sure to have an environment variable for GitHub authentication
=
=
# Specify repo and path to CSV file
=
=
# Make GET request for current CSV file
=
# Convert CSV file to pandas DataFrame
=
=
# Specify contents of the new row in key-value pairs
=
# Concatenate new row to df
=
=
# Write new version of the CSV file with appended row
# --------------------------------------------------------
# user = os.environ["GITHUB_USERNAME"]
# access_token = os.environ["GITHUB_TOKEN"]
# password = os.environ["GITHUB_PASSWORD"]
# Authenticate with GitHub
=
# Get Repository
# repo_name = 'your-github-repo-name'
=
# Save path to current working directory
=
# Add file_names relative to the root
=
=
# Directory separator
# Windows
=
# Linux/MacOS
=
# Save full-length file paths
# Commit Message
= +
# Get latest commit refs
= # on main branch
=
=
# Initialize empty list for git elements
=
# Populate list
=
=
# Commit new files
=
=
=
1
👀 Might be useful??? It's not like I'm using a CSV file as a database.