fetching data from a file

def query_reviews():
    f = open("/home/tes/workspace/tests/src/1.xls", "r")
    c=f.readlines()
    print c[0]
    print c[1]
    nodeid=""
    name=""
    parent_id=""
    text=""
    paa=""
    x=1
    y=0
    z=0
    id=1
    while(x<len(c)):
        y=0
        while(y<len(c[x])):
            if(c[x][y]=='"'):
                z=y+1
                while(z<len(c[x])):
                    if(c[x][z]=='"'):
                        for kk in range(y+1,z):
                            text+=c[x][kk]
                        y=z+1
                        z=len(c[x])-1
                        
                    
                    if(nodeid=='' and z==len(c[x])-1):
                        nodeid=text
                        text=""
                        
                    elif(name=="" and z==len(c[x])-1 and nodeid!=''):
                        name=text
                        text=""
                        
                    elif(parent_id=="" and z==len(c[x])-1 and nodeid!='' and name!=''):
                        parent_id=text
                        
                        for kk in range((parent_id.find('>')+1), parent_id.find('</a>')):
                            paa+=parent_id[kk]
                        parent_id=paa
                        paa=""
                        print nodeid, name, parent_id
                        nextag_node_id=nodeid
                        is_live='YES'
                        okies={'id':'id','name':'name', 'parent_id_id':'parent_id', 'is_live':'is_live', 'nextag_node_id':'nextag_node_id'}
                        sql = ('''insert into categories(id, name, parent_id, is_live, nextag_node_id, last_modified) values (%(id)s, %(name)s, %(parent_id)s, %(is_live)s, %(nextag_node_id)s, %(last_modified)s)''', okies)
                        db.wize.execute(sql).scalar()
                        id+=1 
                        nodeid=""
                        name=""
                        parent_id=""
                        text=""
                        y=len(c[x])-1
                    else:
                        asd=0
                    z=z+1    
            y=y+1       
        x=x+1   

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: