SlideShare ist ein Scribd-Unternehmen logo
1 von 52
Build a
Better
Python Web
APP
MongoDB
• Much fasterthan SQL databases
• No needto learnquery languages*and setups
• Easier toscale whendesignedproperly
Install pymongo
pip install pymongo
easy_install pymongo
Hello World
from pymongo import MongoClient
client = MongoClient("localhost", 27017)
db = client.databasename
Step
from pymongo import MongoClient
Import MongoClient from pymongo
client = MongoClient("localhost", 27017)
Connect to the mongodb server at the IP address and port defined
db = client.databasename
Access a specific database in the mongodb server
collection = db.collectionname
Access a specific collection (table in SQL) in the selected db
Basic DB Operations
•Create
•Read
•Update
•Delete
Create
@route("/register", method="POST")
def newuser():
username = request.forms.get("username")
password = request.forms.get("password")
email = request.forms.get("email")
userdata = {"name":username, "password":password, "email":email}
try:
db.users.save(userdata)
except:
return {"status":"ERROR"}
return {"status":"OK"}
Step
username = request.forms.get("username")
Get the username, password, email to data from the forms
userdata = {"name":username, "password":password,
"email":email}
Create a dictionary with the data obtained above
try:
Setup anexception handler
Step
db.users.save(userdata)
Save the dictionary to the users collection in the db we connected before
except:
Start of the exception block. Thiswill execute when the db save fails
Read
@route("/user/list")
def listuser():
usercursor = db.users.find({},{"_id":False})
users = list(usercursor)
return {"users":users}
Step
usercursor = db.users.find({},{"_id":False})
Find allentries in the collection named users and do not show the _id field
users = list(usercursor)
Convert the cursor object into a list,which we can be converted to a jsonobject
return {"users":users}
Return the list of users to the browser
The Query Format
db.collectionname.find(filter,projection)
Filter is the expression that needs to be true an element to be included
Examples:
• {} = will return all
• {“name”:”paolo”} = will only return entries with name exactly to“paolo”
• {“name”:”paolo”, “age”:{“$lte”:30}} = will only return entries with names exactly “paolo” and age
is less thanor equal to 30
See more filter operators here: https://docs.mongodb.com/manual/reference/operator/query/
The Query Format
db.collectionname.find(filter,projection)
Projection controls what fields will be shown, done by setting field names True or False
Examples:
{“name”:True}
{“_id”:False}
Inputs in Bottle
Via POST body
@route('/login', method="POST")
def login():
username = request.forms.get("username")
password = request.forms.get("password")
acceptedpasswords = ["gloopgroup", "devconph" ,
"adventuretime"]
if password in acceptedpasswords:
return "Welcome "+ username
else:
return "Unauthorized"
Visit: localhost:8001/login using login page
Activity 1
Create a calculatorapi:
http://localhost:8001/operation/operand1/operand2
will return the value of
operand1 <operation> operand2
Example:
/subtraction/10/2 will output 8
Common Return TYPES
PlainText
Similar to whatwe were doing earlier
Common Return TYPES
Binary
Whenreturning fileslike images, video, audio, pdfs…
Common Return TYPES
JSON
The common return type for APIs
Example:FB API
/{userid}/friends
{
"data": [
{
"name": "Terence Pua",
"id": "608407"
},
{
"name": "Gene Paul Quevedo",
"id": "10153785024974240"
},
{
"name": "Jc Velasquez",
"id": "722462218"
},
{
"name": "Jomel C. Imperio",
"id": "779287017"
}
],
"summary": {
"total_count": 770
}
}
Common Return TYPES
HTML
Returnweb pages with dynamic/static content
<!DOCTYPE html>
<html itemscope itemtype="http://schema.org/QAPage">
<head>
<title>regex - Validate email address in JavaScript? - Stack Overflow</title>
<link rel="shortcut icon" href="//cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d">
<link rel="apple-touch-icon image_src" href="//cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a">
<link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml">
<meta name="twitter:card" content="summary">
<meta name="twitter:domain" content="stackoverflow.com"/>
<meta property="og:type" content="website" />
<meta property="og:image" itemprop="image primaryImageOfPage" content="http://cdn.sstatic.net/Sites/stackoverflow/img/apple-
touch-icon@2.png?v=73d79a89bded&a" />
<meta name="twitter:title" property="og:title" itemprop="title name" content="Validate email address in JavaScript?" />
<meta name="twitter:description" property="og:description" itemprop="description" content="How can an email address be validated
in JavaScript?" />
<meta property="og:url" content="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript"/>
<link rel="canonical" href="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript" />
Returning JSON Object
JSON
Simplyreturn a dictionary or list
@route("/json")
def jason():
return {"lastname":"bourne", "alias":"David Webb"}
Returning Static HTML
HTML
Use static_file from bottle
@route("/loginpage")
def loginpage():
return static_file("login.html", root=".")
Testing the POST Handler
Visit localhost:8081/loginpage
Type your nameand use any of theseas passwordg
gloopgroup, devconph, adventuretime
Click submit
The POST Request Cycle
<form action="/login" method="POST">
Method dictates what kind of request happens when submitted
Action tells the browser where to submit the request
<input type="text" name="username">
Adds a text input that will be associated to the username field
<input type="password" name="password">
Adds a password inputthat willbe associatedto the password field
<input type="submit">
Adds a button that submits the form whenclicked
Returning Dynamic HTML
HTML
Use a templatingengine:
• Library thatcan substitutevariables intoa templatequickly and cleanly
• Isolates thedesigner’s job of designing and thecoder’s job of coding
Install Tenjin
pip install tenjin
easy_install tenjin
Using Tenjin
from gevent import monkey;
monkey.patch_all()
from bottle import run, route, request
import tenjin
from tenjin.helpers import *
@route("/introduction/<name>/<age>/<work>")
def template1(name, age, work):
context = {"name":name, "age":age, "work":work}
return engine.render("introduction.html", context);
engine = tenjin.Engine(path=['.'])
run(server='gevent', host="localhost", port=8001, debug=True)
The template
<!doctype html>
<html lang="en">
<head>
<title>Login</title>
</head>
<body>
<h1>${name}</h1>
<h2>Age:${age}<h2>
<h2>Work:${work}<h2>
</body>
</html>
Step
from gevent import monkey;
monkey.patch_all()
from bottle import run, route, request
import tenjin
from tenjin.helpers import *
Import alllibraries, including tenjin and all helper methods
@route("/introduction/<name>/<age>/<work>")
Define a route for the url, and define variables in it
def template1(name, age, work):
Declare a request handler and receive the variables from the url
Step
context = {"name":name, "age":age, "work":work}
Define a context variable, which is a dictionary of values that will be substituted into the template
return engine.render("introduction.html", context);
Render the template called introduction.html using the context variable named context, and return it to
the browser
engine = tenjin.Engine(path=['.'])
Instructs the templating engine to look for the templates in the directories listed in path
Step (Inside the template)
<!doctype html>
<html lang="en">
<head>
<title>Login</title>
</head>
<body>
<h1>${name}</h1>
<h2>Age:${age}<h2>
<h2>Work:${work}<h2>
</body>
</html>
{
"name":"Paolo",
"age":"30",
"work":"Synergist"
}
+
Displaying Lists
@route("/spell/<word>")
def template1(word):
letters = list(word)
context = {"letters":letters, "word":word}
return engine.render("speller.html", context);
Step
@route("/spell/<word>")
Define a route that accepts a variable assigned to word
def speller(word):
Define a handler that accepts avariable named word
letters = list(word)
Convert the text string into a listobject. From a string “word”, it becomes a list [“w”, “o”, “r”, “d”]
Step
context = {"letters":letters}
Define a context variable, which contains the listof letters we just created
return engine.render("speller.html", context);
Render the template called speller.html using the context variable named context, and return it to the
browser
Step (Inside the template)
<?py for letter in letters: ?>
Loop on the elements of the list named letters
<h3>${letter}</h3><br>
Display the element letter along with the html
<?py #endfor ?>
Denote where the loop ends inthe template
<a href="/greet/${word}">greet ${word}</a>
Create a link that willcall the greet API we created earlier
{"letters":["s", "u", "s", "h", "i"]}
Highlighting Names
@route("/profiles/<name>")
def profile(name):
users = [
{"name":"Em", "image":"http://goo.gl/aDxeu1", "age":30,
"work":"Futurist"},
{"name":"Paolo", "image":"http://goo.gl/5k2oZr", "age":30,
"work":"Synergist"}
]
context = {"users":users, "name":name}
return engine.render("profiles.html", context)
Step
users = [
{"name":"Em", "image":"http://goo.gl/aDxeu1", "age":30, "work":"Futurist"},
{"name":"Paolo", "image":"http://goo.gl/5k2oZr", "age":30, "work":"Synergist"}
]
Define a list of dictionaries, with each dictionary objectcontaining information about a user. It contains information
name,url of the image, age, and work
context = {"users":users, "name":name}
Define a conext containing the name to behighlighted, and the list of users
return engine.render("profiles.html", context)
Render the template named profiles.html with the context
Step (Inside the template)
<?py for user in users: ?>
Loop on the elements of the list named users, each element in the listcan be referred to using the user
variable
<div style="height:100px;">
Create a div element in the html to contain one user element
<img src="${user['image']}" style="float:left;
height:100%;"/>
Place an image in the html coming from the url defined in user[‘image’]
Step (Inside the template)
<?py if name==user["name"]: ?>
Compare the current user’s name to the name entered in the url
<strong>Name: ${user['name']}</strong>
Thishappens when the above condition istrue, display the name asbold characters
<?py else: ?>
Add an else handler that executes if condition is not met
Step (Inside the template)
Name: ${user['name']}
This happens when primary condition is not met, display the user’s name without any decorations
<?py #endif ?>
Denote where the if statement ends
Make a Sushi Menu
Create a menu using allthe sushiitems in the sushilistvariable
Display the image and name of the sushi
When the menu item is clicked, it should display another page containingthe name, image, price, and
rating of the sushi(defined in the sushilistvariable)
The most creative presentation of the menu wins aprize
Activity 1
pip install gevent
pip install bottle
Cost per Mille =
• Cost per 1000 impressions
• Abuse of statistics
• i.e. Magic
• i.e. It sucks
• Not based on empirical measured data
ADVERTISING!
Eyeballs
cost
How many are watching
me right now?
How many are paying attention?
How many are interested?
How many are still reading this part?
How about now?
Now?
ROUTER ON
PROMISCUOUS MODE
DEVICEs SENDING
PROBE REQUESTS
PYTHON
+TCPDUMP
We get this
Pilot Installation
23000
Passers-by
39%
viewed
10%
Finished
Meh…
Map movement
Geofencing alternative
Detection
perimeter
snoop
turn off your phones
when going to the lagoon

Weitere ähnliche Inhalte

Was ist angesagt?

Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexyananelson
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/ServletSunil OS
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KThomas Fuchs
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDMichele Capra
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginningAnis Ahmad
 
Working with AFNetworking
Working with AFNetworkingWorking with AFNetworking
Working with AFNetworkingwaynehartman
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSencha
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networkingVitali Pekelis
 
Let ColdFusion ORM do the work for you!
Let ColdFusion ORM do the work for you!Let ColdFusion ORM do the work for you!
Let ColdFusion ORM do the work for you!Masha Edelen
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreRyan Weaver
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...Codemotion
 
Javascript call ObjC
Javascript call ObjCJavascript call ObjC
Javascript call ObjCLin Luxiang
 
Building High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsBuilding High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsMichele Capra
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Eric Palakovich Carr
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012Nicholas Zakas
 

Was ist angesagt? (20)

Graphql, REST and Apollo
Graphql, REST and ApolloGraphql, REST and Apollo
Graphql, REST and Apollo
 
Refresh Austin - Intro to Dexy
Refresh Austin - Intro to DexyRefresh Austin - Intro to Dexy
Refresh Austin - Intro to Dexy
 
Jsp/Servlet
Jsp/ServletJsp/Servlet
Jsp/Servlet
 
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2KZepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
 
Developing application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDDDeveloping application for Windows Phone 7 in TDD
Developing application for Windows Phone 7 in TDD
 
Url programming
Url programmingUrl programming
Url programming
 
jQuery from the very beginning
jQuery from the very beginningjQuery from the very beginning
jQuery from the very beginning
 
Working with AFNetworking
Working with AFNetworkingWorking with AFNetworking
Working with AFNetworking
 
jQuery in 15 minutes
jQuery in 15 minutesjQuery in 15 minutes
jQuery in 15 minutes
 
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark BrocatoSenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
SenchaCon 2016: Keynote Presentation - Art Landro, Gautam Agrawal, Mark Brocato
 
Advanced #2 networking
Advanced #2   networkingAdvanced #2   networking
Advanced #2 networking
 
Let ColdFusion ORM do the work for you!
Let ColdFusion ORM do the work for you!Let ColdFusion ORM do the work for you!
Let ColdFusion ORM do the work for you!
 
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and moreSymfony Guard Authentication: Fun with API Token, Social Login, JWT and more
Symfony Guard Authentication: Fun with API Token, Social Login, JWT and more
 
And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...And now you have two problems. Ruby regular expressions for fun and profit by...
And now you have two problems. Ruby regular expressions for fun and profit by...
 
Django Heresies
Django HeresiesDjango Heresies
Django Heresies
 
Javascript call ObjC
Javascript call ObjCJavascript call ObjC
Javascript call ObjC
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 
Building High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 AppsBuilding High Performance and Reliable Windows Phone 8 Apps
Building High Performance and Reliable Windows Phone 8 Apps
 
Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!Django Rest Framework and React and Redux, Oh My!
Django Rest Framework and React and Redux, Oh My!
 
Maintainable JavaScript 2012
Maintainable JavaScript 2012Maintainable JavaScript 2012
Maintainable JavaScript 2012
 

Ähnlich wie Python Code Camp for Professionals 4/4

Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4DEVCON
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBMongoDB
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Knoldus Inc.
 
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Neelkanth Sachdeva
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.jsAdrien Guéret
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flaskJeetendra singh
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”apostlion
 
Web весна 2013 лекция 6
Web весна 2013 лекция 6Web весна 2013 лекция 6
Web весна 2013 лекция 6Technopark
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIEyal Vardi
 
Web осень 2012 лекция 6
Web осень 2012 лекция 6Web осень 2012 лекция 6
Web осень 2012 лекция 6Technopark
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2Adam Klein
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web developmentJohannes Brodwall
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access RunbookTaha Shakeel
 

Ähnlich wie Python Code Camp for Professionals 4/4 (20)

Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4Python Code Camp for Professionals 3/4
Python Code Camp for Professionals 3/4
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDBDev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
 
Q
QQ
Q
 
Java Script
Java ScriptJava Script
Java Script
 
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala traits event , New Delh...
 
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
Play framework training by Neelkanth Sachdeva @ Scala Traits Event , New Delh...
 
Introduction to node.js
Introduction to node.jsIntroduction to node.js
Introduction to node.js
 
Build restful ap is with python and flask
Build restful ap is with python and flaskBuild restful ap is with python and flask
Build restful ap is with python and flask
 
Play 2.0
Play 2.0Play 2.0
Play 2.0
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”
 
Tutorial asp.net
Tutorial  asp.netTutorial  asp.net
Tutorial asp.net
 
Wt unit 5
Wt unit 5Wt unit 5
Wt unit 5
 
Web весна 2013 лекция 6
Web весна 2013 лекция 6Web весна 2013 лекция 6
Web весна 2013 лекция 6
 
The Full Power of ASP.NET Web API
The Full Power of ASP.NET Web APIThe Full Power of ASP.NET Web API
The Full Power of ASP.NET Web API
 
Web осень 2012 лекция 6
Web осень 2012 лекция 6Web осень 2012 лекция 6
Web осень 2012 лекция 6
 
Data models in Angular 1 & 2
Data models in Angular 1 & 2Data models in Angular 1 & 2
Data models in Angular 1 & 2
 
Php summary
Php summaryPhp summary
Php summary
 
Bare-knuckle web development
Bare-knuckle web developmentBare-knuckle web development
Bare-knuckle web development
 
Azure F#unctions
Azure F#unctionsAzure F#unctions
Azure F#unctions
 
VPN Access Runbook
VPN Access RunbookVPN Access Runbook
VPN Access Runbook
 

Mehr von DEVCON

Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...DEVCON
 
The A1 by Christian John Felix
The A1 by Christian John FelixThe A1 by Christian John Felix
The A1 by Christian John FelixDEVCON
 
Developing Your First Mobile VR App by NJ Realubit
Developing Your First Mobile VR App by NJ RealubitDeveloping Your First Mobile VR App by NJ Realubit
Developing Your First Mobile VR App by NJ RealubitDEVCON
 
Smart Waste Disposal System by Russ Earl Malangen
Smart Waste Disposal System by Russ Earl MalangenSmart Waste Disposal System by Russ Earl Malangen
Smart Waste Disposal System by Russ Earl MalangenDEVCON
 
Progressive Web Apps by Millicent Convento
Progressive Web Apps by Millicent ConventoProgressive Web Apps by Millicent Convento
Progressive Web Apps by Millicent ConventoDEVCON
 
How to Prevent Design Blindness by Tin Balabat
How to Prevent Design Blindness by Tin BalabatHow to Prevent Design Blindness by Tin Balabat
How to Prevent Design Blindness by Tin BalabatDEVCON
 
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del MundoPayment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del MundoDEVCON
 
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...DEVCON
 
Securing Your AWS Cloud Infrastructure by Neil Hermosilla
Securing Your AWS Cloud Infrastructure by Neil HermosillaSecuring Your AWS Cloud Infrastructure by Neil Hermosilla
Securing Your AWS Cloud Infrastructure by Neil HermosillaDEVCON
 
Talk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
Talk nerdy to me: how the future of UX is conversation and bots by Brian RoweTalk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
Talk nerdy to me: how the future of UX is conversation and bots by Brian RoweDEVCON
 
Pokemon Go Analysis by Jolo Balbin
Pokemon Go Analysis by Jolo BalbinPokemon Go Analysis by Jolo Balbin
Pokemon Go Analysis by Jolo BalbinDEVCON
 
Docker - Contain that Wild Application by Marvin Arcilla
Docker - Contain that Wild Application by Marvin ArcillaDocker - Contain that Wild Application by Marvin Arcilla
Docker - Contain that Wild Application by Marvin ArcillaDEVCON
 
Applying Machine Learning for Mobile Games by Neil Patrick Del Gallego
Applying Machine Learning for Mobile Games by Neil Patrick Del GallegoApplying Machine Learning for Mobile Games by Neil Patrick Del Gallego
Applying Machine Learning for Mobile Games by Neil Patrick Del GallegoDEVCON
 
Quick prototyping (Construct 2 & Unity) by Roan Contreras
Quick prototyping (Construct 2 & Unity) by Roan ContrerasQuick prototyping (Construct 2 & Unity) by Roan Contreras
Quick prototyping (Construct 2 & Unity) by Roan ContrerasDEVCON
 
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...DEVCON
 
Creating a Hospital Based IoT Solution by Russ Earl Malangen
Creating a Hospital Based IoT Solution by Russ Earl MalangenCreating a Hospital Based IoT Solution by Russ Earl Malangen
Creating a Hospital Based IoT Solution by Russ Earl MalangenDEVCON
 
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...DEVCON
 
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis LozanoRain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis LozanoDEVCON
 
Fundamentals of IoT: Communications with Uttr by Edmandie Samonte
Fundamentals of IoT: Communications with Uttr by Edmandie SamonteFundamentals of IoT: Communications with Uttr by Edmandie Samonte
Fundamentals of IoT: Communications with Uttr by Edmandie SamonteDEVCON
 
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...DEVCON
 

Mehr von DEVCON (20)

Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
Open Minded? Software Engineer to a UX Engineer. Ask me how. by Micael Diaz d...
 
The A1 by Christian John Felix
The A1 by Christian John FelixThe A1 by Christian John Felix
The A1 by Christian John Felix
 
Developing Your First Mobile VR App by NJ Realubit
Developing Your First Mobile VR App by NJ RealubitDeveloping Your First Mobile VR App by NJ Realubit
Developing Your First Mobile VR App by NJ Realubit
 
Smart Waste Disposal System by Russ Earl Malangen
Smart Waste Disposal System by Russ Earl MalangenSmart Waste Disposal System by Russ Earl Malangen
Smart Waste Disposal System by Russ Earl Malangen
 
Progressive Web Apps by Millicent Convento
Progressive Web Apps by Millicent ConventoProgressive Web Apps by Millicent Convento
Progressive Web Apps by Millicent Convento
 
How to Prevent Design Blindness by Tin Balabat
How to Prevent Design Blindness by Tin BalabatHow to Prevent Design Blindness by Tin Balabat
How to Prevent Design Blindness by Tin Balabat
 
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del MundoPayment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
Payment Acceptance and Card Tokenization in JavaScript by Diwa Del Mundo
 
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
Solving Database Management, Migration, and Scaling Problems with DevOps Tool...
 
Securing Your AWS Cloud Infrastructure by Neil Hermosilla
Securing Your AWS Cloud Infrastructure by Neil HermosillaSecuring Your AWS Cloud Infrastructure by Neil Hermosilla
Securing Your AWS Cloud Infrastructure by Neil Hermosilla
 
Talk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
Talk nerdy to me: how the future of UX is conversation and bots by Brian RoweTalk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
Talk nerdy to me: how the future of UX is conversation and bots by Brian Rowe
 
Pokemon Go Analysis by Jolo Balbin
Pokemon Go Analysis by Jolo BalbinPokemon Go Analysis by Jolo Balbin
Pokemon Go Analysis by Jolo Balbin
 
Docker - Contain that Wild Application by Marvin Arcilla
Docker - Contain that Wild Application by Marvin ArcillaDocker - Contain that Wild Application by Marvin Arcilla
Docker - Contain that Wild Application by Marvin Arcilla
 
Applying Machine Learning for Mobile Games by Neil Patrick Del Gallego
Applying Machine Learning for Mobile Games by Neil Patrick Del GallegoApplying Machine Learning for Mobile Games by Neil Patrick Del Gallego
Applying Machine Learning for Mobile Games by Neil Patrick Del Gallego
 
Quick prototyping (Construct 2 & Unity) by Roan Contreras
Quick prototyping (Construct 2 & Unity) by Roan ContrerasQuick prototyping (Construct 2 & Unity) by Roan Contreras
Quick prototyping (Construct 2 & Unity) by Roan Contreras
 
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
A Smarter World: The Mesh of Interconnected Devices and Artificial Intelligen...
 
Creating a Hospital Based IoT Solution by Russ Earl Malangen
Creating a Hospital Based IoT Solution by Russ Earl MalangenCreating a Hospital Based IoT Solution by Russ Earl Malangen
Creating a Hospital Based IoT Solution by Russ Earl Malangen
 
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
Developing a Smart Farm: Using Low-Cost electronics and a Civil Engineering B...
 
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis LozanoRain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
Rain Classifier: The Engineered Way of Evaluating the Rain by Paulo Luis Lozano
 
Fundamentals of IoT: Communications with Uttr by Edmandie Samonte
Fundamentals of IoT: Communications with Uttr by Edmandie SamonteFundamentals of IoT: Communications with Uttr by Edmandie Samonte
Fundamentals of IoT: Communications with Uttr by Edmandie Samonte
 
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
Protocol-Oriented Programming in iOS: the Correct Way to Use Swift by JC Vela...
 

Kürzlich hochgeladen

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Kürzlich hochgeladen (20)

How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Python Code Camp for Professionals 4/4

  • 2. MongoDB • Much fasterthan SQL databases • No needto learnquery languages*and setups • Easier toscale whendesignedproperly
  • 3. Install pymongo pip install pymongo easy_install pymongo
  • 4. Hello World from pymongo import MongoClient client = MongoClient("localhost", 27017) db = client.databasename
  • 5. Step from pymongo import MongoClient Import MongoClient from pymongo client = MongoClient("localhost", 27017) Connect to the mongodb server at the IP address and port defined db = client.databasename Access a specific database in the mongodb server collection = db.collectionname Access a specific collection (table in SQL) in the selected db
  • 7. Create @route("/register", method="POST") def newuser(): username = request.forms.get("username") password = request.forms.get("password") email = request.forms.get("email") userdata = {"name":username, "password":password, "email":email} try: db.users.save(userdata) except: return {"status":"ERROR"} return {"status":"OK"}
  • 8. Step username = request.forms.get("username") Get the username, password, email to data from the forms userdata = {"name":username, "password":password, "email":email} Create a dictionary with the data obtained above try: Setup anexception handler
  • 9. Step db.users.save(userdata) Save the dictionary to the users collection in the db we connected before except: Start of the exception block. Thiswill execute when the db save fails
  • 10. Read @route("/user/list") def listuser(): usercursor = db.users.find({},{"_id":False}) users = list(usercursor) return {"users":users}
  • 11. Step usercursor = db.users.find({},{"_id":False}) Find allentries in the collection named users and do not show the _id field users = list(usercursor) Convert the cursor object into a list,which we can be converted to a jsonobject return {"users":users} Return the list of users to the browser
  • 12. The Query Format db.collectionname.find(filter,projection) Filter is the expression that needs to be true an element to be included Examples: • {} = will return all • {“name”:”paolo”} = will only return entries with name exactly to“paolo” • {“name”:”paolo”, “age”:{“$lte”:30}} = will only return entries with names exactly “paolo” and age is less thanor equal to 30 See more filter operators here: https://docs.mongodb.com/manual/reference/operator/query/
  • 13. The Query Format db.collectionname.find(filter,projection) Projection controls what fields will be shown, done by setting field names True or False Examples: {“name”:True} {“_id”:False}
  • 14. Inputs in Bottle Via POST body @route('/login', method="POST") def login(): username = request.forms.get("username") password = request.forms.get("password") acceptedpasswords = ["gloopgroup", "devconph" , "adventuretime"] if password in acceptedpasswords: return "Welcome "+ username else: return "Unauthorized" Visit: localhost:8001/login using login page
  • 15. Activity 1 Create a calculatorapi: http://localhost:8001/operation/operand1/operand2 will return the value of operand1 <operation> operand2 Example: /subtraction/10/2 will output 8
  • 16. Common Return TYPES PlainText Similar to whatwe were doing earlier
  • 17. Common Return TYPES Binary Whenreturning fileslike images, video, audio, pdfs…
  • 18. Common Return TYPES JSON The common return type for APIs Example:FB API /{userid}/friends { "data": [ { "name": "Terence Pua", "id": "608407" }, { "name": "Gene Paul Quevedo", "id": "10153785024974240" }, { "name": "Jc Velasquez", "id": "722462218" }, { "name": "Jomel C. Imperio", "id": "779287017" } ], "summary": { "total_count": 770 } }
  • 19. Common Return TYPES HTML Returnweb pages with dynamic/static content <!DOCTYPE html> <html itemscope itemtype="http://schema.org/QAPage"> <head> <title>regex - Validate email address in JavaScript? - Stack Overflow</title> <link rel="shortcut icon" href="//cdn.sstatic.net/Sites/stackoverflow/img/favicon.ico?v=4f32ecc8f43d"> <link rel="apple-touch-icon image_src" href="//cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon.png?v=c78bd457575a"> <link rel="search" type="application/opensearchdescription+xml" title="Stack Overflow" href="/opensearch.xml"> <meta name="twitter:card" content="summary"> <meta name="twitter:domain" content="stackoverflow.com"/> <meta property="og:type" content="website" /> <meta property="og:image" itemprop="image primaryImageOfPage" content="http://cdn.sstatic.net/Sites/stackoverflow/img/apple- touch-icon@2.png?v=73d79a89bded&a" /> <meta name="twitter:title" property="og:title" itemprop="title name" content="Validate email address in JavaScript?" /> <meta name="twitter:description" property="og:description" itemprop="description" content="How can an email address be validated in JavaScript?" /> <meta property="og:url" content="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript"/> <link rel="canonical" href="http://stackoverflow.com/questions/46155/validate-email-address-in-javascript" />
  • 20. Returning JSON Object JSON Simplyreturn a dictionary or list @route("/json") def jason(): return {"lastname":"bourne", "alias":"David Webb"}
  • 21. Returning Static HTML HTML Use static_file from bottle @route("/loginpage") def loginpage(): return static_file("login.html", root=".")
  • 22. Testing the POST Handler Visit localhost:8081/loginpage Type your nameand use any of theseas passwordg gloopgroup, devconph, adventuretime Click submit
  • 23. The POST Request Cycle <form action="/login" method="POST"> Method dictates what kind of request happens when submitted Action tells the browser where to submit the request <input type="text" name="username"> Adds a text input that will be associated to the username field <input type="password" name="password"> Adds a password inputthat willbe associatedto the password field <input type="submit"> Adds a button that submits the form whenclicked
  • 24. Returning Dynamic HTML HTML Use a templatingengine: • Library thatcan substitutevariables intoa templatequickly and cleanly • Isolates thedesigner’s job of designing and thecoder’s job of coding
  • 25. Install Tenjin pip install tenjin easy_install tenjin
  • 26. Using Tenjin from gevent import monkey; monkey.patch_all() from bottle import run, route, request import tenjin from tenjin.helpers import * @route("/introduction/<name>/<age>/<work>") def template1(name, age, work): context = {"name":name, "age":age, "work":work} return engine.render("introduction.html", context); engine = tenjin.Engine(path=['.']) run(server='gevent', host="localhost", port=8001, debug=True)
  • 27. The template <!doctype html> <html lang="en"> <head> <title>Login</title> </head> <body> <h1>${name}</h1> <h2>Age:${age}<h2> <h2>Work:${work}<h2> </body> </html>
  • 28. Step from gevent import monkey; monkey.patch_all() from bottle import run, route, request import tenjin from tenjin.helpers import * Import alllibraries, including tenjin and all helper methods @route("/introduction/<name>/<age>/<work>") Define a route for the url, and define variables in it def template1(name, age, work): Declare a request handler and receive the variables from the url
  • 29. Step context = {"name":name, "age":age, "work":work} Define a context variable, which is a dictionary of values that will be substituted into the template return engine.render("introduction.html", context); Render the template called introduction.html using the context variable named context, and return it to the browser engine = tenjin.Engine(path=['.']) Instructs the templating engine to look for the templates in the directories listed in path
  • 30. Step (Inside the template) <!doctype html> <html lang="en"> <head> <title>Login</title> </head> <body> <h1>${name}</h1> <h2>Age:${age}<h2> <h2>Work:${work}<h2> </body> </html> { "name":"Paolo", "age":"30", "work":"Synergist" } +
  • 31. Displaying Lists @route("/spell/<word>") def template1(word): letters = list(word) context = {"letters":letters, "word":word} return engine.render("speller.html", context);
  • 32. Step @route("/spell/<word>") Define a route that accepts a variable assigned to word def speller(word): Define a handler that accepts avariable named word letters = list(word) Convert the text string into a listobject. From a string “word”, it becomes a list [“w”, “o”, “r”, “d”]
  • 33. Step context = {"letters":letters} Define a context variable, which contains the listof letters we just created return engine.render("speller.html", context); Render the template called speller.html using the context variable named context, and return it to the browser
  • 34. Step (Inside the template) <?py for letter in letters: ?> Loop on the elements of the list named letters <h3>${letter}</h3><br> Display the element letter along with the html <?py #endfor ?> Denote where the loop ends inthe template <a href="/greet/${word}">greet ${word}</a> Create a link that willcall the greet API we created earlier {"letters":["s", "u", "s", "h", "i"]}
  • 35. Highlighting Names @route("/profiles/<name>") def profile(name): users = [ {"name":"Em", "image":"http://goo.gl/aDxeu1", "age":30, "work":"Futurist"}, {"name":"Paolo", "image":"http://goo.gl/5k2oZr", "age":30, "work":"Synergist"} ] context = {"users":users, "name":name} return engine.render("profiles.html", context)
  • 36. Step users = [ {"name":"Em", "image":"http://goo.gl/aDxeu1", "age":30, "work":"Futurist"}, {"name":"Paolo", "image":"http://goo.gl/5k2oZr", "age":30, "work":"Synergist"} ] Define a list of dictionaries, with each dictionary objectcontaining information about a user. It contains information name,url of the image, age, and work context = {"users":users, "name":name} Define a conext containing the name to behighlighted, and the list of users return engine.render("profiles.html", context) Render the template named profiles.html with the context
  • 37. Step (Inside the template) <?py for user in users: ?> Loop on the elements of the list named users, each element in the listcan be referred to using the user variable <div style="height:100px;"> Create a div element in the html to contain one user element <img src="${user['image']}" style="float:left; height:100%;"/> Place an image in the html coming from the url defined in user[‘image’]
  • 38. Step (Inside the template) <?py if name==user["name"]: ?> Compare the current user’s name to the name entered in the url <strong>Name: ${user['name']}</strong> Thishappens when the above condition istrue, display the name asbold characters <?py else: ?> Add an else handler that executes if condition is not met
  • 39. Step (Inside the template) Name: ${user['name']} This happens when primary condition is not met, display the user’s name without any decorations <?py #endif ?> Denote where the if statement ends
  • 40. Make a Sushi Menu Create a menu using allthe sushiitems in the sushilistvariable Display the image and name of the sushi When the menu item is clicked, it should display another page containingthe name, image, price, and rating of the sushi(defined in the sushilistvariable) The most creative presentation of the menu wins aprize
  • 41. Activity 1 pip install gevent pip install bottle
  • 42. Cost per Mille = • Cost per 1000 impressions • Abuse of statistics • i.e. Magic • i.e. It sucks • Not based on empirical measured data ADVERTISING! Eyeballs cost
  • 43. How many are watching me right now? How many are paying attention? How many are interested? How many are still reading this part? How about now? Now?
  • 44.
  • 45. ROUTER ON PROMISCUOUS MODE DEVICEs SENDING PROBE REQUESTS
  • 51. snoop
  • 52. turn off your phones when going to the lagoon

Hinweis der Redaktion

  1. This is our current project onewatt. It’s a device that can save you up to 40% in your electricity bills by utilizing fluctuations in electricicty prices in WESM throughout the day. How?
  2. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  3. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  4. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  5. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  6. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  7. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  8. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  9. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  10. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  11. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  12. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  13. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  14. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  15. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  16. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  17. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  18. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  19. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  20. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  21. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  22. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  23. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  24. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  25. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  26. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  27. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  28. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  29. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  30. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  31. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  32. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  33. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  34. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  35. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  36. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  37. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  38. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  39. I wont be talking about OneWatt. Since, apparently, Wilson deemed this thing not too thingie enough for the internet of things. So I’m going to talk about something more thingie…
  40. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  41. I did this by exploiting one of the thingiest thinies right now, something that everyone here has on them most fo the time. Your mobile devices. Assuming that an average person has at least 1 devic eon them, I was able to get how many people walked by the screen, how many stayed for at least 2 secs, and how many people finished the ad.
  42. One of the key metrics used in advertising is the number of eyeballs gained by an ad. Makes sense, since advertisers are paying to have their ads seen by the most amount of people. The problem with this though is that this number, or Cost per Mille, is an abuse of statistics, it is not based on a solid methodology. So back then we did this media wall project in Shanghai. we wanted to prove how many people saw the ad, and how long people were looking at it. So we devised a way to have more empirical data.
  43. As of now, I can empirically estimate about ___________ watching me right now.   (turn on device and get count)
  44. The setup is actually quite simple. You can even do it with a router, but for this purpose, I used a pi, connected to a wifi dongle, and this cute little screen i salvaged from an old tv, all powered by a power bank. Very mcgyvery.
  45. This wifi transmitter is set to promiscuous mode, para syang carinderia na bukas sa lahat ng gutong kumain, actually worse, bukas kahit sa mga walang planong kumain. Using this, I am able to sniff all the traffic being trasmitted by all the dvices, specifically probe requests, within a certain range, (with this range varying based on the yyy used).
  46. The CPU, running python, gets the output of tcpdump, mining all the sniffed mac addresses and adding timestamps to each record withing the vicinity, without them installing anything on their device or being aware. So right now I am getting all the mad accdresses of the devices of this group right here, since they are withing x meters form me, which I can now use to check for uniqueness, use for idnetification or use in whatever evil scheme I plan. Sounds excting diba? Borderline snooping.
  47. We ran this on 2 pilot sites, one in Zhngshan park, and the other in Lujiazhui station. Using my setup, on the average, there were 23000 people who pass by our screens everyday, 36% of which stopped and watched for at least 2 secs, and around 10% stayed finished the 15 second ad.
  48. So, especially for the group here <referto prev group>, so what if you got our mac addrsses, that doesn’t sound too bad, are there other possible application of this?
  49. I have used this device in stores to measure foot traffic. I can identify how a customer moves between shelves, and identifying which items attract the most views. Which is important data for a retailer or advertiser.
  50. You can also use this as a replacemnt for gps in geofencing. By attenuating the broadcast range to a specific area. You can then identify new and returning customers to your shop, and instruct your staff to be more accommodating to new customers going in.
  51. And the most fun thing to do with this s probably just snoop. Imagine if we install one of these in each classroom. Using simple data such as class schedules, we can then relate a mac address to a specific student. Imagine then if we leave this device in the lagoon area. We will now have a list of people visiting that spot at say 10pm onwards. Who is meeting who, who is coming in in groups of 2 or even people coming in groups of 3 or more.
  52. So in summary, turn off your phones when going to the lagoon.