Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
ee18984
Merge pull request #1 from The-Knowledge-House/master
joojie Mar 30, 2016
7a8ecb1
Assignment1
joojie Mar 30, 2016
e1006b4
CleanVersion
joojie Mar 30, 2016
d69c5e0
Assignment2 upload
joojie Apr 1, 2016
1e44eb5
april12-2016
joojie Apr 15, 2016
4a01cd4
Merge pull request #2 from The-Knowledge-House/master
joojie Apr 15, 2016
7d3aca5
adding assignment 3.3
May 6, 2016
a0c8732
sunday race day update 1
May 8, 2016
a7afae1
sunday raceday 2
May 8, 2016
6440843
assignment 5.2 + cleanup
May 9, 2016
f5bbb44
clean up = Assignment 5.2
May 9, 2016
8b5d27c
Assignment 6.5
May 9, 2016
af907c8
Assignment 7.1
May 9, 2016
2c453ba
Assignment 7.3
May 9, 2016
dd03e31
cwAVG for Stepheon Nixon
May 9, 2016
d548b1b
cwAVG_SN_Debug
May 9, 2016
0a8ccaf
Merge branch 'master' of https://github.com/The-Knowledge-House/pytho…
May 10, 2016
e06159c
Merge branch 'The-Knowledge-House-master'
May 10, 2016
8b1f4d1
Assignment 8.4
May 10, 2016
2b357b4
Assignment 9.4
May 11, 2016
8e67500
12-2preview
May 14, 2016
7ab8436
first webscrape!
May 18, 2016
f2819c8
assignment_10.2
May 19, 2016
930fa94
cleanup
May 19, 2016
176618c
Assignments Update
May 19, 2016
c93dad3
Assignments 11 and 12
May 20, 2016
801a2c9
Update to Assignments 12
May 20, 2016
94ab34b
update 25-2016-05
May 27, 2016
dbaf5bd
2x Folder check
May 31, 2016
cc9beea
Merge pull request #4 from The-Knowledge-House/master
joojie May 31, 2016
695464d
assignment push
Jun 1, 2016
078379f
Merge branch 'master' of https://github.com/joojie/python01
Jun 1, 2016
1b92eef
Merge pull request #5 from The-Knowledge-House/master
joojie Jun 7, 2016
e0e1583
Assignment 16. 1&2 push
Jun 11, 2016
d8d1370
Merge branch 'master' of https://github.com/joojie/python01
Jun 11, 2016
407a349
Assignment 17 & 18 push
Jun 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Assignments/.DS_Store
Binary file not shown.
56 changes: 56 additions & 0 deletions Assignments/10strip.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'''Hello Fellows,

Write a program to read through the mbox-short.txt and figure out the distribution by hour of the day for each of the messages.
You can pull the hour out from the 'From ' line by finding the time and then splitting the string a second time using a colon.

From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008

Once you have accumulated the counts for each hour, print out the counts, sorted by hour as shown below.


Begin to write the program with the following code below:
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)


Happy Coding,
Tunisia'''

def openFile():
fname = raw_input("press enter: ")
if len(fname) < 1 : fname = "mbox-short.txt"
try:
fh = open(fname, 'r')
except:
print "Error opening file", fname
quit()
return fh

def startsWith():
sw = raw_input("press enter: ")
if len(sw) < 1 : sw = "From"
return sw

def countTimes(lines,s):
counts = dict()
for line in lines:
if line.startswith(s) and not line.startswith(s+':'):
line = line.strip().split()
str = line[5]
hour = str[0:str.find(":"):1]
counts[hour] = counts.get(hour,0) + 1
return counts

def sortTimes(d):
lst = list()
for key, val in d.items():
lst.append((key,val))
lst.sort()
for val,key in lst:
print val,key

fh = openFile()
sw = startsWith()
dictionary = countTimes(fh,sw)
t = sortTimes(dictionary)
Binary file added Assignments/Ages.db
Binary file not shown.
8 changes: 0 additions & 8 deletions Assignments/Assignment_1

This file was deleted.

18 changes: 0 additions & 18 deletions Assignments/Assignment_10.2

This file was deleted.

56 changes: 56 additions & 0 deletions Assignments/Assignment_10.2_Massawa_Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
'''Hello Fellows,

Write a program to read through the mbox-short.txt and figure out the distribution by hour of the day for each of the messages.
You can pull the hour out from the 'From ' line by finding the time and then splitting the string a second time using a colon.

From stephen.marquard@uct.ac.za Sat Jan 5 09:14:16 2008

Once you have accumulated the counts for each hour, print out the counts, sorted by hour as shown below.


Begin to write the program with the following code below:
name = raw_input("Enter file:")
if len(name) < 1 : name = "mbox-short.txt"
handle = open(name)


Happy Coding,
Tunisia'''

def openFile():
fname = raw_input("press enter: ")
if len(fname) < 1 : fname = "mbox-short.txt"
try:
fh = open(fname, 'r')
except:
print "Error opening file", fname
quit()
return fh

def startsWith():
sw = raw_input("press enter: ")
if len(sw) < 1 : sw = "From"
return sw

def countTimes(lines,s):
counts = dict()
for line in lines:
if line.startswith(s) and not line.startswith(s+':'):
line = line.strip().split()
str = line[5]
hour = str[0:str.find(":"):1]
counts[hour] = counts.get(hour,0) + 1
return counts

def sortTimes(d):
lst = list()
for key, val in d.items():
lst.append((key,val))
lst.sort()
for val,key in lst:
print val,key

fh = openFile()
sw = startsWith()
dictionary = countTimes(fh,sw)
t = sortTimes(dictionary)
12 changes: 12 additions & 0 deletions Assignments/Assignment_11_Massawa_Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import re

Fname = raw_input("Enter file name: ")
f = open(Fname)
fr = f.read()


numbers = re.findall('[0-9]+', fr)

numbers = map(int, numbers)

print sum(numbers)
Binary file added Assignments/Assignment_12_Massawa_Lawson.pdf
Binary file not shown.
30 changes: 30 additions & 0 deletions Assignments/Assignment_12_Massawa_Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import socket

mysock=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
mysock.connect(('www.pythonlearn.com',80))
mysock.send('GET http://www.pythonlearn.com/code/intro-short.txt HTTP/1.0\n\n')

Etag = []
while True:
data = mysock.recv(512)
#for line in data:
# if line.startswith('Etag'):
# print line
# Etag.append(line)
# ConLen = line.startswith('Content-Length')
# CacCon = line.startswith('Cache-Control')
# ConTyp = line.startswith('Content-Type')
if (len(data)<1):
break
print data, #"\n Assignment Data: \n"
#print Etag, "\n", ConLen, "\n", CacCon, "\n", ConTyp

mysock.close

'''ETag: "20f7401b-1d3-521e9853a392b"

Content-Length: 467

Cache-Control: max-age=604800, public

Content-Type: text/plain'''
20 changes: 20 additions & 0 deletions Assignments/Assignment_13.1_Massawa_Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# 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*

url = raw_input('Enter - ')
html = urllib.urlopen(url).read()

soup = BeautifulSoup(html)

# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
# Look at the parts of a tag
print 'TAG:',tag
print 'URL:',tag.get('href', None)
print 'Contents:',tag.contents[0]
print 'Attrs:',tag.attrs
15 changes: 15 additions & 0 deletions Assignments/Assignment_13.2_Massawa_Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# 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 *

url = raw_input('Enter - ')
html = urllib.urlopen(url).read()
soup = BeautifulSoup(html)

# Retrieve all of the anchor tags
tags = soup('a')
for tag in tags:
print tag.get('href', None)
25 changes: 25 additions & 0 deletions Assignments/Assignment_14_Massawa_Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import urllib
import xml.etree.ElementTree as ET

serviceurl = 'http://maps.googleapis.com/maps/api/geocode/xml?'

while True:
address = raw_input('Enter location: ')
if len(address) < 1 : break

url = serviceurl + urllib.urlencode({'sensor':'false', 'address': address})
print 'Retrieving', url
uh = urllib.urlopen(url)
data = uh.read()
print 'Retrieved',len(data),'characters'
print data
tree = ET.fromstring(data)


results = tree.findall('result')
lat = results[0].find('geometry').find('location').find('lat').text
lng = results[0].find('geometry').find('location').find('lng').text
location = results[0].find('formatted_address').text

print 'lat',lat,'lng',lng
print location
23 changes: 23 additions & 0 deletions Assignments/Assignment_15.1_Massawa_Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import urllib
import json


serviceurl = 'http://maps.googleapis.com/maps/api/geocode/json?'
#serviceurl = 'http://python-data.dr-chuck.net/geojson?'

while True:
address = raw_input('\nEnter a location: ')
if len(address) < 1 : break

print 'Retrieving', serviceurl + urllib.urlencode({'sensor':'false', 'address': address})
print 'Retrieved',len(urllib.urlopen( serviceurl + urllib.urlencode({'sensor':'false', 'address': address})).read()),'characters'

try: js = json.loads(urllib.urlopen( serviceurl + urllib.urlencode({'sensor':'false', 'address': address})).read())
except: js = None
if 'status' not in js or js['status'] != 'OK':
print '==== Failure To Retrieve ===='
continue

place_id = js["results"][0]["place_id"]
print 'Place id', place_id
46 changes: 46 additions & 0 deletions Assignments/Assignment_15.2_Massawa_Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import urllib
import xml.etree.ElementTree as ET
import json

serviceurl = 'http://maps.googleapis.com/maps/api/geocode/xml?'

while True:
address = raw_input('Enter location: ')
if len(address) < 1 : break

url = serviceurl + urllib.urlencode({'sensor':'false', 'address': address})
print 'Retrieving', url
uh = urllib.urlopen(url)
data = uh.read()
print 'Retrieved',len(data),'characters'
print data
tree = ET.fromstring(data)


results = tree.findall('result')
lat = results[0].find('geometry').find('location').find('lat').text
lng = results[0].find('geometry').find('location').find('lng').text
location = results[0].find('formatted_address').text

print 'lat',lat,'lng',lng
print location

input = '''
[
{ "id" : "001",
"x" : "2",
"name" : "Chuck"
} ,
{ "id" : "009",
"x" : "7",
"name" : "Chuck"
}
]'''

info = json.loads(input)
print 'User count:', len(info)

for item in info:
print 'Name', item['name']
print 'Id', item['id']
print 'Attribute', item['x']
31 changes: 31 additions & 0 deletions Assignments/Assignment_16.1_Massawa.Lawson.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'''********************************** Assignment_16.1_Massawa.Lawson Result ***********************************************
First Row in the resulting record set: 416E6E65726F793137

*************************************************************************************************************

Instructions
If you don't already have it, install the SQLite Browser from http://sqlitebrowser.org/.

Then, create a SQLITE database or use an existing database and create a table in the database called "Ages":

CREATE TABLE Ages (
name VARCHAR(128),
age INTEGER
)
Then make sure the table is empty by deleting any rows that you previously inserted, and insert these rows and only these rows with the following commands:

DELETE FROM Ages;
INSERT INTO Ages (name, age) VALUES ('Malakhy', 37);
INSERT INTO Ages (name, age) VALUES ('Marlee', 23);
INSERT INTO Ages (name, age) VALUES ('Timucin', 18);
INSERT INTO Ages (name, age) VALUES ('Anneroy', 17);
Once the inserts are done, run the following SQL command:
SELECT hex(name || age) AS X FROM Ages ORDER BY X
Find the first row in the resulting record set and enter the long string that looks like 53656C696E613333.
Note: This assignment must be done using SQLite - in particular, the SELECT query above will not work in any other database. So you cannot use MySQL or Oracle for this assignment.

********************************** Assignment_16.1_Massawa.Lawson Result ***********************************************
First Row in the resulting record set: 416E6E65726F793137
'''


Loading