Skip to content

Instantly share code, notes, and snippets.

View acrymble's full-sized avatar

Adam Crymble acrymble

  • London
View GitHub Profile
@acrymble
acrymble / python-elif.py
Created June 30, 2011 13:06
Python Elif
if char == '<':
# do something
elif char == '>':
# do another thing
else:
# do something completely different
@acrymble
acrymble / obo.py
Created June 30, 2011 13:09
obo.py
# obo.py
def stripTags(pageContents):
startLoc = pageContents.find("<hr/><h2>")
pageContents = pageContents[startLoc:]
inside = 0
text = ''
for char in pageContents:
@acrymble
acrymble / python-integer.py
Created June 30, 2011 13:16
Python Integer
inside = 1
@acrymble
acrymble / python-file-handle.py
Created June 30, 2011 13:18
Python File Handle
f = open('helloworld.txt','w')
f.write('hello world')
f.close()
@acrymble
acrymble / string-to-list.py
Created June 30, 2011 13:20
Python Strings to List
# string-to-list.py
# some strings
s1 = 'hello world'
s2 = 'howdy world'
# list of characters
charlist = []
for char in s1:
charlist.append(char)
@acrymble
acrymble / HTML-to-list1.py
Created June 30, 2011 13:22
HTML to list 1
#html-to-list1.py
import urllib2, obo
url = 'http://www.oldbaileyonline.org/print.jsp?div=t17800628-33'
response = urllib2.urlopen(url)
html = response.read()
text = obo.stripTags(html)
wordlist = text.split()
print wordlist[0:120]
@acrymble
acrymble / trial-content-to-list.py
Created June 30, 2011 13:26
List of Trial words
['BENJAMIN', 'BOWSEY,', 'Breaking', 'Peace', '&gt;',
'riot,', '28th', 'June', '1780.', '324.', 'BENJAMIN',
'BOWSEY', '(a', 'blackmoor', ')', 'was', 'indicted',
'for', 'that', 'he', 'together', 'with', 'five',
'hundred', 'other', 'persons', 'and', 'more,', 'did,',
'unlawfully,', 'riotously,', 'and', 'tumultuously',
'assemble', 'on', 'the', '6th', 'of', 'June', 'to',
'the', 'disturbance', 'of', 'the', 'public', 'peace',
'and', 'did', 'begin', 'to', 'demolish', 'and', 'pull',
'down', 'the', 'dwelling', 'house', 'of', 'Richard',
@acrymble
acrymble / html-to-list1.py
Created June 30, 2011 14:13
HTML to List
#html-to-list1.py
import urllib2
import dh
url = 'http://www.oldbaileyonline.org/print.jsp?div=t17800628-33'
response = urllib2.urlopen(url)
xhtml = response.read()
text = dh.stripTags(xhtml).lower() #add the string method here.
wordlist = text.split()
@acrymble
acrymble / html-to-list1.py
Created July 5, 2011 19:10
HTML to a List of Words
#html-to-list1.py
import urllib2, obo
url = 'http://www.oldbaileyonline.org/print.jsp?div=t17800628-33'
response = urllib2.urlopen(url)
html = response.read()
text = obo.stripTags(html).lower() #add the string method here.
wordlist = text.split()
@acrymble
acrymble / replace.py
Created July 5, 2011 19:13
Python Replace
text = text.replace('[', '')
text = text.replace(']', '')
text = text.replace(',', '')
#etc...