User:Max Dovey/PT/TRIMESTER 2: Difference between revisions
No edit summary |
|||
(21 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
===A Short History of The Internet=== | |||
{{youtube| mfMrVKnGzwg}} | |||
THE WEB - html, http, url | |||
web page : html, javascript, css | |||
MArch 1989, Tim Berners-Lee publishes 'information management: A proposal'. | |||
Could login to servers via physical terminals and ssh. He was working on improving terminal interactions with server environments. http://www.w3.org/History/1989/proposal.html | |||
hypertext -Ted Nelson "Computer lib / Dream Machines" defines computer lib championing creative use of technology and computers. He defines Hypermedia in his unstrcutured, loose writng format. Ted Nelson believed in central ownership and a network where users would license in a cut/copy format rather than a c opy paste format. Brings up the argument about the freedom of web2.0 where all the content is free,but access through telecomms costs. Another system would be free acess but pay for content , that way authors would get credited and payed. | |||
HTTP protocol | |||
we no longer view the "original" html doc on the server, we request php,perl that access the html for updates , and caches the file so that it doesnt have to reload it to show it to the browser client every time. | |||
Hosting & Databases | |||
The economics of hosting... | |||
Its only as stable as the next Bussiness plan. | |||
Which isnt wrong, its just bad for us to assume that this is unfair (that when a company changes its bussiness plan and deletes your account its not fair) | |||
If you did have an economic network where you became the purchaser or the license owner of content when you embedd, rather than being the customer, you become the buyer and therefore if the company/ server goes down than you can still have ownership. | |||
Active archives | |||
When 1 person (or millions of people) loose their myspace or geocities page all you hear is complaints, but the scale is greater when cultral institutions and large bussiness (or their server hosting companies) sink and cant pay to recover their archives. | |||
'''Network traffic sound''' | '''Network traffic sound''' | ||
http://www.ioplex.com/~miallen/tcpsound/ | http://www.ioplex.com/~miallen/tcpsound/ | ||
Line 14: | Line 35: | ||
*http://pzwart3.wdka.hro.nl/wiki/Python_CGI | *http://pzwart3.wdka.hro.nl/wiki/Python_CGI | ||
*www.tutorialspoint.com/python/python_cgi_programming.htm | *www.tutorialspoint.com/python/python_cgi_programming.htm | ||
===search === | |||
Where? map dispaying google searchers containing the phrase 'where can i?" http://headroom.pzwart.wdka.hro.nl/~max/where.html | |||
===subtitles=== | |||
'''Takes text from SRT (film subtitle files) into a formatted text file''' | |||
<source lang = "python"> | |||
import sys, zipfile, os, shutil, glob, textwrap, re | |||
from os.path import join | |||
f = open("filmsubs/Lost In Translation [Eng].srt", "r",) | |||
h =open("lostintranslation.txt", "w") | |||
i=0 | |||
for line in f: | |||
# read file | |||
if re.findall(r'\b --> \w+', line): #if you find '-->' do something | |||
# print next(f) | |||
# print i | |||
x = 1 # x = line after this symbol | |||
checkBlank = False | |||
while checkBlank is False: | |||
p = open("filmsubs/Lost In Translation [Eng].srt", "r",) | |||
line = p.readlines()[i+x] #read line from point i(where we last where) plus x (read on from this point) | |||
h.write(line) | |||
p.close() | |||
x=x+1 #iterate this digit so that it reads nextline in this while loop until.... | |||
if re.match(r'^\s*$',line): | |||
checkBlank = True | |||
i=i+1 | |||
</source > | |||
===pilimageseuqncefromtextfile=== | |||
<source lang = "python"> | |||
import PIL | |||
from PIL import ImageFont | |||
from PIL import Image | |||
from PIL import ImageDraw | |||
import struct, sys , time , os | |||
import glob | |||
from images2gif import writeGif | |||
import sys, zipfile, os, shutil, glob, textwrap | |||
from os.path import join | |||
font = ImageFont.truetype("/Library/Fonts/arial.ttf", size= 12, index = 0 , encoding = 'armn' ) #set font to armn apple roman | |||
img=Image.new("RGBA", (600,480),(0,0,0)) | |||
pages = 0 | |||
speed = 0.2 | |||
height = 7 | |||
f = open("thegrandbeauty.txt", "r",) | |||
# text = f.readlines() | |||
if not os.path.exists('images'): | |||
os.makedirs('images') | |||
for word in f: | |||
pages = pages +1 | |||
height = height +10 | |||
draw = draw = ImageDraw.Draw(img) | |||
draw.text((260, height),word,(255,255,255),font=font) | |||
img.save("images/a_test%02d.png" % pages) | |||
</source > | |||
[[File:A test14.png]] | |||
<br> | |||
''A still from subtitle rip of "cleo from 5 - 7" by agnes Varda.'' | |||
===CGI Scripting=== | |||
CGI lesson Networked prototyping | |||
cgi = Common Gateway Interface | |||
using the two simple server commands from a dir of your choice ("python -m simpleHTTPServer or python -m CGIHTTPServer") | |||
write a hello world cgi script | |||
#!/usr/bin/python #shebang | |||
print "Content-type:text/html;charset=utf-8" #header | |||
print #must have blank return before body | |||
print Hello World | |||
or hello time | |||
#!/usr/bin/python | |||
print "Content-type:text/html;charset=utf-8" | |||
print | |||
import datetime | |||
now = datetime.datetime.now() | |||
print str(now) | |||
if you point your browser to your cgi-bin/hello.cgi then you should run the clock python script successfully | |||
you must changer perms on the chmod file | |||
how to link to a cgi script and return results in your html.. | |||
project brief | |||
make a basic cgi run.... | |||
also use this line to specificy the python which you run on your local disk | |||
#!/usr/bin/env python | |||
Guestbook example & hitcounters | |||
make a counter textfile that updates everytime script is run. | |||
http://pzwart3.wdka.hro.nl/wiki/Python_CGI | |||
checklist - | |||
PYthon and CGI | |||
<ul> | |||
<li>1.create a folder called cgi-bin | |||
name your python sketch with 'cgi' extension</li> | |||
2.add shebang line to python script | |||
#!/usr/bin/python | |||
or | |||
#!/usr/bin/env python | |||
3. print content type at the very top of your script so browser can handle the file accordingly. | |||
print "Content-type: text/html;charset=utf-8" | |||
print | |||
__blank line___ | |||
start code | |||
4. change perms on cgi script so that it is executable | |||
chmod 755 myscript.cgi | |||
5. run a python -m CGIHTTPServer from the dir to check if script is working. | |||
open up the browser to your ip:8000/dir/file.cgi | |||
Be warned. when listing directories make them full absolute path as the apache server is running from localhost and needs to find the file from the top of directory. no local. | |||
some apache is configed so that you should copy your sgi scripts to - | |||
/usr/lib/cgi-bin | |||
</ul> | |||
===Sailor's Dictionary=== | |||
Sailor's Dictionary translates your words into the sailors dictionary via a speech search engine. | |||
(must use google chrome for speech enable) | |||
http://headroom.pzwart.wdka.hro.nl/~max/words2.html | |||
code - | |||
<source lang = "python" > | |||
#!/usr/bin/env python | |||
import cgi, urllib | |||
import cgitb; cgitb.enable() | |||
from xml.sax.saxutils import quoteattr | |||
form = cgi.FieldStorage() | |||
q = form.getvalue("q", "").strip().lower() | |||
print "Content-type: text/html;charset=utf-8" | |||
print | |||
print """ | |||
<!DOCTYPE html> | |||
<html> | |||
<head> | |||
<meta charset="utf-8" /> | |||
<title>wordin: results</title> | |||
<link rel="stylesheet" type="text/css" href="/styles.css"> | |||
</head> | |||
<body> | |||
<div class="top"><form action="" class="top"> | |||
<a href="/~max/public_html/words2.html"> | |||
<span class="r">w</span> | |||
<span class="g">o</span> | |||
<span class="b">r</span> | |||
<span class="r">d</span> | |||
<span class="g">s</span> | |||
</a> | |||
""" | |||
print '<input type="text" name="q" value='+quoteattr(q)+' />' | |||
print """ | |||
</form> | |||
<div class="links"> | |||
""" | |||
print '<a href="images.cgi?' + urllib.urlencode({"q": q}) + '">images</a>' | |||
print """ | |||
</div> | |||
</div> | |||
""" | |||
a = [] | |||
b = [] | |||
for line in open("/Users/user/Desktop/web/ryog/cgi-bin/sailorsdictionary.txt"): | |||
line = line.lower().strip() | |||
if ("." in line): | |||
w, d = line.split(".", 1) | |||
combo = (w,d) | |||
a.append(w) | |||
b.append(d) | |||
dictionary = dict(zip(a,b)) | |||
if q: | |||
for key,value in dictionary.items(): | |||
if q in key: | |||
print "<div> <b>" + key + "</b>" + value + "</div>" | |||
# + '<a href="?' + urllib.urlencode({'q': value[5:]}) + '">' + line[5:] + "</a></div>" | |||
# print ("<div>"+line+"<div>") | |||
print """ | |||
</body> | |||
</html> | |||
""" | |||
</source> | |||
===speech=== | |||
'''Talking into the Twitter Stream''' | |||
<source lang = "Python" > | |||
import json | |||
import simplejson | |||
import os, sys | |||
import time | |||
import commands | |||
import subprocess | |||
import twitter | |||
CONSUMER_KEY = "****" | |||
CONSUMER_SECRET = "****" | |||
OAUTH_TOKEN = "****" | |||
OAUTH_TOKEN_SECRET = "****" | |||
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET, | |||
CONSUMER_KEY, CONSUMER_SECRET) | |||
twitter_api = twitter.Twitter(domain='api.twitter.com', | |||
api_version='1.1', | |||
auth=auth | |||
) | |||
f = open("translate.txt", "r") #define file path | |||
key=[] | |||
q = [] | |||
for line in f: | |||
sentence = line.split() | |||
words = sentence[-1::] | |||
key.append(words) | |||
p = open("translationfull.txt", "w",) | |||
sawword= False | |||
q = key | |||
print q | |||
count = 2 | |||
search_results= twitter_api.search.tweets(q=q, count=count) | |||
for status in search_results['statuses']: | |||
text = status['text'] | |||
words = text.split() | |||
print words | |||
for i in words: | |||
if q in words: | |||
sawword=True | |||
print i | |||
p.write(word) | |||
p.writelines("\n ") | |||
elif (sawword): | |||
print word | |||
p.write(word) | |||
p.writelines("\n") | |||
sawword= False | |||
time.sleep(2) | |||
p.close() | |||
</source> | |||
===Google Speech Recognition=== | |||
Google have a pretty handy speech api that you can use with javascript here are some examples (must use chrome) - | |||
'''Change the color of the internet''' | |||
http://headroom.pzwart.wdka.hro.nl/~max/colors.html | |||
<source lang = "html4strict" > | |||
<!DOCTYPE html> | |||
<!-- saved from url=(0064)https://html5-examples.herokuapp.com/web_speech_recognition.html --> | |||
<html xmlns="http://www.w3.org/1999/html"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |||
<title>Simple Web Speech Recognition Example</title> | |||
<script type="text/javascript" src="./Simple Web Speech Recognition Example_files/jquery.min.js"></script> | |||
<body onload="document.getElementById('q').focus()"> | |||
<style> | |||
webkit-transition: 2s background; | |||
</style> | |||
<script type="text/javascript"> | |||
recognition = new webkitSpeechRecognition(); | |||
recognition.continuous = true; | |||
recognition.onresult = function(e) { | |||
color = $.trim(e.results[e.results.length - 1][0]["transcript"]); | |||
$("body").css({ background: color }); | |||
}; | |||
recognition.start(); | |||
</source> | |||
'''live chat''' <br> | |||
http://headroom.pzwart.wdka.hro.nl/~max/solo.html | |||
[[File:New.jpg]] <br> |
Latest revision as of 17:17, 8 April 2014
A Short History of The Internet
THE WEB - html, http, url web page : html, javascript, css
MArch 1989, Tim Berners-Lee publishes 'information management: A proposal'. Could login to servers via physical terminals and ssh. He was working on improving terminal interactions with server environments. http://www.w3.org/History/1989/proposal.html hypertext -Ted Nelson "Computer lib / Dream Machines" defines computer lib championing creative use of technology and computers. He defines Hypermedia in his unstrcutured, loose writng format. Ted Nelson believed in central ownership and a network where users would license in a cut/copy format rather than a c opy paste format. Brings up the argument about the freedom of web2.0 where all the content is free,but access through telecomms costs. Another system would be free acess but pay for content , that way authors would get credited and payed.
HTTP protocol we no longer view the "original" html doc on the server, we request php,perl that access the html for updates , and caches the file so that it doesnt have to reload it to show it to the browser client every time.
Hosting & Databases The economics of hosting... Its only as stable as the next Bussiness plan. Which isnt wrong, its just bad for us to assume that this is unfair (that when a company changes its bussiness plan and deletes your account its not fair) If you did have an economic network where you became the purchaser or the license owner of content when you embedd, rather than being the customer, you become the buyer and therefore if the company/ server goes down than you can still have ownership.
Active archives When 1 person (or millions of people) loose their myspace or geocities page all you hear is complaints, but the scale is greater when cultral institutions and large bussiness (or their server hosting companies) sink and cant pay to recover their archives. Network traffic sound http://www.ioplex.com/~miallen/tcpsound/ html.write()
speech language processing
- http://fritz-weber.de/raw-sonata/
- http://www.voxforge.org/home/read
- http://www.speech.cs.cmu.edu/sphinx/dictator/
- http://nuancedev.github.io/samples/http/python/
CGI
- http://pzwart3.wdka.hro.nl/wiki/Python_CGI_checklist
- http://pzwart3.wdka.hro.nl/wiki/Python_CGI
- www.tutorialspoint.com/python/python_cgi_programming.htm
search
Where? map dispaying google searchers containing the phrase 'where can i?" http://headroom.pzwart.wdka.hro.nl/~max/where.html
subtitles
Takes text from SRT (film subtitle files) into a formatted text file
import sys, zipfile, os, shutil, glob, textwrap, re
from os.path import join
f = open("filmsubs/Lost In Translation [Eng].srt", "r",)
h =open("lostintranslation.txt", "w")
i=0
for line in f:
# read file
if re.findall(r'\b --> \w+', line): #if you find '-->' do something
# print next(f)
# print i
x = 1 # x = line after this symbol
checkBlank = False
while checkBlank is False:
p = open("filmsubs/Lost In Translation [Eng].srt", "r",)
line = p.readlines()[i+x] #read line from point i(where we last where) plus x (read on from this point)
h.write(line)
p.close()
x=x+1 #iterate this digit so that it reads nextline in this while loop until....
if re.match(r'^\s*$',line):
checkBlank = True
i=i+1
pilimageseuqncefromtextfile
import PIL
from PIL import ImageFont
from PIL import Image
from PIL import ImageDraw
import struct, sys , time , os
import glob
from images2gif import writeGif
import sys, zipfile, os, shutil, glob, textwrap
from os.path import join
font = ImageFont.truetype("/Library/Fonts/arial.ttf", size= 12, index = 0 , encoding = 'armn' ) #set font to armn apple roman
img=Image.new("RGBA", (600,480),(0,0,0))
pages = 0
speed = 0.2
height = 7
f = open("thegrandbeauty.txt", "r",)
# text = f.readlines()
if not os.path.exists('images'):
os.makedirs('images')
for word in f:
pages = pages +1
height = height +10
draw = draw = ImageDraw.Draw(img)
draw.text((260, height),word,(255,255,255),font=font)
img.save("images/a_test%02d.png" % pages)
A still from subtitle rip of "cleo from 5 - 7" by agnes Varda.
CGI Scripting
CGI lesson Networked prototyping cgi = Common Gateway Interface using the two simple server commands from a dir of your choice ("python -m simpleHTTPServer or python -m CGIHTTPServer")
write a hello world cgi script
- !/usr/bin/python #shebang
print "Content-type:text/html;charset=utf-8" #header print #must have blank return before body
print Hello World
or hello time
- !/usr/bin/python
print "Content-type:text/html;charset=utf-8" print import datetime now = datetime.datetime.now() print str(now)
if you point your browser to your cgi-bin/hello.cgi then you should run the clock python script successfully you must changer perms on the chmod file how to link to a cgi script and return results in your html.. project brief make a basic cgi run.... also use this line to specificy the python which you run on your local disk
- !/usr/bin/env python
Guestbook example & hitcounters make a counter textfile that updates everytime script is run. http://pzwart3.wdka.hro.nl/wiki/Python_CGI
checklist - PYthon and CGI
- 1.create a folder called cgi-bin name your python sketch with 'cgi' extension 2.add shebang line to python script
- !/usr/bin/python
- !/usr/bin/env python
Sailor's Dictionary
Sailor's Dictionary translates your words into the sailors dictionary via a speech search engine. (must use google chrome for speech enable) http://headroom.pzwart.wdka.hro.nl/~max/words2.html
code -
#!/usr/bin/env python
import cgi, urllib
import cgitb; cgitb.enable()
from xml.sax.saxutils import quoteattr
form = cgi.FieldStorage()
q = form.getvalue("q", "").strip().lower()
print "Content-type: text/html;charset=utf-8"
print
print """
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>wordin: results</title>
<link rel="stylesheet" type="text/css" href="/styles.css">
</head>
<body>
<div class="top"><form action="" class="top">
<a href="/~max/public_html/words2.html">
<span class="r">w</span>
<span class="g">o</span>
<span class="b">r</span>
<span class="r">d</span>
<span class="g">s</span>
</a>
"""
print '<input type="text" name="q" value='+quoteattr(q)+' />'
print """
</form>
<div class="links">
"""
print '<a href="images.cgi?' + urllib.urlencode({"q": q}) + '">images</a>'
print """
</div>
</div>
"""
a = []
b = []
for line in open("/Users/user/Desktop/web/ryog/cgi-bin/sailorsdictionary.txt"):
line = line.lower().strip()
if ("." in line):
w, d = line.split(".", 1)
combo = (w,d)
a.append(w)
b.append(d)
dictionary = dict(zip(a,b))
if q:
for key,value in dictionary.items():
if q in key:
print "<div> <b>" + key + "</b>" + value + "</div>"
# + '<a href="?' + urllib.urlencode({'q': value[5:]}) + '">' + line[5:] + "</a></div>"
# print ("<div>"+line+"<div>")
print """
</body>
</html>
"""
speech
Talking into the Twitter Stream
import json
import simplejson
import os, sys
import time
import commands
import subprocess
import twitter
CONSUMER_KEY = "****"
CONSUMER_SECRET = "****"
OAUTH_TOKEN = "****"
OAUTH_TOKEN_SECRET = "****"
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
CONSUMER_KEY, CONSUMER_SECRET)
twitter_api = twitter.Twitter(domain='api.twitter.com',
api_version='1.1',
auth=auth
)
f = open("translate.txt", "r") #define file path
key=[]
q = []
for line in f:
sentence = line.split()
words = sentence[-1::]
key.append(words)
p = open("translationfull.txt", "w",)
sawword= False
q = key
print q
count = 2
search_results= twitter_api.search.tweets(q=q, count=count)
for status in search_results['statuses']:
text = status['text']
words = text.split()
print words
for i in words:
if q in words:
sawword=True
print i
p.write(word)
p.writelines("\n ")
elif (sawword):
print word
p.write(word)
p.writelines("\n")
sawword= False
time.sleep(2)
p.close()
Google Speech Recognition
Google have a pretty handy speech api that you can use with javascript here are some examples (must use chrome) -
Change the color of the internet
http://headroom.pzwart.wdka.hro.nl/~max/colors.html
<!DOCTYPE html>
<!-- saved from url=(0064)https://html5-examples.herokuapp.com/web_speech_recognition.html -->
<html xmlns="http://www.w3.org/1999/html"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Simple Web Speech Recognition Example</title>
<script type="text/javascript" src="./Simple Web Speech Recognition Example_files/jquery.min.js"></script>
<body onload="document.getElementById('q').focus()">
<style>
webkit-transition: 2s background;
</style>
<script type="text/javascript">
recognition = new webkitSpeechRecognition();
recognition.continuous = true;
recognition.onresult = function(e) {
color = $.trim(e.results[e.results.length - 1][0]["transcript"]);
$("body").css({ background: color });
};
recognition.start();