Skip to content

Instantly share code, notes, and snippets.

View songokjesse's full-sized avatar
🏠
Working from home

Jesse Songok songokjesse

🏠
Working from home
  • CodeHustle
  • Nairobi, Kenya
View GitHub Profile
@songokjesse
songokjesse / createWorksheetHeader.py
Last active October 26, 2020 10:46
Create a google sheet worksheet header
def createWorksheetHeader(sheet):
# Get the header data
headerData = ['Hits', 'CourseName', 'CourseCode', 'Department', 'Lecturer', 'Students']
# The row you want to enter
index = 1
# Insert the data to row with index
sheet.insert_row(headerData, index)
# format the color
sheet.format('A1:F1', {'textFormat': {'bold': True}})
@songokjesse
songokjesse / CreateNewWorksheet.py
Last active October 26, 2020 10:45
Creating a new google sheet workbook and transferring pandas dataframe data
def createMasterListWorkSheet():
# get cleaned data from the RemoveDuplicateData Function
newData = RemoveDuplicateData()
# get the row count from the dataframe and convert to type int so as to be serialized to json (Produces error if not converted)
rowCount = int(newData['hits'].count())
# create a new sheet
sheet.add_worksheet(title="MASTER_LIST", cols=6, rows=rowCount + 1)
# Get the instance
newSheet = sheet.worksheet("MASTER_LIST")
@songokjesse
songokjesse / RemoveDuplicates.py
Last active October 26, 2020 09:27
Removing Duplicates from Excel Columns
def removeDuplicatedData():
'''
Get the excel data and add it to a dataframe
'''
excelData = sheet_instance.get_all_records()
# Add the excel data from sheet 1 into a dataFrame
mydata = pd.DataFrame.from_dict(excelData)
# Create a blank data list
data = []
@songokjesse
songokjesse / getWorksheet.py
Last active October 26, 2020 09:19
Getting and referencing a google sheet
#Get the google sheet with the name "musomi hits"
sheet = client.open('musomi hits')
#Get the first worksheet (sheet 1)
sheet_instance = sheet.get_worksheet(0)
# or get the worksheet using its name
# sheet_instance = sheet.worksheet("sheet1")
#Get all the records in sheet 1 using a function
@songokjesse
songokjesse / gsheet.py
Created October 26, 2020 08:14
Installation and instantiation of google sheet gspread dependencies
import gspread
import pandas as pd
from oauth2client.service_account import ServiceAccountCredentials
from collections import OrderedDict
# define scope
scope = ['https://spreadsheets.google.com/feeds', 'https://www.googleapis.com/auth/drive']
# add credentials to the account
creds = ServiceAccountCredentials.from_json_keyfile_name('add_json_file_here.json', scope)
@songokjesse
songokjesse / app.js
Last active December 25, 2019 14:11
Express Error Handling Middleware
//catch 404 and forward to error handler
app.use((req,res,next)=>{
let err = new Error('Not Found');
err.status = 404;
next(err);
});
// error handler
app.use((err,req,res,next)=>{