CSE project step - version 2

import urllib.request
import csv
import time

# Get a file-like object for a site.
def cse_link():
try:
f = urllib.request.urlopen("http://www.cse.lk/listedcompanies/overview.htm?d-16544-e=1&6578706f7274=1")
# NOTE: At the interactive Python prompt, you may be prompted for a username
#http://www.cse.lk/listedcompanies/overview.htm?d-16544-e=1&6578706f7274=1
# NOTE: and password here.
# Read from the object, storing the page's contents in 's'.
# Read data decoded to utf-8
s = f.read().decode('utf-8')

# Save 's' data to log.csv file
logfile=open("log.csv",'w')
# log.csv file size
logfile.write(s)

size =logfile.tell()
if size==0:
print ("Nothing found to display"
"If the market status is CLOSED" )

logfile.close()
except:
print ("Network failed please re-check after few minuits")


def csv_read():
" Open save file from above function"
filename = "log.csv"
reader = csv.reader(open(filename, "rt"))
line_to_read=0

# Comapny Status
positive=[]
negitive=[]
nothing=[]

#Value of gain
change_c=[]
# Price changes
price_c=[]

for r in reader:
" Read first value of the file "
Name_of_Company =r[0]
" Read coloum of Price change in Rs"
price_index=r[9]
" Read Coloum of price change in % "
gain=r[10]



"*********************************************************************************"
"Read contributor status (-),'',(+) "

change_symbol=r[11]

if change_symbol=='(-)':
line_to_read +=1
negitive.append(Name_of_Company)

if change_symbol=='(+)':
line_to_read +=1
positive.append(Name_of_Company)
change_c.append(gain)
print (price_index)
if price_index.find(',')>0:
#print (price_index.find(','))
first_c=price_index[0]
second_c=eval(first_c)
#print (second_c)
third_c=eval(price_index[2:])
#print (third_c)
for i in range(second_c):
fixed_val=+second_c*1000
now_val=fixed_val + third_c
print (now_val)
price_c.append(now_val)

else:

price_c.append(price_index)

if change_symbol=='':
line_to_read +=1
nothing.append(Name_of_Company)

"Reading Status completed"
" ********************************************************************************* "
" Number of Company involved for trading"
total=len(positive) + len(negitive) + len(nothing)
Positive_Cont=int(len(positive)/total*100)
print ("\nDaily Share Trading companies", total)
"**************************************************************************************"
" To read Max and Min change in percerntage-wise (%)"

Max_v=max(change_c, key=float)
Min_v=min(change_c, key=float)
"To get Maximum % changes"
name_company=change_c.index(Max_v)
name_company_min=change_c.index(Min_v)


">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"

" To read Max and Min change in price-wise"
try:

Max_price=max(price_c, key=float)
Min_price=min(price_c, key=float)
except:
print (" Version Upgration required")

try:
name_company_price_max=price_c.index(Max_price)
name_company_price_min=price_c.index(Min_price)
except:
print ("Version upgrading required")


"Analys of Positive contributors status"

print ("_______________________________________________________")

print ("\nNo's of Positive |contributors",len(positive), "as " ,Positive_Cont,"%" )

print (" \n\tMaximum Gain companies : ",positive[name_company], "at", Max_v,"%")


print ("\n\tMinimum Gain companies : ",positive[name_company_min],"at",Min_v,"%")
print ("\n\tMaximum Price change companies : ",positive[name_company_price_max],
"at Rs",Max_price ," &",change_c[name_company_price_max])
print ("_________________________________________________________")
print ("\nNo's of Negitive |contributors",len(negitive), " as %",
int(len(negitive)/total*100))
print ("_________________________________________________________")
print ("\nNo's of No|contributors",len(nothing), " as % " ,
int(len(nothing)/total*100))


def check(t):
while True:

cse_link()
csv_read()
print (" \n Next check will be after :",t,"seconds\n\t")
time.sleep(t)
continue