Skip to content

Instantly share code, notes, and snippets.

@kunal732
Created January 20, 2015 00:22
Show Gist options
  • Save kunal732/7e66e6bfbee30be5d99b to your computer and use it in GitHub Desktop.
Save kunal732/7e66e6bfbee30be5d99b to your computer and use it in GitHub Desktop.
Gets crunchbase analysis of sending email domain and returns an email to the user
from flask import Flask, request
import sendgrid
import requests
app = Flask(__name__)
@app.route ('/incoming', methods =['POST'])
def nextweb():
subject = request.form['subject']
body = request.form['text']
mailfrom = request.form['from']
domain = mailfrom.split("@")[1].rstrip(".com>")
print domain
url = 'https://api.crunchbase.com/v/2/organization/'+domain+'?user_key=your_crunchbase_key'
r = requests.get(url)
#print r
#print url
desc = r.json()
comp_info = desc["data"]["properties"]["description"]
body = " ### " +domain+ " ### "
body = body + comp_info
sg = sendgrid.SendGridClient('SG_user', 'SG_pass')
message = sendgrid.Mail()
message.add_to(mailfrom)
message.set_subject('Re: '+subject)
message.set_html(body)
message.set_text(body)
message.set_from('get@analysis.bymail.ini')
status, msg = sg.send(message)
return "OK"
if __name__=='__main__':
app.run(debug=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment