User:Jasper van Loenen/Prototyping/message: Difference between revisions
(Created page with "This form takes a name and a message as its input and uses the [https://www.prowlapp.com/ Prowl API] to send the message to my iPhone.") |
No edit summary |
||
Line 1: | Line 1: | ||
This form takes a name and a message as its input and uses | This form takes a name and a message as its input and uses Prowl <ref>Prowl, IOS push notification API - https://www.prowlapp.com/</ref> and Prowlpy <ref>Prowlpy, Python library for Prowl - https://github.com/jacobb/prowlpy</ref> to send the message to my iPhone. | ||
You'll find an active version of the form [http://pzwart3.wdka.hro.nl/~jvloenen/cgi-bin/message.cgi over here]. | |||
==message.cgi== | |||
<source lang="python"> | |||
#!/usr/bin/env python | |||
#-*- coding:utf-8 -*- | |||
import cgi | |||
import cgitb; cgitb.enable() | |||
query = cgi.FieldStorage() | |||
msg = query.getvalue("msg", "") #getvalue is both GET and POST ($_REQUEST in PHP) | |||
usr = query.getvalue("usr", "") #getvalue is both GET and POST ($_REQUEST in PHP) | |||
#if a message and username have been found, the form was filled so import the Prowl library and send the message | |||
if msg!="your message" and msg!="" and usr!="your name" and usr!="": | |||
import prowlpy | |||
apikey = '1234512345123451234512345123451234512345' #needs a valid Prowl API key, which you can generate on the website | |||
p = prowlpy.Prowl(apikey) | |||
try: | |||
p.add('CGI',usr,msg, 1, None) | |||
print "Location: done.cgi\n\n"; #landing page for successful sending | |||
except Exception,msg: | |||
print "Location: fail.cgi\n\n"; #landing page for failures :( | |||
else: #the form wasn't filled (correctly) so show it (again) | |||
print "Content-type: text/html" | |||
print "" | |||
print """ | |||
<html> | |||
<head> | |||
<style> | |||
textarea {{ | |||
font-size: 32px; | |||
width: 100%; | |||
border: 4px solid black; | |||
height: 400px; | |||
}} | |||
</style> | |||
</head> | |||
<body> | |||
<form action="" method="POST"> | |||
<textarea name="usr" onclick="this.value=''" onfocus="this.value=''">your name</textarea> | |||
<textarea name="msg" onclick="this.value=''" onfocus="this.value=''">your message</textarea> | |||
<input type="submit"> | |||
</form> | |||
</body> | |||
</html> | |||
""" | |||
</source> | |||
<references/> |
Revision as of 16:25, 17 November 2011
This form takes a name and a message as its input and uses Prowl [1] and Prowlpy [2] to send the message to my iPhone.
You'll find an active version of the form over here.
message.cgi
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import cgi
import cgitb; cgitb.enable()
query = cgi.FieldStorage()
msg = query.getvalue("msg", "") #getvalue is both GET and POST ($_REQUEST in PHP)
usr = query.getvalue("usr", "") #getvalue is both GET and POST ($_REQUEST in PHP)
#if a message and username have been found, the form was filled so import the Prowl library and send the message
if msg!="your message" and msg!="" and usr!="your name" and usr!="":
import prowlpy
apikey = '1234512345123451234512345123451234512345' #needs a valid Prowl API key, which you can generate on the website
p = prowlpy.Prowl(apikey)
try:
p.add('CGI',usr,msg, 1, None)
print "Location: done.cgi\n\n"; #landing page for successful sending
except Exception,msg:
print "Location: fail.cgi\n\n"; #landing page for failures :(
else: #the form wasn't filled (correctly) so show it (again)
print "Content-type: text/html"
print ""
print """
<html>
<head>
<style>
textarea {{
font-size: 32px;
width: 100%;
border: 4px solid black;
height: 400px;
}}
</style>
</head>
<body>
<form action="" method="POST">
<textarea name="usr" onclick="this.value=''" onfocus="this.value=''">your name</textarea>
<textarea name="msg" onclick="this.value=''" onfocus="this.value=''">your message</textarea>
<input type="submit">
</form>
</body>
</html>
"""
- ↑ Prowl, IOS push notification API - https://www.prowlapp.com/
- ↑ Prowlpy, Python library for Prowl - https://github.com/jacobb/prowlpy