Last active
August 29, 2015 14:10
-
-
Save kunal732/73ab7bb28a89230e96b8 to your computer and use it in GitHub Desktop.
Day 2 Challenge
This file contains hidden or 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
| 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