Skip to content

Commit

Permalink
Not sure what's going on here...
Browse files Browse the repository at this point in the history
Merge branch 'master' of github.com:kialio/python-bootcamp
  • Loading branch information
kialio committed Jan 7, 2014
2 parents 2b88415 + 62da2c3 commit ebc044c
Show file tree
Hide file tree
Showing 11 changed files with 205 additions and 10 deletions.
Binary file added Lectures/12_Testing/12_Testing.pdf
Binary file not shown.
Binary file added Lectures/12_Testing/12_Testing.pptx
Binary file not shown.
Binary file added Lectures/12_Testing/testing.tgz
Binary file not shown.
Binary file not shown.
170 changes: 170 additions & 0 deletions Lectures/15_Appetite/updatedslides_pyfile/appetite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
#! /usr/bin/env python

import sqlite3, os, urllib2, smtplib
from lxml import etree
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
import NothingToSeeHere # Email password stored in this (private) file

# Global variables
MYSNURL = "http://astro.berkeley.edu/~cenko/public/BootCamp/SNeInfo.html"
ASTROPEEPSDB = "/Users/cenko/BootCamp/2012B/appetite/astropeeps.sql"
# Need to change this to a path you can write to

###########################################################################

def create_astro_table(filename=ASTROPEEPSDB):

"""Creates sqlite database to store basic information on astronomy department"""

conn = sqlite3.connect(filename)
c = conn.cursor()

c.execute('''CREATE TABLE ASTROPEEPS (f_name text, l_name text,
email text, status text)''')
c.execute('''INSERT INTO ASTROPEEPS VALUES ("Josh", "Bloom",
"[email protected]", "Faculty")''')
c.execute('''INSERT INTO ASTROPEEPS VALUES ("Berian", "James",
"[email protected]", "Postdoc")''')
c.execute('''INSERT INTO ASTROPEEPS VALUES ("Joey", "Richards",
"[email protected]", "Postdoc")''')
c.execute('''INSERT INTO ASTROPEEPS VALUES ("Adam", "Morgan",
"[email protected]", "Student")''')
c.execute('''INSERT INTO ASTROPEEPS VALUES ("Chris", "Klein",
"[email protected]", "Student")''')
c.execute('''INSERT INTO ASTROPEEPS VALUES ("Isaac", "Shivvers",
"[email protected]", "Student")''')
c.execute('''INSERT INTO ASTROPEEPS VALUES ("Dan", "Starr",
"[email protected]", "Staff")''')
c.execute('''INSERT INTO ASTROPEEPS VALUES ("Henrik", "Brink",
"[email protected]", "Student")''')

conn.commit()
c.close()

return

############################################################################

def retrieve_random_gradstudent(filename=ASTROPEEPSDB, student="Student"):

"""Returns the name and email address of a random graduate student"""

conn = sqlite3.connect(filename)
c = conn.cursor()

c.execute("SELECT f_name, l_name, email FROM ASTROPEEPS WHERE status" + \
" = '%s' ORDER BY RANDOM() LIMIT 1" % student)
row = c.fetchall()

conn.commit()
c.close()

return [row[0][0], row[0][1], row[0][2]]

###########################################################################

def retrieve_sn_info(sn_name, url=MYSNURL):

"""Given the name of a supernova, retrieves the object's coordinates,
host galaxy, and type (if they exists) by reading through the provided
URL. Otherwise returns a list of None."""

# Download the HTML from the SNe URL
flob = urllib2.urlopen(url)
s = flob.read()
flob.close()
html = etree.HTML(s)

# Find all lines following the <table> tag
rows = html.find('.//table')

# Loop over the table rows
for row in rows:

# Check if matches name given SN
if (sn_name == row[0].text):

# Get important info
coords = [row[1].text.replace(" ", ":"),
row[2].text.replace(" ", ":")]
host = row[3].text
sntype = row[4].text
return [host, coords, sntype]

# If no match found, return a whole lot of nothing
return [None, None, None]

###############################################################################

def email_student(address, f_name, l_name, sn_name, host, coords, sntype,
myemail="[email protected]"):

"""Generate and send an email to address with a request to observe
the given supernova."""

# Create the message
msg = MIMEMultipart()
msg["From"] = myemail
msg["To"] = address

# Write the body, making sure all variables are defined.
msgstr = "Hi %s %s,\n\n" % (f_name, l_name)
msgstr += "I just found out about %s, and it seems neat. " % sn_name
if (host == None):
msgstr += "The host galaxy is unknown. "
else:
msgstr += "The host galaxy is %s. " % host
if (coords == None):
msgstr += "I do not know the coordinates. "
else:
msgstr += "The location is: RA=%s; Dec=%s. " % (coords[0], coords[1])
if (sntype == None):
msgstr += "I do not know the type.\n\n"
else:
msgstr += "The type is %s.\n\n" % sntype
msgstr += "Could you please arrange some new observations? "
msgstr += "I am really busy drinking right now.\n\n"
msgstr += "Thanks,\nBrad"
msg.attach(MIMEText(msgstr))

# Configure the outgoing mail server
mailServer = smtplib.SMTP("smtp.gmail.com", 587)
mailServer.starttls()
mailServer.login(myemail, NothingToSeeHere.passwd)

# Send the message
mailServer.sendmail(myemail, address, msg.as_string())
mailServer.close()

return

###############################################################################

def do_science(sn_name, filename=ASTROPEEPSDB, url=MYSNURL,
myemail="[email protected]"):

"""Script to do cutting edge science. Takes a supernova name, finds
some information about it on a webpage, picks a random graduate student,
and emails that student to request follow-up observations."""

# See if the department database exists. If not, create it.
if not os.path.exists(filename):
create_astro_table(filename=filename)

# Select a random graduate student to do our bidding
[f_name, l_name, address] = retrieve_random_gradstudent(filename=filename)

# Find out some information about the supernova
[host, coords, sntype] = retrieve_sn_info(sn_name, url=url)

# Email the student
email_student(address, f_name, l_name, sn_name, host, coords, sntype,
myemail=myemail)

print "I emailed %s %s at %s about %s." % (f_name, l_name, address, sn_name)

# Stockholm here I come!
return

###############################################################################
Binary file added Lectures/SciPy.pdf
Binary file not shown.
Binary file added Lectures/astropy-bootcamp-june2013.pdf
Binary file not shown.
Binary file added Lectures/astropy-bootcamp-june2013.pptx
Binary file not shown.
Binary file added Lectures/python-bootcamp-postmortem.pdf
Binary file not shown.
Binary file added Lectures/python-bootcamp-postmortem.pptx
Binary file not shown.
45 changes: 35 additions & 10 deletions Webpages/agenda.html
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,17 @@ <h2>Day 2 - Wed, June 12</h2>
</tr>
<tr>
<td width="100">11:10 AM</td>
<td colspan="2"><b>Breakout 7</b></td>
<td colspan="2"><b>Breakout 7</b></td>
<!-- <td><a href="https://raw.github.com/kialio/python-bootcamp/master/Breakouts/Solutions/07_AdvancedStuff/Breakout7Solution.py">Breakout7Solution.py</a><br/>
<a href="https://raw.github.com/kialio/python-bootcamp/master/Breakouts/Solutions/07_AdvancedStuff/Breakout7Solution.ipynb">Solution (raw notebook)</a><br/>
<a href="http://nbviewer.ipython.org/urls/raw.github.com/kialio/python-bootcamp/master/Breakouts/Solutions/07_AdvancedStuff/Breakout7Solution.ipynb">Solution (view notebook)</a></td> -->
</tr>
<tr>
<td width="100">11:30 AM</td>
<td>Breakout 7 Post-mortem</td>
<td width="200">Terri Brandt</td>
<td><a href="https://raw.github.com/kialio/python-bootcamp/master/Breakouts/Solutions/07_AdvancedStuff/Breakout7Solution.ipynb">Solution (raw notebook)</a><br/>
<td><a href="https://raw.github.com/kialio/python-bootcamp/master/Breakouts/Solutions/07_AdvancedStuff/Breakout7Solution.py">Breakout7Solution.py</a>
<a href="https://raw.github.com/kialio/python-bootcamp/master/Breakouts/Solutions/07_AdvancedStuff/Breakout7Solution.ipynb">Solution (raw notebook)</a><br/>
<a href="http://nbviewer.ipython.org/urls/raw.github.com/kialio/python-bootcamp/master/Breakouts/Solutions/07_AdvancedStuff/Breakout7Solution.ipynb">Solution (view notebook)</a></td>
</tr>
<tr>
Expand Down Expand Up @@ -263,13 +267,14 @@ <h2>Day 3 - Fri, June 14</h2>
<tr>
<td width="100">8:30 AM</td>
<td>Homework Post-mortem/General Help</a></td>
<td></td>
<td>Brad Cenko</td>
<td><a href="https://raw.github.com/kialio/python-bootcamp/master/Homeworks/Homework_02/hw_2_solutions.py">hw_2_solutions.py</a></td>
</tr>
<tr>
<td width="100">9:00 AM</td>
<td>Scientific Programming</td>
<td width="200">Dan Kocevski</td>
<td><a href="https://github.com/kialio/python-bootcamp/raw/master/Lectures/SciPy.pdf">PDF</td>
</tr>
<tr>
<td width="100">10:00 AM</td>
Expand All @@ -284,6 +289,8 @@ <h2>Day 3 - Fri, June 14</h2>
<td width="100">10:40 AM</td>
<td>Development II</td>
<td width="200">Terri Brandt</td>
<td><a href="https://github.com/kialio/python-bootcamp/raw/master/Lectures/12_Testing/12_Testing.pdf">PDF</td>
<td>Scripts: <a href="https://github.com/kialio/python-bootcamp/raw/master/Lectures/12_Testing/testing.tgz">testing.tgz</a></td>
</tr>
<tr>
<td width="100">11:40 AM</td>
Expand All @@ -301,31 +308,49 @@ <h2>Day 3 - Fri, June 14</h2>
<tr>
<td width="100">1:00 PM</td>
<td>Advanced iPython</td>
<td width="200">Jeremy Perkins</td>
<td width="200">Jamie Cohen</td>
<td><a href="https://raw.github.com/kialio/python-bootcamp/master/Lectures/13_AdvancedIPython/Advanced%20IPython%20Notebook.v2.ipynb">Notebook (raw)<br/>
<a href="http://nbviewer.ipython.org/urls/raw.github.com/kialio/python-bootcamp/master/Lectures/13_AdvancedIPython/Advanced%2520IPython%2520Notebook.v2.ipynb">Notebook (view)</td>
</tr>
<tr>
<td width="100">2:00 PM</td>
<td colspan="2"><b>Breakout 13</b></td>
<td><a href="https://raw.github.com/kialio/python-bootcamp/master/Breakouts/13_AdvancedIPython/Advanced%20IPython%20Breakout.ipynb">Notebook (raw)<br/>
<a href="http://nbviewer.ipython.org/urls/raw.github.com/kialio/python-bootcamp/master/Breakouts/13_AdvancedIPython/Advanced%2520IPython%2520Breakout.ipynb">Notebook (view)</td>
</tr>
<tr>
<td width="100">2:30 PM</td>
<td>Breakout 13 Post-mortem</td>
<td width="200">Jeremy Perkins</td>
<td width="200">Jamie Cohen</td>
</tr>
<tr>
<td width="100">2:40 PM</td>
<td>Scientific Programming II</td>
<td width="200">Dan Kocevski</td>
<td>AstroPy</td>
<td width="200">Andy Ptak</td>
<td><a href="https://github.com/kialio/python-bootcamp/raw/master/Lectures/astropy-bootcamp-june2013.pdf">PDF</td>
</tr>
<tr>
<td width="100">3:00 PM</td>
<td>AstroPy</td>
<td width="200">Andy Ptak</td>
<td>Whetting your Appetite</td>
<td width="200">Brad Cenko</td>
<td><a href="https://github.com/kialio/python-bootcamp/raw/master/Lectures/15_Appetite/updatedslides_pyfile/Appetite.pdf">PDF</td>
<td><a href="https://github.com/kialio/python-bootcamp/raw/master/Lectures/15_Appetite/updatedslides_pyfile/appetite.py">appetite.py</td>
</tr>
<tr>
<td width="100">4:00 PM</td>
<td>Wrap Up</td>
<td width="200">TBD</td>
<td width="200">Andy Ptak</td>
<td><a href="https://github.com/kialio/python-bootcamp/raw/master/Lectures/python-bootcamp-postmortem.pdf">PDF</a></td>
<td>Give us <a href="http://www.surveymonkey.com/s/65XDGF9">feedback</a>!</td>
</tr>
<tr>
<td width="100">Extra!</td>
<td>Scientific Programming II</td>
<td width="200">from Berkley Bootcamp 2012, James Gao</td>
<td><a href="https://sites.google.com/site/pythonbootcamp2012b/agenda/scicomp2.pdf?attredirects=0">PDF</a><br/>
<a href="http://youtu.be/7chDT2b_sco">Video</a></td>
<td><a href="https://sites.google.com/site/pythonbootcamp2012b/agenda/scicomp2.ipynb?attredirects=0">ipy Notebook (Raw)</a><br/>
<a href="https://sites.google.com/site/pythonbootcamp2012b/agenda/neurons.hf5?attredirects=0">Data file</a></td>
</tr>
</table>

Expand Down

0 comments on commit ebc044c

Please sign in to comment.