Skip to content

Instantly share code, notes, and snippets.

@kunal732
Created September 30, 2014 21:05
Show Gist options
  • Select an option

  • Save kunal732/e1b59150412d7dcc164e to your computer and use it in GitHub Desktop.

Select an option

Save kunal732/e1b59150412d7dcc164e to your computer and use it in GitHub Desktop.
Inbound Email to Google Spreadsheet
from flask import Flask, request
import requests
import os
import gspread
app = Flask(__name__)
googleUser = ''
googlePass = ''
gc = gspread.login(googleUser, googlePass)
wks = gc.open("Replace with your SpreadSheet name").sheet1
def getNextRow():
values_list = wks.col_values(1) #gets all values in first column
emptyrow = str(len(values_list)+1)
return emptyrow
def addRow(email, subject, spam_score):
row = getNextRow()
emailCell = 'A'+row
subjectCell = 'B'+row
spamCell = 'C'+row
wks.update_acell(emailCell, email)
wks.update_acell(subjectCell, subject)
wks.update_acell(spamCell, spam_score)
@app.route('/', methods = ['POST'])
def insertData():
email = request.form['from']
subject = request.form['subject']
spamscore = request.form['spam_score']
addRow(email, subject, spamscore)
return "OK"
if __name__ == '__main__':
app.debug = True
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment