Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions lab-00/file-copy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/python

f = open("/var/log/system.log")
buf = f.read()
print buf
f1 = open("mylogfile.log")
f1.write(buf)
f1.close()
35 changes: 35 additions & 0 deletions lab-01/file_ops.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/python


# Open the license file, read the content into the buffer
# then close the file descriptor

# f = open('conditions.py')
# f.seek(15)
# lines10 = f.read(5)
# # line11_20 = f.read(10)
# # f.seek(0)
# # lines10 = f.read(10)
# #alllines = f.read()
# print (lines10)
# f.close()

# Open the license file, read the content as "lines" into the
# buffer and close it.

# f = open('conditions.py')
# file_content = f.read()
# print file_content
# f.close()

f = open('conditions.py')
file_content = f.readlines()
print file_content
f.close()

for line in file_content:
if len(line) !=0:
line_list = line.split()
if len(line_list) !=0:
if line_list[0] == 'print':
print line_list
49 changes: 49 additions & 0 deletions lab-01/list-operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@

mylist = []

mylist = [-15.3068189663,-0.883700335702,3.30128033411]

new_list = []

# print mylist[0]
# print mylist[1]
# print mylist[2]

# for list_item in mylist:
# new_item = list_item * 100
# print new_item

new_list = []

# new_list.append(100)
# new_list.append(200)
# new_list.append(300)

items = [100,200,300]

for item in items:
new_list.append(item)
print new_list

# print new_list
# for l in mylist:
# #print l * 100
# new_list.append(l + 100)

# print new_list
# print max(new_list)
# print min(new_list)
# print sum(new_list)

my_range = [0, 1, 2, 3]
my_list = []


for item in range(2,20):
new_item = item + 10
my_list.append(new_item)
print my_list




34 changes: 34 additions & 0 deletions lab-01/strings-operations.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/python

my_string = "My,string,has,many,spaces,let,me,see,how,many"

my_string = "My,string,has,many,spaces,let,me,see,how,many"

my_list = my_string.split(',')

print my_list

length_list = len(my_list)

print length_list

first_item = my_list[0]

print first_item

see_item = my_list[7]

print see_item

# print "Lets loop through the strings"

# for s in my_string.split():
# print ("String literal ", s)

# my_string = "My,string,has,many,commas,let,me,see,how,many"

# Assignment
# Count number of , in the string
# Replace , with space
# Count the string length
# Find the index where the word many starts
16 changes: 0 additions & 16 deletions lab-02/file_ops.py

This file was deleted.

20 changes: 20 additions & 0 deletions lab-02/func-03.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@



# Check if filename is less < 4
def myfunc(filename,nlines):
if filename < 4:
return "error"

with open(filename) as f:
lines = f.readlines()

my_lines = lines[:nlines]

with open('myfiles.txt','w') as f:
for line in my_lines:
f.write(line)

myfunc("functions.py",3)


28 changes: 28 additions & 0 deletions lab-02/functions-args.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

def myfunction(arg1, arg2,arg3="Chicago"):
print "My Very first python function with Arguments"
print "{},{},{}".format(arg1, arg2, arg3)
sum = arg1 + arg2 + arg3

#return sum

if arg3 == "chicago":
second_func(arg1,arg2)
else:
second_func(arg1,arg2,arg3)


# # Polymorphism in Funtion names
def second_func(arg1,arg2,arg3=None):
print("Testing optional argument")
print (arg1,arg2,arg3)

print third_func(arg1)

def third_func(arg1):
return "My arg is: " + arg1


if __name__ == "__main__":
my_return = myfunction("Hello", "World","Toronto")
print my_return
10 changes: 10 additions & 0 deletions lab-02/functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

def myfunction():
print "My Very first python function"

myfunction()

# if __name__ == "__main__":
# myfunction()


File renamed without changes.
14 changes: 14 additions & 0 deletions lab-03/csv_parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/python

with open("N4xFilterTier") as f:
# Reading lines in form of lists
lines = f.readlines()

for line in lines:
print line


## Assignment

# Parse the ny-census.csv file, and print the rows with POP100 clumn is more than 50477
# Find the row with maxium value in column POP100
63 changes: 63 additions & 0 deletions lab-03/ny-census.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
GEOID,SUMLEV,STATE,COUNTY,CBSA,CSA,NECTA,CNECTA,NAME,POP100,HU100,POP100.2000,HU100.2000,P002001,P002001.2000,P002002,P002002.2000,P002003,P002003.2000,P002004,P002004.2000,P002005,P002005.2000,P002006,P002006.2000
36003,050,36,003,99999,999,,,Allegany County,48946,26140,49927,24505,48946,49927,0,0,0,0,0,0,0,0,48946,49927
36005,050,36,005,35620,408,,,Bronx County,1385108,511896,1332650,490659,1385108,1332650,0,0,0,0,0,0,0,0,1385108,1332650
36007,050,36,007,13780,999,,,Broome County,200600,90563,200536,88817,200600,200536,0,0,0,0,0,0,0,0,200600,200536
36009,050,36,009,36460,160,,,Cattaraugus County,80317,41111,83955,39839,80317,83955,0,0,0,0,0,0,0,0,80317,83955
36011,050,36,011,12180,532,,,Cayuga County,80026,36489,81963,35477,80026,81963,0,0,0,0,0,0,0,0,80026,81963
36013,050,36,013,27460,999,,,Chautauqua County,134905,66920,139750,64900,134905,139750,0,0,0,0,0,0,0,0,134905,139750
36015,050,36,015,21300,999,,,Chemung County,88830,38369,91070,37745,88830,91070,0,0,0,0,0,0,0,0,88830,91070
36017,050,36,017,99999,999,,,Chenango County,50477,24710,51401,23890,50477,51401,0,0,0,0,0,0,0,0,50477,51401
36019,050,36,019,38460,999,,,Clinton County,82128,35888,79894,33091,82128,79894,0,0,0,0,0,0,0,0,82128,79894
36021,050,36,021,26460,104,,,Columbia County,63096,32775,63094,30207,63096,63094,0,0,0,0,0,0,0,0,63096,63094
36023,050,36,023,18660,296,,,Cortland County,49336,20577,48599,20116,49336,48599,0,0,0,0,0,0,0,0,49336,48599
36025,050,36,025,99999,999,,,Delaware County,47980,31222,48055,28952,47980,48055,0,0,0,0,0,0,0,0,47980,48055
36027,050,36,027,39100,408,,,Dutchess County,297488,118638,280150,106103,297488,280150,0,0,0,0,0,0,0,0,297488,280150
36029,050,36,029,15380,160,,,Erie County,919040,419974,950265,415868,919040,950265,0,0,0,0,0,0,0,0,919040,950265
36031,050,36,031,99999,999,,,Essex County,39370,25603,38851,23115,39370,38851,0,0,0,0,0,0,0,0,39370,38851
36037,050,36,037,12860,464,,,Genesee County,60079,25589,60370,24190,60079,60370,0,0,0,0,0,0,0,0,60079,60370
36039,050,36,039,99999,999,,,Greene County,49221,29210,48195,26544,49221,48195,0,0,0,0,0,0,0,0,49221,48195
36043,050,36,043,46540,999,,,Herkimer County,64519,33381,64427,32026,64519,64427,0,0,0,0,0,0,0,0,64519,64427
36045,050,36,045,48060,999,,,Jefferson County,116229,57966,111738,54070,116229,111738,0,0,0,0,0,0,0,0,116229,111738
36047,050,36,047,35620,408,,,Kings County,2504700,1000293,2465326,930866,2504700,2465326,0,0,0,0,0,0,0,0,2504700,2465326
36049,050,36,049,99999,999,,,Lewis County,27087,15112,26944,15134,27087,26944,0,0,0,0,0,0,0,0,27087,26944
36051,050,36,051,40380,464,,,Livingston County,65393,27123,64328,24023,65393,64328,0,0,0,0,0,0,0,0,65393,64328
36053,050,36,053,45060,532,,,Madison County,73442,31757,69441,28646,73442,69441,0,0,0,0,0,0,0,0,73442,69441
36055,050,36,055,40380,464,,,Monroe County,744344,320593,735343,304388,744344,735343,0,0,0,0,0,0,0,0,744344,735343
36057,050,36,057,11220,104,,,Montgomery County,50219,23063,49708,22522,50219,49708,0,0,0,0,0,0,0,0,50219,49708
36059,050,36,059,35620,408,,,Nassau County,1339532,468346,1334544,458151,1339532,1334544,0,0,0,0,0,0,0,0,1339532,1334544
36063,050,36,063,15380,160,,,Niagara County,216469,99120,219846,95715,216469,219846,0,0,0,0,0,0,0,0,216469,219846
36065,050,36,065,46540,999,,,Oneida County,234878,104180,235469,102803,234878,235469,0,0,0,0,0,0,0,0,234878,235469
36067,050,36,067,45060,532,,,Onondaga County,467026,202357,458336,196633,467026,458336,0,0,0,0,0,0,0,0,467026,458336
36069,050,36,069,40380,464,,,Ontario County,107931,48193,100224,42647,107931,100224,0,0,0,0,0,0,0,0,107931,100224
36075,050,36,075,45060,532,,,Oswego County,122109,53598,122377,52831,122109,122377,0,0,0,0,0,0,0,0,122109,122377
36077,050,36,077,36580,999,,,Otsego County,62259,30777,61676,28481,62259,61676,0,0,0,0,0,0,0,0,62259,61676
36079,050,36,079,35620,408,,,Putnam County,99710,38224,95745,35030,99710,95745,0,0,0,0,0,0,0,0,99710,95745
36081,050,36,081,35620,408,,,Queens County,2230722,835127,2229379,817250,2230722,2229379,0,0,0,0,0,0,0,0,2230722,2229379
36083,050,36,083,10580,104,,,Rensselaer County,159429,71475,152538,66120,159429,152538,0,0,0,0,0,0,0,0,159429,152538
36085,050,36,085,35620,408,,,Richmond County,468730,176656,443728,163993,468730,443728,0,0,0,0,0,0,0,0,468730,443728
36087,050,36,087,35620,408,,,Rockland County,311687,104057,286753,94973,311687,286753,0,0,0,0,0,0,0,0,311687,286753
36089,050,36,089,36300,999,,,St. Lawrence County,111944,52133,111931,49721,111944,111931,0,0,0,0,0,0,0,0,111944,111931
36091,050,36,091,10580,104,,,Saratoga County,219607,98656,200635,86701,219607,200635,0,0,0,0,0,0,0,0,219607,200635
36093,050,36,093,10580,104,,,Schenectady County,154727,68196,146555,65032,154727,146555,0,0,0,0,0,0,0,0,154727,146555
36099,050,36,099,42900,464,,,Seneca County,35251,16043,33342,14794,35251,33342,0,0,0,0,0,0,0,0,35251,33342
36101,050,36,101,18500,999,,,Steuben County,98990,48875,98726,46132,98990,98726,0,0,0,0,0,0,0,0,98990,98726
36105,050,36,105,99999,999,,,Sullivan County,77547,49186,73966,44730,77547,73966,0,0,0,0,0,0,0,0,77547,73966
36109,050,36,109,27060,296,,,Tompkins County,101564,41674,96501,38625,101564,96501,0,0,0,0,0,0,0,0,101564,96501
36113,050,36,113,24020,104,,,Warren County,65707,38726,63303,34852,65707,63303,0,0,0,0,0,0,0,0,65707,63303
36115,050,36,115,24020,104,,,Washington County,63216,28844,61042,26794,63216,61042,0,0,0,0,0,0,0,0,63216,61042
36117,050,36,117,40380,464,,,Wayne County,93772,41057,93765,38767,93772,93765,0,0,0,0,0,0,0,0,93772,93765
36119,050,36,119,35620,408,,,Westchester County,949113,370821,923459,349445,949113,923459,0,0,0,0,0,0,0,0,949113,923459
36123,050,36,123,99999,999,,,Yates County,25348,13491,24621,12064,25348,24621,0,0,0,0,0,0,0,0,25348,24621
36073,050,36,073,40380,464,,,Orleans County,42883,18431,44171,17347,42883,44171,0,0,0,0,0,0,0,0,42883,44171
36103,050,36,103,35620,408,,,Suffolk County,1493350,569985,1419369,522323,1493350,1419369,0,0,0,0,0,0,0,0,1493350,1419369
36001,050,36,001,10580,104,,,Albany County,304204,137739,294565,129972,304204,294565,0,0,0,0,0,0,0,0,304204,294565
36033,050,36,033,31660,999,,,Franklin County,51599,25306,51134,23936,51599,51134,0,0,0,0,0,0,0,0,51599,51134
36035,050,36,035,24100,104,,,Fulton County,55531,28562,55073,27787,55531,55073,0,0,0,0,0,0,0,0,55531,55073
36041,050,36,041,99999,999,,,Hamilton County,4836,8694,5379,7965,4836,5379,0,0,0,0,0,0,0,0,4836,5379
36061,050,36,061,35620,408,,,New York County,1585873,847090,1537195,798144,1585873,1537195,0,0,0,0,0,0,0,0,1585873,1537195
36071,050,36,071,39100,408,,,Orange County,372813,137025,341367,122754,372813,341367,0,0,0,0,0,0,0,0,372813,341367
36095,050,36,095,10580,104,,,Schoharie County,32749,17231,31582,15915,32749,31582,0,0,0,0,0,0,0,0,32749,31582
36097,050,36,097,99999,999,,,Schuyler County,18343,9455,19224,9181,18343,19224,0,0,0,0,0,0,0,0,18343,19224
36107,050,36,107,13780,999,,,Tioga County,51125,22203,51784,21410,51125,51784,0,0,0,0,0,0,0,0,51125,51784
36111,050,36,111,28740,408,,,Ulster County,182493,83638,177749,77656,182493,177749,0,0,0,0,0,0,0,0,182493,177749
36121,050,36,121,99999,999,,,Wyoming County,42155,17970,43424,16940,42155,43424,0,0,0,0,0,0,0,0,42155,43424
18 changes: 18 additions & 0 deletions lab-04/json-parsing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import json

with open("ec2.json") as f:
content = f.read()

j = json.loads(content)
# print j['changed']
# print j['instance_ids']
#print j['instances'][0]
#print json.dumps(j,sort_keys=True,indent=4)

for k,v in j.items():
if k == 'instances':
for instance in v:
for k,v in instance.items():
if k == "dns_name":
print v

2 changes: 1 addition & 1 deletion lab-05/disk_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def check_disk(server,mount_point):
s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect('localhost', username='chandank', password='chandan',
s.connect('localhost', username='chandank', password='password',
allow_agent=False,look_for_keys=False)
err,out,ins = s.exec_command("df -h")
ss=out.read()
Expand Down
13 changes: 13 additions & 0 deletions lab-05/simple_os.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

import multiprocessing
import os



def print_os_info():
print multiprocessing.cpu_count()
print os.uname()[0]
print os.system("df -h")
print os.system("uptime")

print_os_info()
28 changes: 28 additions & 0 deletions lab-06/requests-example.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import requests


def count_yelp(text):
all_words = text.split()
yelp_count = all_words.count('Yelp')
return yelp_count

def replace_yelp(text):
return text.replace('yelp','google')


r = requests.get('http://wwww.yelp.com')
if r.status_code == 200:
print count_yelp(r.text)
#print replace_yelp(r.text)



# Assignment

# Load the yelp page count number of types yelp word is there and
# replace all occurance of yelp to google


# Load the file from http://censusdata.ire.org/36/all_050_in_36.P2.csv and find
# the max P002001

17 changes: 17 additions & 0 deletions lab-07/ec-create-instance.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import boto3


def create_instance():
ec2_resource = boto3.resource('ec2')
instances = ec2_resource.create_instances(ImageId='ami-49f0762d',
MinCount=1, MaxCount=1,InstanceType='t2.micro',
SecurityGroupIds=['ansible-node'],KeyName='ansible')
instance_ids = []
for instance in instances:
instance_ids.append(instance.id)
ec2_client = boto3.client('ec2')
waiter=ec2_client.get_waiter('instance_running')
waiter.wait(InstanceIds=instance_ids)
print ("Instance is Running now!")

create_instance()
14 changes: 14 additions & 0 deletions lab-07/ec2-client-list-instances.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import boto3

ec2_client = boto3.client('ec2')
response = ec2_client.describe_instances()
#print(response)

for k,v in response.items():
if k == 'Reservations':
for instance in v:
for i,vv in instance.items():
if i == 'Instances':
for ii in vv:
print ii['PublicDnsName']

Loading