dynamic web programming: python pg and cgi modules

Download Dynamic Web Programming: python  pg  and  cgi  modules

If you can't read please download the document

Post on 19-Jan-2016

22 views

Category:

Documents

2 download

Embed Size (px)

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

Dynamic Web Programming: pg & cgi modules

Dynamic Web Programming:python pg and cgi modulesMansi M. KasliwalCarnegie Institution for ScienceCalifornia Institute of TechnologyDatabaseLogical tables to organize large amounts of dataEasy-to-manage: add/subtract/modifyStructure facilitating super-fast complex queriesPython pg moduleconnectquery, insert, delete, update

(Note: psycopg2 module for cursor handling in large databases, copy command etc.)

2An 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 );

3Example 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;)4Dynamic Web ProgrammingGenerate nimble webpages on-the-fly that push and pull data to and fro a databasePython cgi module is easy-to-useURL: GET method e.g. tutorial.cgi?firstname=mansi&lastname=kasliwalFORM: POST methodRadio buttons or check boxesDrop down menuFile upload/downloadBlank Text Area Retrieving cookiese.g. os.environ['REMOTE_USER']

(Note: wsgi is more portable than cgi since it unifies the application programming interface; wsgi = Web Server Gateway Interface)

5Example Form6

#!/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 databasedb.insert(people, [firstname=%s, lastname=%s] %(first_name, last_name)) Check box / Dropdown Menu Maths Physics

7

Maths Physics

Applications in Time DomainA Treasures PortalFollow-up MarshalsExtragalactic TransientsMilky Way VariablesSolar SystemTarget-of-opportunity8iPTF Treasures Portal9

Developers: MMK, Yi CaoThe iPTF Treasure Chest10A versatile portal with query derivatives:ROBOTIC treasurerSYSTEMATIC daily monitoring YOUNG supernovaeGAP transients in the local universe SLOWLY rising supernovaeLARGE amplitude starsFermi/Icecube target of opportunity fields triggersM31/M33 transients and variablesFAST TransientsNUCLEAR Transients

Developers: MMK, Yi Cao, Iair Arcavi11Developers: Robert Quimby, MMK, Iair Arcavi

12

13Light Curves: Key to Variable Stars

14Developers: David Levitan

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

16Movement: Key to Asteroids

17Developer: Adam Waszczak

Target-of-Opportunity Marshal

18Developer: Leo Singer

Questions?19

Recommended

View more >