Skip to content

Instantly share code, notes, and snippets.

View donlovett's full-sized avatar

Don Lovett donlovett

  • ProjectBits Consulting
  • 20191
View GitHub Profile
@donlovett
donlovett / donfirst.groovy
Created November 22, 2015 08:51
Grovy First Program
/**
* Created by don on 11/22/2015.
*/
println "Hello World This is my first test"
def x = 42
println x.getClass()
x = "Hello World"
println x.getClass()
@donlovett
donlovett / re14_djl.py
Created September 16, 2016 20:25
Week 2 Coursera Web python
# Search for lines that start with From and have an at sign
import re
#fname = raw_input('Enter file:')
#hand = open(fname)
hand = open("/home/vagrant/Coursera/Week2/regex_sum_318168.txt")
nums = list()
z = 0
for line in hand:
line = line.rstrip()
x = re.findall('([0-9]+)', line)
@donlovett
donlovett / re14_djl.py
Created September 16, 2016 21:05
Update with some comments and debug code disabled
# Search for lines that have numbers with a regular expression, add to an array, convert to integers and count and sum
# Author Don lovett Based on Code from Using Python to Access Web Data text by Charles Severance
import re
#fname = raw_input('Enter file:') Use for prompted file name
#hand = open(fname)
hand = open("/home/vagrant/Coursera/Week2/regex_sum_318168.txt")
nums = list()
z = 0
for line in hand:
line = line.rstrip()
@donlovett
donlovett / wk4assign1.py
Created September 17, 2016 22:15
Read a webfile and sum the numbers in the table
# Note - this code must run in Python 2.x and you must download
# http://www.pythonlearn.com/code/BeautifulSoup.py
# Into the same folder as this program
# http://www.dr-chuck.com/page1.htm
# Week 4 Assignment Sample is defined
# Author Don lovett Based on Code from Using Python to Access Web Data text by Charles Severance
import re
import urllib
from BeautifulSoup import *
@donlovett
donlovett / wk4assign2_final.py
Created September 18, 2016 05:04
Week 4 2nd assignment
# Note - this code must run in Python 2.x and you must download
# http://www.pythonlearn.com/code/BeautifulSoup.py
# Into the same folder as this program
import urllib
from BeautifulSoup import *
countb = int(input("Enter a count: "))
position = int(input("Enter position: "))
url = 'http://python-data.dr-chuck.net/known_by_Lida.html'
@donlovett
donlovett / xml4localfile.py
Created September 22, 2016 17:01
Read xml file and sum an attribute for Coursera Week 5
import xml.etree.ElementTree as ET
#fname = raw_input('Enter the file name: ')
#fname = '/home/vagrant/Coursera/Week5/comments_42.xml'
fname = '/home/vagrant/Coursera/Week5/comments_318170.xml'
try:
tree = ET.ElementTree(file=fname)
except:
print 'File cannot be opened:', fname
exit()
root = tree.getroot()
@donlovett
donlovett / xml4localfile.py
Created September 22, 2016 18:14
update with stats labeled and debut prints out
import xml.etree.ElementTree as ET
#fname = raw_input('Enter the file name: ')
#fname = '/home/vagrant/Coursera/Week5/comments_42.xml'
fname = '/home/vagrant/Coursera/Week5/comments_318170.xml'
try:
tree = ET.ElementTree(file=fname)
print 'Retreived ',fname
#Retrieved 4204 characters
except:
print 'File cannot be opened:', fname
@donlovett
donlovett / xml4webfile.py
Created September 22, 2016 19:33
Final Week 5 Assignment to pull XML from Web and sum count element
import urllib
import xml.etree.ElementTree as ET
url = raw_input('Enter file: ')
#url = 'http://python-data.dr-chuck.net/comments_318170.xml'
mycounter = 0
mysum = 0
while True:
print 'Retrieving', url
@donlovett
donlovett / jason_webfile.py
Created September 25, 2016 02:05
This is the first assignement for week 6 of the Python Data Course
import urllib
import json
# step 1 determine file to read from the web
# #url = raw_input('Enter file: ')
#url = 'http://python-data.dr-chuck.net/comments_42.json'
url = 'http://python-data.dr-chuck.net/comments_318174.json'
mycounter = 0
mysum = 0
# step 2 read web info into a dictionary
while True:
@donlovett
donlovett / jason_webfile.py
Created September 25, 2016 02:20
Final As Submitted
import urllib
import json
# step 1 determine file to read from the web
# #url = raw_input('Enter file: ')
#url = 'http://python-data.dr-chuck.net/comments_42.json'
url = 'http://python-data.dr-chuck.net/comments_318174.json'
mycounter = 0
mysum = 0
# step 2 read web info into a dictionary
while True: