1 / 19

Dynamic Web Programming: python pg and cgi modules

Dynamic Web Programming: python pg and cgi modules. Mansi M. Kasliwal Carnegie Institution for Science California Institute of Technology. Database. L ogical t ables to organize large amounts of data Easy-to-manage: add/subtract/modify

otylia
Download Presentation

Dynamic Web Programming: python pg and cgi modules

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Dynamic Web Programming:python pg and cgi modules Mansi M. Kasliwal Carnegie Institution for Science California Institute of Technology

  2. Database • Logical tables to organize large amounts of data • Easy-to-manage: add/subtract/modify • Structure facilitating super-fast complex queries • Python “pg” module • connect • query, insert, delete, update (Note: psycopg2 module for cursor handling in large databases, copy command etc.)

  3. An Example Database Schema createdb tutorial psql –d tutorial CREATE SEQUENCE people_id_seq; CREATE TABLE people ( id bigint NOT NULL default nextval(‘people_id_seq’), firstname text, lastname text ); CREATE TABLE education ( people_idbigint, subject text, degree text, college text, year int);

  4. Example pg commands import pg #Connect to Database db = pg.connect(dbname=‘tutorial’, host=‘localhost’, user=‘mmk’) #Add Entries db.insert(people, [firstname=‘mansi’, lastname=‘kasliwal’]) delete(table, [d,] [key = val, ...]) update(table, [d,] [key = val, ...]) #Example Query Joining Two Tables result = db.query(“SELECT * from people, education WHERE people.id = education.people_id AND subject=‘astronomy’;”)

  5. Dynamic Web Programming • Generate nimble webpages on-the-fly that push and pull data to and fro a database • Python “cgi” module is easy-to-use • URL: GET method • e.g. tutorial.cgi?firstname=‘mansi’&lastname=‘kasliwal’ • FORM: POST method • Radio buttons or check boxes • Drop down menu • File upload/download • Blank Text Area • Retrieving cookies • e.g. os.environ['REMOTE_USER'] (Note: wsgi is more portable than cgi since it unifies the application programming interface; wsgi = Web Server Gateway Interface)

  6. Example Form #!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form =cgi.FieldStorage() # Put up a form <form action="/cgi-bin/tutorial.cgi" method="post"> First Name: <input type="text" name="firstname"> <br /> Last Name: <input type="text" name="lastname" /> <input type="submit" value="Submit" /> </form> # Get data from fields first_name = form.getvalue('firstname') last_name = form.getvalue('lastname') #Insert entry into database db.insert(people, [firstname=‘%s’, lastname=‘%s’] %(first_name, last_name))

  7. Check box / Dropdown Menu <form action="/cgi-bin/checkbox.cgi" method="POST" target="_blank"> <input type="checkbox" name="maths" value="on" /> Maths <input type="checkbox" name="physics" value="on" /> Physics <input type="submit" value="Select Subject" /> </form> <form action="/cgi-bin/dropdown.cgi" method="post" target="_blank"> <select name="dropdown"> <option value="Maths" selected>Maths</option> <option value="Physics">Physics</option> </select> <input type="submit" value="Submit"/> </form>

  8. Applications in Time Domain • A Treasures Portal • Follow-up Marshals • Extragalactic Transients • Milky Way Variables • Solar System • Target-of-opportunity

  9. iPTF Treasures Portal Developers: MMK, Yi Cao

  10. The iPTF Treasure Chest A versatile portal with query derivatives: ROBOTIC treasurer SYSTEMATIC daily monitoring YOUNG supernovae GAP transients in the local universe SLOWLY rising supernovae LARGE amplitude stars Fermi/Icecube target of opportunity fields triggers M31/M33 transients and variables FAST Transients NUCLEAR Transients Developers: MMK, Yi Cao, IairArcavi

  11. Developers: Robert Quimby, MMK, IairArcavi

  12. Light Curves: Key to Variable Stars Developers: David Levitan

  13. Automatically match with SDSS, WISE, SimbadLinks to NED, CRTS, LINEAR, etc. Periods

  14. Period search

  15. Movement: Key to Asteroids Developer: Adam Waszczak

  16. Target-of-Opportunity Marshal Developer: Leo Singer

  17. Questions?

More Related