Download presentation
Presentation is loading. Please wait.
Published byStewart George Modified over 9 years ago
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.) 2
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_id bigint, subject text, degree text, college text, year int ); 3
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’;”) 4
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) 5
6
Example Form 6 #!/usr/bin/python # Import modules for CGI handling import cgi, cgitb # Create instance of FieldStorage form =cgi.FieldStorage() # Put up a form First Name: Last Name: # 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 Maths Physics 7 Maths Physics
8
Applications in Time Domain 1.A Treasures Portal 2.Follow-up Marshals a.Extragalactic Transients b.Milky Way Variables c.Solar System d.Target-of-opportunity 8
9
iPTF Treasures Portal 9 Developers: MMK, Yi Cao
10
The iPTF Treasure Chest 10 A versatile portal with query derivatives: 1.ROBOTIC treasurer 2.SYSTEMATIC daily monitoring 3.YOUNG supernovae 4.GAP transients in the local universe 5.SLOWLY rising supernovae 6.LARGE amplitude stars 7.Fermi/Icecube target of opportunity fields triggers 8.M31/M33 transients and variables 9.FAST Transients 10.NUCLEAR Transients Developers: MMK, Yi Cao, Iair Arcavi
11
11 Developers: Robert Quimby, MMK, Iair Arcavi
12
12
13
13
14
Light Curves: Key to Variable Stars 14 Developers: David Levitan
15
Automatically match with SDSS, WISE, Simbad Links to NED, CRTS, LINEAR, etc. Periods 15
16
Period search 16
17
Movement: Key to Asteroids 17 Developer: Adam Waszczak
18
Target-of-Opportunity Marshal 18 Developer: Leo Singer
19
Questions? 19
Similar presentations
© 2024 SlidePlayer.com Inc.
All rights reserved.