This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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)=>{ |