Skip to content

Instantly share code, notes, and snippets.

@kunal732
Last active August 29, 2015 14:10
Show Gist options
  • Select an option

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

Select an option

Save kunal732/73ab7bb28a89230e96b8 to your computer and use it in GitHub Desktop.
Day 2 Challenge
from flask import Flask, request
import json
import sendgrid
app = Flask(__name__)
sg = sendgrid.SendGridClient('username', 'password')
@app.route('/',methods=['POST'])
def foo():
data = json.loads(request.data)
body = ""
for x in data['results']['collection1']:
body = body + format(x['TV Name']['text'])
body = body + '<br>'
body = body + format(x['TV Price'])
body = body + '<br>'
body = body + format(x['Savings'])
body = body + '<br><br><br>'
subject = "Changes to Best Buy Black Friday TV DEALS!!!"
sender = "[email protected]"
to = "[email protected]"
message = sendgrid.Mail()
message.add_to(to)
message.set_subject(subject)
message.set_html(body)
message.set_text(body)
message.set_from(sender)
status, msg = sg.send(message)
return "OK"
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment