Episode 1 - The Python Menace

Description:
In this tutorial we will crawl quotes from Star Wars The clone wars, clean the format and automate a daily random email.

Activities included in this tutorial:

  • Web scraping and automated mailing
  • Python and SQL

Topics:

  • Data mining
  • Automation
  • Natural Language Processing (NLP)
  • SQL
  • Web scraping
  • Machine learning

Path of the Python Menace:

  1. Get the force in the quotes
  2. Send the quotes through email

Episode 2

  1. Classify the quotes by topics using Natural language processing + Machine Learning
  2. Select a specific topic and receive a quote
    1. Use jupyter buttons
    2. Save the logs to the SQL palace

Theme: Starwars, python

The website is from mytowntutors.com : quotes link


In [1]:
import webbrowser
import requests
import bs4
import csv
import pandas as pd
res = requests.get('http://mytowntutors.com/2014/04/star-wars-the-clone-wars/')

print(res.status_code == requests.codes.ok)
print("Number of lines in te downloaded page: %i"%len(res.text))
print("The first 20 thousand lines for a quick assesment. Hint: by using the finder it will give you an idea of the tags related to the info.")
print(res.text[:20000]) # quick assesment


True
Number of lines in te downloaded page: 21122
The first 20 thousand lines for a quick assesment. Hint: by using the finder it will give you an idea of the tags related to the info.
<!DOCTYPE html>
<html dir="ltr" lang="en-US">
<head>
<meta charset="UTF-8" />
<title>Star Wars The Clone Wars: 98 Clone Wars Quotes | My Town Tutors</title>
<link rel="stylesheet" type="text/css" media="all" href="http://mytowntutors.com/wp-content/themes/mytowntutor/style.css" />
<link rel="pingback" href="http://mytowntutors.com/xmlrpc.php" />
<link rel="alternate" type="application/rss+xml" title="My Town Tutors &raquo; Feed" href="http://mytowntutors.com/feed/" />
<link rel="alternate" type="application/rss+xml" title="My Town Tutors &raquo; Comments Feed" href="http://mytowntutors.com/comments/feed/" />
<script type='text/javascript' src='http://mytowntutors.com/wp-includes/js/l10n.js?ver=20101110'></script>
<script type='text/javascript' src='http://mytowntutors.com/wp-includes/js/comment-reply.js?ver=20090102'></script>
<link rel="EditURI" type="application/rsd+xml" title="RSD" href="http://mytowntutors.com/xmlrpc.php?rsd" />
<link rel="wlwmanifest" type="application/wlwmanifest+xml" href="http://mytowntutors.com/wp-includes/wlwmanifest.xml" /> 
<link rel='index' title='My Town Tutors' href='http://mytowntutors.com/' />
<link rel='start' title='P is the Kindergarten &#8220;Letter of the Week&#8221;' href='http://mytowntutors.com/2011/01/p-is-the-kindergarten-letter-of-the-week/' />
<link rel='prev' title='Social Media: 5 Goals of a Tweet' href='http://mytowntutors.com/2014/04/social-media-5-goals-of-a-tweet/' />
<link rel='next' title='Top 10 Quotes for Teachers: Translated By Yoda' href='http://mytowntutors.com/2014/04/top-10-quotes-for-teachers-translated-by-yoda/' />
<meta name="generator" content="WordPress 3.1.4" />
<link rel='shortlink' href='http://mytowntutors.com/?p=31713' />

<!-- All in One SEO Pack 1.6.13.3 by Michael Torbert of Semper Fi Web Design[82,152] -->
<meta name="description" content="Star Wars: The Clone Wars. Star Wars The Clone Wars: 98 Clone Wars Quotes" />
<meta name="keywords" content="star wars: the clone wars, star wars the clone wars: 98 clone wars quotes,star wars the clone wars: 98 clone wars quotes" />
<link rel="canonical" href="http://mytowntutors.com/2014/04/star-wars-the-clone-wars/" />
<!-- /all in one seo pack -->
<script type="text/javascript" src="http://mytowntutors.com/wp-content/themes/mytowntutor/js/jquery.tools.min.js"></script>
<script type="text/javascript" src="http://mytowntutors.com/wp-content/themes/mytowntutor/js/cufon-yui.js"></script>
<script type="text/javascript" src="http://mytowntutors.com/wp-content/themes/mytowntutor/js/Eraser_500.font.js"></script>
<script type="text/javascript">
		// Cufon.replace('body');
		Cufon('#nav a', {
			hover: {
				color: '#ffc'
			}
		});		
</script>
<script type="text/javascript">
function clearText(thefield){
	if (thefield.defaultValue==thefield.value) thefield.value = "";
}
function resetText(thefield){
	if (thefield.value=="") thefield.value = thefield.defaultValue;
}

function resetFormElements(oForm, sType){
	var aElems = oForm.elements;
	for (var iI=0;iI<aElems.length-3;iI++){
		if (aElems[iI].type = sType) aElems[iI].checked = false;
	}
}
</script>
</head>

<body>
<div id="headerwrap">
	<div id="header">
		            <div id="notlogged">
            	<a href="http://mytowntutors.com/login">Tutor Login &raquo;</a>
            </div>
                
        <div id="logo">
            <a href="http://mytowntutors.com"><img src="http://mytowntutors.com/wp-content/themes/mytowntutor/images/logo.png" alt="MyTownTutor Logo" /></a>
        </div>
        <div id="topsearch">
            <form action="http://mytowntutors.com/find-a-tutor/" method="post">
                <ul>
                	<li><strong>Find a tutor in your area:</strong></li>
                    <li><input type="text" name="zip" value="Zip Code" onFocus="clearText(this)" onBlur="resetText(this)" class="field" /></li>
                    <li>
                        <select name="range">
                        	                            <option value="15">15 Miles</option>
                            <option value="5">5 Miles</option>
                            <option value="10">10 Miles</option>                            
                            <option value="20">20 Miles</option>
                            <option value="25">25 Miles</option>
                        </select>
                    </li>
                    <li><input type="submit" name="search" value="Find" class="button" /></li>
                </ul>
            </form>        
        </div>
	</div>        
</div>
<div id="navwrap">
	<div id="nav">
    	<div id="social">
        	<a href="https://www.facebook.com/pages/My-Town-Tutors/231169106897790"><img src="http://mytowntutors.com/wp-content/themes/mytowntutor/images/facebook.png" alt="Follow Us on Facebook" /></a>
        	<a href="https://twitter.com/#!/mytowntutors"><img src="http://mytowntutors.com/wp-content/themes/mytowntutor/images/twitter.png" alt="Follow Us on Twitter" /></a>
        	<a href="http://www.linkedin.com/in/wwwmytowntutorscom"><img src="http://mytowntutors.com/wp-content/themes/mytowntutor/images/linkedin.png" alt="LinkedIn" /></a>
        	<a href="http://www.delicious.com/?view=fresh"><img src="http://mytowntutors.com/wp-content/themes/mytowntutor/images/delicious.png" alt="Delicious" /></a>
        	<a href="http://mytowntutors.com/feed/"><img src="http://mytowntutors.com/wp-content/themes/mytowntutor/images/rss.png" alt="Subscribe to our RSS Feed" /></a>
        </div>
    	<ul>
        	<li class="page_item page-item-2"><a href="http://mytowntutors.com/sample-page/" title="About Us">About Us</a></li>
<li class="page_item page-item-8"><a href="http://mytowntutors.com/become-a-tutor/" title="Become A Tutor">Become A Tutor</a></li>
<li class="page_item page-item-10"><a href="http://mytowntutors.com/blog/" title="My Town Tutors Blog">Blog</a></li>
<li class="page_item page-item-7038"><a href="http://mytowntutors.com/coaching-youth-basketball/" title="Coaching Youth Basketball">Coaching Youth Basketball</a></li>
<li class="page_item page-item-6"><a href="http://mytowntutors.com/find-a-tutor/" title="FINd A Tutor">FINd A Tutor</a></li>
<li class="page_item page-item-94"><a href="http://mytowntutors.com/guest-bloggers/" title="Guest blogs">Guest Blogs</a></li>
<li class="page_item page-item-196"><a href="http://mytowntutors.com/parent-pages/" title="Parent Pages">Parent Pages</a></li>
<li class="page_item page-item-30963"><a href="http://mytowntutors.com/support-our-sponsors/" title="Support our Sponsors">Support our Sponsors</a></li>
<li class="page_item page-item-23692"><a href="http://mytowntutors.com/teacher-resources/" title="Teacher Resources">Teacher Resources</a></li>
<li class="page_item page-item-236"><a href="http://mytowntutors.com/testimonials/" title="Testimonials">Testimonials</a></li>
<li class="page_item page-item-44170"><a href="http://mytowntutors.com/tutoring/" title="Tutoring">Tutoring</a></li>
<li class="page_item page-item-50183"><a href="http://mytowntutors.com/worlds-best-jokes/" title="World's Best Jokes">World&#8217;s Best Jokes</a></li>
            <li><a href="http://mytowntutors.com/promote">Promote MTT</a></li>
        </ul>
    </div>
</div>
        <div id="content">
            <div id="sidebar">
	<div id="randomtutor">
    	        <h2>Mary Carrig<span>, </span></h2>
        <img src="http://mytowntutors.com/images/tutors/missing.jpg" alt="Mary Carrig" />
        <ul>
            <li><label>School:</label><span>Thomas E. Willett School</span></li>
            <li><label>About Mary:</label><p>Special Education Teacher trained in Lindamood Bell Lips, Wilson Reading System, Project Read and Write Traits.</p></li>
        </ul>
		<a href="http://mytowntutors.com/tutors/136/mary-carrig-02703" class="button">More Info &raquo;</a>        
    </div>
</div>    	        
            <div id="breadcrumb">
                <a href="http://mytowntutors.com">My Town Tutors</a> &raquo; <a href="http://mytowntutors.com/category/latest-news/" title="View all posts in Latest News" rel="category tag">Latest News</a> &raquo; Star Wars The Clone Wars: 98 Clone Wars Quotes    
            </div>        
            <div id="main">
                

				<div id="post-31713" class="post-31713 post type-post status-publish format-standard hentry category-latest-news tag-star-wars-the-clone-wars-98-clone-wars-quotes tag-star-wars-the-clone-wars">
					<h1 class="entry-title">Star Wars The Clone Wars: 98 Clone Wars Quotes</h1>

					<div class="entry-meta">
						<span class="meta-prep meta-prep-author">Posted on</span> <a href="http://mytowntutors.com/2014/04/star-wars-the-clone-wars/" title="7:44 pm" rel="bookmark"><span class="entry-date">April 26, 2014</span></a> <span class="meta-sep">by</span> <span class="author vcard"><a class="url fn n" href="http://mytowntutors.com/author/" title="View all posts by "></a></span>					</div><!-- .entry-meta -->

					<div class="entry-content">
						<p>Each episode starts with an inspirational quote / lesson. We included the title of the episode and the quote.</p>
<p>May the Force be with you!</p>
<p><em><strong>Please Share!</strong></em></p>
<p><a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.mytowntutors.com/2014/04/star-wars-the-clone-wars/" data-text="#StarWars The Clone Wars: 98 Clone Wars Quotes" data-via="MyTownTutors" data-hashtags="Maythe4th">Tweet</a><br />
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script></p>
<p>&nbsp;</p>
<p>Season One</p>
<ol>
<li>Ambush: &#8220;Great leaders inspire greatness in others.&#8221;</li>
<li>Rising Malevolence: &#8220;Belief is not a matter of choice, but conviction.&#8221;</li>
<li>Shadow of Malevolence: &#8220;Easy is the path to wisdom for those not blinded by ego.&#8221;</li>
<li>Destroy Malevolence: &#8220;A plan is only as good as those who see it through.&#8221;</li>
<li>Rookies: &#8220;The best confidence builder is experience.&#8221;</li>
<li>Downfall of a Droid: &#8220;Trust in your friends, and they&#8217;ll have reason to trust in you.&#8221;</li>
<li>Duel of the Droids: &#8220;You hold onto your friends by keeping your heart a little softer than you head.&#8221;</li>
<li>Bombad Jedi: &#8220;Heroes are made by the times.&#8221;</li>
<li>Cloak of Darkness: &#8220;Ignore your instincts at your peril.&#8221;</li>
<li>Lair of Grievous: &#8220;Most powerful is he who controls his own power.&#8221;</li>
<li>Dooku Captured: &#8220;The winding path to peace is always a worthy one, regardless of how many turns it takes.&#8221;</li>
<li>The Gungan General: &#8220;Fail with honor rather than succeed with fraud.&#8221;</li>
<li>Jedi Crash: &#8220;Greed and fear of loss are the roots that lead to the tree of evil.&#8221;</li>
<li>Defenders of Peace: &#8220;When surrounded by war, one must eventually choose a side.&#8221;</li>
<li>Trespass: &#8220;Arrogance diminishes wisdom.&#8221;</li>
<li>The Hidden Enemy: &#8220;Truth enlightens the mind, but won&#8217;t always bring happiness to your heart.&#8221;</li>
<li>Blue Shadow Virus: &#8220;Fear is a disease; hope is its only cure.&#8221;</li>
<li>Mystery of a Thousand Moons: &#8220;A single chance is a galaxy of hope.&#8221;</li>
<li>Storm Over Ryloth: &#8220;It is a rough road that leads to the heights of greatness.&#8221;</li>
<li>Innocents of Ryloth: &#8220;The costs of war can never be truly accounted for.&#8221;</li>
<li>Liberty on Ryloth: &#8220;Compromise is a virtue to be cultivated, not a weakness to be despised.&#8221;</li>
<li>Hostage Crisis: &#8220;A secret shared is a trust formed.&#8221;</li>
</ol>
<p>Season Two</p>
<ol>
<li>Holocron Heist: &#8220;A lesson learned is a lesson earned.&#8221;</li>
<li>Cargo of Doom: &#8220;Overconfidence is the most dangerous form of carelessness.&#8221;</li>
<li>Children of the Force: &#8220;The first step to correcting a mistake is patience.&#8221;</li>
<li>Senate Spy: &#8220;A true heart should never be doubted.&#8221;</li>
<li>Landing at Point Rain: &#8220;Believe in yourself or no one else will.&#8221;</li>
<li>Weapons Factory: &#8220;No gift is more precious than trust.&#8221;</li>
<li>Legacy of Terror: &#8220;Sometimes, accepting help is harder than offering it.&#8221;</li>
<li>Brain Invaders: &#8220;Attachment is not compassion&#8221;</li>
<li>Grievous Intrigue: &#8220;For everything you gain, you lose something else.&#8221;</li>
<li>The Deserter: &#8220;It is the quest for honor that makes one honorable.&#8221;</li>
<li>Lightsaber Lost: &#8220;Easy isn&#8217;t always simple.&#8221;</li>
<li>The Mandalore Plot: &#8220;If you ignore the past, you jeopardize your future.&#8221;</li>
<li>Voyage of Temptation: &#8220;Fear not for the future, weep not for the past.&#8221;</li>
<li>Duchess of Mandalore: &#8220;In war, truth is the first casualty.&#8221;</li>
<li>Senate Murders: &#8220;Searching for the truth is easy. Accepting the truth is hard.&#8221;</li>
<li>Cat and Mouse: &#8220;A wise leader knows when to follow.&#8221;</li>
<li>Bounty Hunters: &#8220;Courage makes heroes, but trust builds friendship.&#8221;</li>
<li>The Zillo Beast: &#8220;Choose what is right, not what is easy&#8221;</li>
<li>The Zillo Beast Strikes Back: &#8220;The most dangerous beast is the beast within.&#8221;</li>
<li>Death Trap: &#8220;Who my father was matters less than my memory of him.&#8221;</li>
<li>R2 Come Home: &#8220;Adversity is friendship&#8217;s truest test.&#8221;</li>
<li>Lethal Trackdown: &#8220;Revenge is a confession of pain.&#8221;</li>
</ol>
<p>Season Three</p>
<ol>
<li>Clone Cadets: &#8220;Brothers in arms are brothers for life.&#8221;</li>
<li>ARC Troopers: &#8220;Fighting a war tests a soldier&#8217;s skills, defending his home tests a soldier&#8217;s heart.&#8221;</li>
<li>Supply Lines: &#8220;Where there&#8217;s a will, there&#8217;s a way.&#8221;</li>
<li>Sphere of Influence: &#8220;A child stolen is a lost hope.&#8221;</li>
<li>Corruption: &#8220;The challenge of hope is to overcome corruption.&#8221;</li>
<li>The Academy: &#8220;Those who enforce the law must obey the law.&#8221;</li>
<li>Assassin: &#8220;The future has many paths &#8212; choose wisely.&#8221;</li>
<li>Evil Plans: &#8220;A failure in planning is a plan for failure.&#8221;</li>
<li>Hunt for Ziro: &#8220;Love comes in all shapes and sizes.&#8221;</li>
<li>Heroes on Both Sides: &#8220;Fear is a great motivator.&#8221;</li>
<li>Pursuit of Peace: &#8220;Truth can strike down the specter of fear&#8221;</li>
<li>Nightsisters: &#8220;The swiftest path to destruction is through vengeance.&#8221;</li>
<li>Monster: &#8220;Evil is not born, it is taught.&#8221;</li>
<li>Witches of the Mist: &#8220;The path to evil may bring great power, but not loyalty.&#8221;</li>
<li>Overlords: &#8220;Balance is found in the one who faces his guilt.&#8221;</li>
<li>Altar of Mortis: &#8220;He who surrenders hope, surrenders life.&#8221;</li>
<li>Ghosts of Mortis: &#8220;He who seeks to control fate shall never find peace.&#8221;</li>
<li>The Citadel: &#8220;Adaptation is the key to survival.&#8221;</li>
<li>Counterattack: &#8220;Anything that can go wrong will.&#8221;</li>
<li>Citadel Rescue: &#8220;Without honor, victory is hollow.&#8221;</li>
<li>Padawan Lost: &#8220;Without humility, courage is a dangerous game.&#8221;</li>
<li>Wookiee Hunt: &#8220;A great student is what the teacher hopes to be.&#8221;</li>
</ol>
<p>Season Four</p>
<ol>
<li>Water wars: &#8220;When destiny calls, the chosen have no choice.&#8221;</li>
<li>Gungan Attack: &#8220;Only through fire is a strong sword forged.&#8221;</li>
<li>Prisoners: &#8220;Crowns are inherited, kingdoms are earned.&#8221;</li>
<li>Shadow Warrior: &#8220;Who a person truly is cannot be seen with the eye.&#8221;</li>
<li>Mercy Mission: &#8220;Understanding is honoring the truth beneath the surface.&#8221;</li>
<li>Nomad Droids: &#8220;Who&#8217;s the more foolish, the fool or the fool who follows him?&#8221;</li>
<li>Darkness on Umbara: &#8220;The first step toward loyalty is trust.&#8221;</li>
<li>The General: &#8220;The path of ignorance is guided by fear.&#8221;</li>
<li>Plan of Dissent: &#8220;The wise man leads, the strong man follows.&#8221;</li>
<li>Carnage of Krell: Our actions define our legacy.&#8221;</li>
<li>Kidnapped: &#8220;Where we are going always reflects where we came from.&#8221;</li>
<li>Slaves of the Republic: &#8220;Those who enslave others inevitably become slaves themselves.&#8221;</li>
<li>Escape from Kadavo: &#8220;Great hope can come from small sacrifices.&#8221;</li>
<li>A Friend in Need: &#8220;Friendship shows us who we really are.&#8221;</li>
<li>Deception: &#8220;All warfare is based on deception.&#8221;</li>
<li>Friends and Enemies: &#8220;Keep your friends close, but keep your enemies closer.&#8221;</li>
<li>The Box: &#8220;The strong survive, the noble overcome.&#8221;</li>
<li>Crisis on Naboo: &#8220;Trust is the greatest of gifts, but it must be earned.&#8221;</li>
<li>Massacre: &#8220;One must let go of the past to hold onto the future.&#8221;</li>
<li>Bounty: &#8220;Who we are never changes, who we think we are does.&#8221;</li>
<li>Brothers: &#8220;A fallen enemy may rise again, but the reconciled one is truly vanquished.&#8221;</li>
<li>Revenge: &#8220;The enemy of my enemy is my friend.&#8221;</li>
</ol>
<p>Season Five</p>
<ol>
<li>Revival: &#8220;Strength in character can defeat strength in numbers.&#8221;</li>
<li>A War on Two Fronts: &#8220;Fear is a malleable weapon.&#8221;</li>
<li>Front Runners: &#8220;To seek something is to believe in its possibility.&#8221;</li>
<li>The Soft War: &#8220;Struggles often begin and end with the truth.&#8221;</li>
<li>Tipping Points: &#8220;Disobedience is a demand for change.&#8221;</li>
<li>The Gathering: &#8220;He who faces himself, finds himself.&#8221;</li>
<li>A Test of Strength: &#8220;The young are often underestimated.&#8221;</li>
<li>Bound for Rescue: &#8220;When we rescue others, we rescue ourselves.&#8221;</li>
<li>A Necessary Bond: &#8220;Choose your enemies wisely, as they may be your last hope.&#8221;</li>
<li>Secret Weapons: &#8220;Humility is the only defense against humiliation.&#8221;</li>
<li>A Sunny Day in the Void: &#8220;When all seems hopeless, a true hero gives hope.&#8221;</li>
<li>Missing in Action: &#8220;A soldier&#8217;s most powerful weapon is courage.&#8221;</li>
<li>Point of No Return: &#8220;You must trust in others or success is impossible.&#8221;</li>
<li>Eminence: &#8220;One vision can have many interpretations.&#8221;</li>
<li>Shades of Reason: &#8220;Alliances can stall true intentions.&#8221;</li>
<li>The Lawless: &#8220;Morality separates heroes from villains.&#8221;</li>
<li>Sabotage: &#8220;Sometimes even the smallest doubt can shake the greatest belief.&#8221;</li>
<li>The Jedi who knew too much: &#8220;Courage begins by trusting oneself.&#8221;</li>
<li>To catch a Jedi: &#8220;Never become desperate enough to trust the untrustworthy.&#8221;</li>
<li>The Wrong Jedi: Never give up hope, no matter how dark things seem.&#8221;</li>
</ol>
											</div><!-- .entry-content -->

				</div><!-- #post-## -->

				
			<div id="comments">


	<p class="nocomments">Comments are closed.</p>


								
</div><!-- #comments -->

            </div><!-- #content -->
        </div>
<div id="footwrap">
	<div id="footer">
    	<div id="footlogo">
            <p>MTT, LLC<br />112 Ashburton Ave<br />Marshfield, MA 02050<br />(617) 851.6106 <br /><a href="mailto:info@mytowntutor.com">info@mytowntutor.com</a></p>
        </div>
        <div id="footlinks">
        	<ul>
                <li class="first"><a href="h

Getting the quotes

Extracting the quotes


In [2]:
starwars_website = bs4.BeautifulSoup(res.text)
starwars_quotes = starwars_website.select('li')

print("Number of elements that have li tag" + str(len(starwars_quotes)));

starwars_quotes[126].getText(); # Since the quotes are together we need to find the first
                                # quote and the last. In this case were 19 and 127 respectively

starwar_quotes_selected = []
for quote in starwars_quotes[19:127]:
    starwar_quotes_selected.append(quote.getText())
starwar_quotes_selected


Number of elements that have li tag132
Out[2]:
[u'Ambush: \u201cGreat leaders inspire greatness in others.\u201d',
 u'Rising Malevolence: \u201cBelief is not a matter of choice, but conviction.\u201d',
 u'Shadow of Malevolence: \u201cEasy is the path to wisdom for those not blinded by ego.\u201d',
 u'Destroy Malevolence: \u201cA plan is only as good as those who see it through.\u201d',
 u'Rookies: \u201cThe best confidence builder is experience.\u201d',
 u'Downfall of a Droid: \u201cTrust in your friends, and they\u2019ll have reason to trust in you.\u201d',
 u'Duel of the Droids: \u201cYou hold onto your friends by keeping your heart a little softer than you head.\u201d',
 u'Bombad Jedi: \u201cHeroes are made by the times.\u201d',
 u'Cloak of Darkness: \u201cIgnore your instincts at your peril.\u201d',
 u'Lair of Grievous: \u201cMost powerful is he who controls his own power.\u201d',
 u'Dooku Captured: \u201cThe winding path to peace is always a worthy one, regardless of how many turns it takes.\u201d',
 u'The Gungan General: \u201cFail with honor rather than succeed with fraud.\u201d',
 u'Jedi Crash: \u201cGreed and fear of loss are the roots that lead to the tree of evil.\u201d',
 u'Defenders of Peace: \u201cWhen surrounded by war, one must eventually choose a side.\u201d',
 u'Trespass: \u201cArrogance diminishes wisdom.\u201d',
 u'The Hidden Enemy: \u201cTruth enlightens the mind, but won\u2019t always bring happiness to your heart.\u201d',
 u'Blue Shadow Virus: \u201cFear is a disease; hope is its only cure.\u201d',
 u'Mystery of a Thousand Moons: \u201cA single chance is a galaxy of hope.\u201d',
 u'Storm Over Ryloth: \u201cIt is a rough road that leads to the heights of greatness.\u201d',
 u'Innocents of Ryloth: \u201cThe costs of war can never be truly accounted for.\u201d',
 u'Liberty on Ryloth: \u201cCompromise is a virtue to be cultivated, not a weakness to be despised.\u201d',
 u'Hostage Crisis: \u201cA secret shared is a trust formed.\u201d',
 u'Holocron Heist: \u201cA lesson learned is a lesson earned.\u201d',
 u'Cargo of Doom: \u201cOverconfidence is the most dangerous form of carelessness.\u201d',
 u'Children of the Force: \u201cThe first step to correcting a mistake is patience.\u201d',
 u'Senate Spy: \u201cA true heart should never be doubted.\u201d',
 u'Landing at Point Rain: \u201cBelieve in yourself or no one else will.\u201d',
 u'Weapons Factory: \u201cNo gift is more precious than trust.\u201d',
 u'Legacy of Terror: \u201cSometimes, accepting help is harder than offering it.\u201d',
 u'Brain Invaders: \u201cAttachment is not compassion\u201d',
 u'Grievous Intrigue: \u201cFor everything you gain, you lose something else.\u201d',
 u'The Deserter: \u201cIt is the quest for honor that makes one honorable.\u201d',
 u'Lightsaber Lost: \u201cEasy isn\u2019t always simple.\u201d',
 u'The Mandalore Plot: \u201cIf you ignore the past, you jeopardize your future.\u201d',
 u'Voyage of Temptation: \u201cFear not for the future, weep not for the past.\u201d',
 u'Duchess of Mandalore: \u201cIn war, truth is the first casualty.\u201d',
 u'Senate Murders: \u201cSearching for the truth is easy. Accepting the truth is hard.\u201d',
 u'Cat and Mouse: \u201cA wise leader knows when to follow.\u201d',
 u'Bounty Hunters: \u201cCourage makes heroes, but trust builds friendship.\u201d',
 u'The Zillo Beast: \u201cChoose what is right, not what is easy\u201d',
 u'The Zillo Beast Strikes Back: \u201cThe most dangerous beast is the beast within.\u201d',
 u'Death Trap: \u201cWho my father was matters less than my memory of him.\u201d',
 u'R2 Come Home: \u201cAdversity is friendship\u2019s truest test.\u201d',
 u'Lethal Trackdown: \u201cRevenge is a confession of pain.\u201d',
 u'Clone Cadets: \u201cBrothers in arms are brothers for life.\u201d',
 u'ARC Troopers: \u201cFighting a war tests a soldier\u2019s skills, defending his home tests a soldier\u2019s heart.\u201d',
 u'Supply Lines: \u201cWhere there\u2019s a will, there\u2019s a way.\u201d',
 u'Sphere of Influence: \u201cA child stolen is a lost hope.\u201d',
 u'Corruption: \u201cThe challenge of hope is to overcome corruption.\u201d',
 u'The Academy: \u201cThose who enforce the law must obey the law.\u201d',
 u'Assassin: \u201cThe future has many paths \u2014 choose wisely.\u201d',
 u'Evil Plans: \u201cA failure in planning is a plan for failure.\u201d',
 u'Hunt for Ziro: \u201cLove comes in all shapes and sizes.\u201d',
 u'Heroes on Both Sides: \u201cFear is a great motivator.\u201d',
 u'Pursuit of Peace: \u201cTruth can strike down the specter of fear\u201d',
 u'Nightsisters: \u201cThe swiftest path to destruction is through vengeance.\u201d',
 u'Monster: \u201cEvil is not born, it is taught.\u201d',
 u'Witches of the Mist: \u201cThe path to evil may bring great power, but not loyalty.\u201d',
 u'Overlords: \u201cBalance is found in the one who faces his guilt.\u201d',
 u'Altar of Mortis: \u201cHe who surrenders hope, surrenders life.\u201d',
 u'Ghosts of Mortis: \u201cHe who seeks to control fate shall never find peace.\u201d',
 u'The Citadel: \u201cAdaptation is the key to survival.\u201d',
 u'Counterattack: \u201cAnything that can go wrong will.\u201d',
 u'Citadel Rescue: \u201cWithout honor, victory is hollow.\u201d',
 u'Padawan Lost: \u201cWithout humility, courage is a dangerous game.\u201d',
 u'Wookiee Hunt: \u201cA great student is what the teacher hopes to be.\u201d',
 u'Water wars: \u201cWhen destiny calls, the chosen have no choice.\u201d',
 u'Gungan Attack: \u201cOnly through fire is a strong sword forged.\u201d',
 u'Prisoners: \u201cCrowns are inherited, kingdoms are earned.\u201d',
 u'Shadow Warrior: \u201cWho a person truly is cannot be seen with the eye.\u201d',
 u'Mercy Mission: \u201cUnderstanding is honoring the truth beneath the surface.\u201d',
 u'Nomad Droids: \u201cWho\u2019s the more foolish, the fool or the fool who follows him?\u201d',
 u'Darkness on Umbara: \u201cThe first step toward loyalty is trust.\u201d',
 u'The General: \u201cThe path of ignorance is guided by fear.\u201d',
 u'Plan of Dissent: \u201cThe wise man leads, the strong man follows.\u201d',
 u'Carnage of Krell: Our actions define our legacy.\u201d',
 u'Kidnapped: \u201cWhere we are going always reflects where we came from.\u201d',
 u'Slaves of the Republic: \u201cThose who enslave others inevitably become slaves themselves.\u201d',
 u'Escape from Kadavo: \u201cGreat hope can come from small sacrifices.\u201d',
 u'A Friend in Need: \u201cFriendship shows us who we really are.\u201d',
 u'Deception: \u201cAll warfare is based on deception.\u201d',
 u'Friends and Enemies: \u201cKeep your friends close, but keep your enemies closer.\u201d',
 u'The Box: \u201cThe strong survive, the noble overcome.\u201d',
 u'Crisis on Naboo: \u201cTrust is the greatest of gifts, but it must be earned.\u201d',
 u'Massacre: \u201cOne must let go of the past to hold onto the future.\u201d',
 u'Bounty: \u201cWho we are never changes, who we think we are does.\u201d',
 u'Brothers: \u201cA fallen enemy may rise again, but the reconciled one is truly vanquished.\u201d',
 u'Revenge: \u201cThe enemy of my enemy is my friend.\u201d',
 u'Revival: \u201cStrength in character can defeat strength in numbers.\u201d',
 u'A War on Two Fronts: \u201cFear is a malleable weapon.\u201d',
 u'Front Runners: \u201cTo seek something is to believe in its possibility.\u201d',
 u'The Soft War: \u201cStruggles often begin and end with the truth.\u201d',
 u'Tipping Points: \u201cDisobedience is a demand for change.\u201d',
 u'The Gathering: \u201cHe who faces himself, finds himself.\u201d',
 u'A Test of Strength: \u201cThe young are often underestimated.\u201d',
 u'Bound for Rescue: \u201cWhen we rescue others, we rescue ourselves.\u201d',
 u'A Necessary Bond: \u201cChoose your enemies wisely, as they may be your last hope.\u201d',
 u'Secret Weapons: \u201cHumility is the only defense against humiliation.\u201d',
 u'A Sunny Day in the Void: \u201cWhen all seems hopeless, a true hero gives hope.\u201d',
 u'Missing in Action: \u201cA soldier\u2019s most powerful weapon is courage.\u201d',
 u'Point of No Return: \u201cYou must trust in others or success is impossible.\u201d',
 u'Eminence: \u201cOne vision can have many interpretations.\u201d',
 u'Shades of Reason: \u201cAlliances can stall true intentions.\u201d',
 u'The Lawless: \u201cMorality separates heroes from villains.\u201d',
 u'Sabotage: \u201cSometimes even the smallest doubt can shake the greatest belief.\u201d',
 u'The Jedi who knew too much: \u201cCourage begins by trusting oneself.\u201d',
 u'To catch a Jedi: \u201cNever become desperate enough to trust the untrustworthy.\u201d',
 u'The Wrong Jedi: Never give up hope, no matter how dark things seem.\u201d']

Cleaning the quotes


In [3]:
starwar_quotes_selected_cleaned = []
for quote_number in range(len(starwar_quotes_selected)):
    starwar_quotes_selected_cleaned.append(starwar_quotes_selected[quote_number].encode("utf-8").split(":")[1].strip("\xe2\x80\x9d").strip(" \xe2\x80\x9c").replace("\xe2\x80\x99","'").replace("\xe2\x80\x94",","))
starwar_quotes_selected_cleaned


Out[3]:
['Great leaders inspire greatness in others.',
 'Belief is not a matter of choice, but conviction.',
 'Easy is the path to wisdom for those not blinded by ego.',
 'A plan is only as good as those who see it through.',
 'The best confidence builder is experience.',
 "Trust in your friends, and they'll have reason to trust in you.",
 'You hold onto your friends by keeping your heart a little softer than you head.',
 'Heroes are made by the times.',
 'Ignore your instincts at your peril.',
 'Most powerful is he who controls his own power.',
 'The winding path to peace is always a worthy one, regardless of how many turns it takes.',
 'Fail with honor rather than succeed with fraud.',
 'Greed and fear of loss are the roots that lead to the tree of evil.',
 'When surrounded by war, one must eventually choose a side.',
 'Arrogance diminishes wisdom.',
 "Truth enlightens the mind, but won't always bring happiness to your heart.",
 'Fear is a disease; hope is its only cure.',
 'A single chance is a galaxy of hope.',
 'It is a rough road that leads to the heights of greatness.',
 'The costs of war can never be truly accounted for.',
 'Compromise is a virtue to be cultivated, not a weakness to be despised.',
 'A secret shared is a trust formed.',
 'A lesson learned is a lesson earned.',
 'Overconfidence is the most dangerous form of carelessness.',
 'The first step to correcting a mistake is patience.',
 'A true heart should never be doubted.',
 'Believe in yourself or no one else will.',
 'No gift is more precious than trust.',
 'Sometimes, accepting help is harder than offering it.',
 'Attachment is not compassion',
 'For everything you gain, you lose something else.',
 'It is the quest for honor that makes one honorable.',
 "Easy isn't always simple.",
 'If you ignore the past, you jeopardize your future.',
 'Fear not for the future, weep not for the past.',
 'In war, truth is the first casualty.',
 'Searching for the truth is easy. Accepting the truth is hard.',
 'A wise leader knows when to follow.',
 'Courage makes heroes, but trust builds friendship.',
 'Choose what is right, not what is easy',
 'The most dangerous beast is the beast within.',
 'Who my father was matters less than my memory of him.',
 "Adversity is friendship's truest test.",
 'Revenge is a confession of pain.',
 'Brothers in arms are brothers for life.',
 "Fighting a war tests a soldier's skills, defending his home tests a soldier's heart.",
 "Where there's a will, there's a way.",
 'A child stolen is a lost hope.',
 'The challenge of hope is to overcome corruption.',
 'Those who enforce the law must obey the law.',
 'The future has many paths , choose wisely.',
 'A failure in planning is a plan for failure.',
 'Love comes in all shapes and sizes.',
 'Fear is a great motivator.',
 'Truth can strike down the specter of fear',
 'The swiftest path to destruction is through vengeance.',
 'Evil is not born, it is taught.',
 'The path to evil may bring great power, but not loyalty.',
 'Balance is found in the one who faces his guilt.',
 'He who surrenders hope, surrenders life.',
 'He who seeks to control fate shall never find peace.',
 'Adaptation is the key to survival.',
 'Anything that can go wrong will.',
 'Without honor, victory is hollow.',
 'Without humility, courage is a dangerous game.',
 'A great student is what the teacher hopes to be.',
 'When destiny calls, the chosen have no choice.',
 'Only through fire is a strong sword forged.',
 'Crowns are inherited, kingdoms are earned.',
 'Who a person truly is cannot be seen with the eye.',
 'Understanding is honoring the truth beneath the surface.',
 "Who's the more foolish, the fool or the fool who follows him?",
 'The first step toward loyalty is trust.',
 'The path of ignorance is guided by fear.',
 'The wise man leads, the strong man follows.',
 'Our actions define our legacy.',
 'Where we are going always reflects where we came from.',
 'Those who enslave others inevitably become slaves themselves.',
 'Great hope can come from small sacrifices.',
 'Friendship shows us who we really are.',
 'All warfare is based on deception.',
 'Keep your friends close, but keep your enemies closer.',
 'The strong survive, the noble overcome.',
 'Trust is the greatest of gifts, but it must be earned.',
 'One must let go of the past to hold onto the future.',
 'Who we are never changes, who we think we are does.',
 'A fallen enemy may rise again, but the reconciled one is truly vanquished.',
 'The enemy of my enemy is my friend.',
 'Strength in character can defeat strength in numbers.',
 'Fear is a malleable weapon.',
 'To seek something is to believe in its possibility.',
 'Struggles often begin and end with the truth.',
 'Disobedience is a demand for change.',
 'He who faces himself, finds himself.',
 'The young are often underestimated.',
 'When we rescue others, we rescue ourselves.',
 'Choose your enemies wisely, as they may be your last hope.',
 'Humility is the only defense against humiliation.',
 'When all seems hopeless, a true hero gives hope.',
 "A soldier's most powerful weapon is courage.",
 'You must trust in others or success is impossible.',
 'One vision can have many interpretations.',
 'Alliances can stall true intentions.',
 'Morality separates heroes from villains.',
 'Sometimes even the smallest doubt can shake the greatest belief.',
 'Courage begins by trusting oneself.',
 'Never become desperate enough to trust the untrustworthy.',
 'Never give up hope, no matter how dark things seem.']

Mailing the quotes

  1. Get the record of the last 15 quotes.
  2. We will randomize the quotes, those that are not in the last 15 sent quotes, so you don't get the same quotes in the same order over and over. # Hint: circular buffer for sent quotes.
  3. Mail the quote

In [31]:
path = "./"
with open(path+"starwar_quotes.txt", "wb") as f:
    for item in starwar_quotes_selected_cleaned:
      f.write("%s\n" % item)
#    writer = csv.writer(f)
#    writer.writerows([starwar_quotes_selected_cleaned])

In [33]:
pd.read_table(path+"starwar_quotes.txt",header=None)


Out[33]:
0
0 Great leaders inspire greatness in others.
1 Belief is not a matter of choice, but conviction.
2 Easy is the path to wisdom for those not blind...
3 A plan is only as good as those who see it thr...
4 The best confidence builder is experience.
5 Trust in your friends, and they'll have reason...
6 You hold onto your friends by keeping your hea...
7 Heroes are made by the times.
8 Ignore your instincts at your peril.
9 Most powerful is he who controls his own power.
10 The winding path to peace is always a worthy o...
11 Fail with honor rather than succeed with fraud.
12 Greed and fear of loss are the roots that lead...
13 When surrounded by war, one must eventually ch...
14 Arrogance diminishes wisdom.
15 Truth enlightens the mind, but won't always br...
16 Fear is a disease; hope is its only cure.
17 A single chance is a galaxy of hope.
18 It is a rough road that leads to the heights o...
19 The costs of war can never be truly accounted ...
20 Compromise is a virtue to be cultivated, not a...
21 A secret shared is a trust formed.
22 A lesson learned is a lesson earned.
23 Overconfidence is the most dangerous form of c...
24 The first step to correcting a mistake is pati...
25 A true heart should never be doubted.
26 Believe in yourself or no one else will.
27 No gift is more precious than trust.
28 Sometimes, accepting help is harder than offer...
29 Attachment is not compassion
... ...
78 Great hope can come from small sacrifices.
79 Friendship shows us who we really are.
80 All warfare is based on deception.
81 Keep your friends close, but keep your enemies...
82 The strong survive, the noble overcome.
83 Trust is the greatest of gifts, but it must be...
84 One must let go of the past to hold onto the f...
85 Who we are never changes, who we think we are ...
86 A fallen enemy may rise again, but the reconci...
87 The enemy of my enemy is my friend.
88 Strength in character can defeat strength in n...
89 Fear is a malleable weapon.
90 To seek something is to believe in its possibi...
91 Struggles often begin and end with the truth.
92 Disobedience is a demand for change.
93 He who faces himself, finds himself.
94 The young are often underestimated.
95 When we rescue others, we rescue ourselves.
96 Choose your enemies wisely, as they may be you...
97 Humility is the only defense against humiliation.
98 When all seems hopeless, a true hero gives hope.
99 A soldier's most powerful weapon is courage.
100 You must trust in others or success is impossi...
101 One vision can have many interpretations.
102 Alliances can stall true intentions.
103 Morality separates heroes from villains.
104 Sometimes even the smallest doubt can shake th...
105 Courage begins by trusting oneself.
106 Never become desperate enough to trust the unt...
107 Never give up hope, no matter how dark things ...

108 rows × 1 columns