dynamic web programming: python pg and cgi modules

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

Upload: otylia

Post on 19-Jan-2016

49 views

Category:

Documents


2 download

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Dynamic Web Programming: python  pg  and  cgi  modules

Dynamic Web Programming:python pg and cgi modulesMansi M. KasliwalCarnegie Institution for ScienceCalifornia Institute of Technology

Page 2: Dynamic Web Programming: python  pg  and  cgi  modules

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

Page 3: Dynamic Web Programming: python  pg  and  cgi  modules

An Example Database Schemacreatedb 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

Page 4: Dynamic Web Programming: python  pg  and  cgi  modules

Example pg commandsimport pg

#Connect to Databasedb = pg.connect(dbname=‘tutorial’, host=‘localhost’, user=‘mmk’)

#Add Entriesdb.insert(people, [firstname=‘mansi’, lastname=‘kasliwal’])delete(table, [d,] [key = val, ...])update(table, [d,] [key = val, ...])

#Example Query Joining Two Tablesresult = db.query(“SELECT * from people, education WHERE people.id = education.people_id AND subject=‘astronomy’;”)

4

Page 5: Dynamic Web Programming: python  pg  and  cgi  modules

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

Page 6: Dynamic Web Programming: python  pg  and  cgi  modules

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<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 databasedb.insert(people, [firstname=‘%s’, lastname=‘%s’] %(first_name, last_name))

Page 7: Dynamic Web Programming: python  pg  and  cgi  modules

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>

7

<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>

Page 8: Dynamic Web Programming: python  pg  and  cgi  modules

Applications in Time Domain

1. A Treasures Portal2. Follow-up Marshals

a. Extragalactic Transientsb. Milky Way Variablesc. Solar Systemd. Target-of-opportunity

8

Page 9: Dynamic Web Programming: python  pg  and  cgi  modules

iPTF Treasures Portal

9

Developers: MMK, Yi Cao

Page 10: Dynamic Web Programming: python  pg  and  cgi  modules

The iPTF Treasure Chest

10

A versatile portal with query derivatives:1. ROBOTIC treasurer2. SYSTEMATIC daily monitoring 3. YOUNG supernovae4. GAP transients in the local universe 5. SLOWLY rising supernovae6. LARGE amplitude stars7. Fermi/Icecube target of opportunity fields triggers8. M31/M33 transients and variables9. FAST Transients10. NUCLEAR Transients

Developers: MMK, Yi Cao, Iair Arcavi

Page 11: Dynamic Web Programming: python  pg  and  cgi  modules

11

Developers: Robert Quimby, MMK, Iair Arcavi

Page 12: Dynamic Web Programming: python  pg  and  cgi  modules

12

Page 13: Dynamic Web Programming: python  pg  and  cgi  modules

13

Page 14: Dynamic Web Programming: python  pg  and  cgi  modules

Light Curves: Key to Variable Stars

14

Developers: David Levitan

Page 15: Dynamic Web Programming: python  pg  and  cgi  modules

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

15

Page 16: Dynamic Web Programming: python  pg  and  cgi  modules

Period search

16

Page 17: Dynamic Web Programming: python  pg  and  cgi  modules

Movement: Key to Asteroids

17

Developer: Adam Waszczak

Page 18: Dynamic Web Programming: python  pg  and  cgi  modules

Targ

et-o

f-O

ppor

tuni

ty M

arsh

al

18Developer: Leo Singer

Page 19: Dynamic Web Programming: python  pg  and  cgi  modules

Questions?

19