def send_daily_quote(): data = request.get_json(force=True) account_sid = data.get('account_sid', None) if account_sid is None: return jsonify({'status': 400, 'error': 'bad request', 'message': 'Twilio account sid required'}), 400 auth_token = data.get('auth_token', None) if auth_token is None: return jsonify({'status': 400, 'error': 'bad request', 'message': 'Twilio auth token required'}), 400 from_phone = data.get('from_phone', None) if from_phone is None: return jsonify({'status': 400, 'error': 'bad request', 'message': 'Twilio phone number required'}), 400 to_phone = data.get('to_phone', None) if to_phone is None: return jsonify({'status': 400, 'error': 'bad request', 'message': 'To phone number required'}), 400 quote = Goodreads.get_daily_quote() message = "%s by - %s" % (quote['quote'], quote['author']) twilio_response = send_message(account_sid, auth_token, from_phone, to_phone, message) if not twilio_response: return jsonify({'status': 400, 'error': 'bad request', 'message': 'Twilio API details required'}), 400 return jsonify({'message': twilio_response})
def draft_email(team, instance_info): """Draft the email for the team members :param team: A string which is the team name :param instance_info: A list of tuples which is the information of the running instances example : [(name, instance_id, instance_type), (name, instance_id, instance_type) ...] :return: Subject and body for email as two separate strings """ qotd = Goodreads.get_daily_quote() subject = SUBJECT_TMPL.format(team.upper()) body = BODY_TMPL.format(team) for detail in instance_info: body = body + str(detail) + '\n' body += "\n\nQOTD : {0} \n - {1} \n".format(qotd['quote'], qotd['author']) return subject, body
def draft_email(team, instance_info): """Draft the email for the team members :param team: A string which is the team name :param instance_info: A list of tuples which is the information of the running instances example : [(name, instance_id, instance_type), (name, instance_id, instance_type) ...] :return: Subject and body for email as two separate strings """ qotd = Goodreads.get_daily_quote() subject = "ec2notify --> {0} TEAM".format(team.upper()) body = """This is an autogenerated email from ec2notify for the team : {0}. Please shutdown the unused instances !!!\n The following are the running ec2 instances : format : Name, Instance-id, Instance-type.\n """.format(team) for detail in instance_info: body = body + str(detail) + '\n' body += "\n\nQOTD : {0} \n - {1} \n".format(qotd['quote'], qotd['author']) return subject, body
def get_popular_quotes(): quotes = Goodreads.get_popular_quotes() return jsonify({ 'quotes': quotes })
def get_daily_quote(): quote = Goodreads.get_daily_quote() return jsonify(quote)
from goodreads_quotes import Goodreads #sender and receiver email ids fromaddr = '*****@*****.**' toaddr = '*****@*****.**' self_addr = '*****@*****.**' to_sheetal = '*****@*****.**' #MIMEMultipart helps add subject to the mail along with plain body msg = MIMEMultipart() msg['From'] = fromaddr msg['To'] = toaddr msg['Subject'] = "Vocab Digest" #fetching a quote from Goodreads fetch_quote = Goodreads.get_daily_quote() quote = fetch_quote['quote'] author = fetch_quote['author'] #Words and their meanings word1 = "Abberation" mean1 = "deviation from normal" word2 = "Abjure" mean2 = "swear to refrain from something" word3 = "Abrasion" mean3 = "damage to skin OR scraping, rubbing" body = "Good morning Sheetal! \nReady to learn something new? \n\nHere are your words for today\n\n 1. "+word1+": "+mean1+"\n 2. "+word2+": "+mean2+"\n 3. "+word3+": "+mean3+"\n\nQuote of the day:\n\n"+quote+"\n- "+author+"\n\nPS - This is an automated mail, kindly excuse formatting errors and brevity wherever used." msg.attach(MIMEText(body.encode('utf-8'),'plain'))