using databases and sql print(friendcur execute('select id from people where name limit '(friend)tryfriend_id cur fetchone()[ countold countold exceptcur execute('''insert or ignore into people (nameretrievedvalues (? )'''(friend)conn commit(if cur rowcount ! print('error inserting account:'friendcontinue friend_id cur lastrowid countnew countnew cur execute('''insert or ignore into follows (from_idto_idvalues (??)'''(idfriend_id)print('new accounts='countnewrevisited='countoldprint('remaining'headers[' -rate-limit-remaining']conn commit(cur close(codethis program is starting to get bit complicatedbut it illustrates the patterns that we need to use when we are using integer keys to link tables the basic patterns are create tables with primary keys and constraints when we have logical key for person ( account nameand we need the id value for the persondepending on whether or not the person is already in the people table we either need to( look up the person in the people table and retrieve the id value for the person or ( add the person to the people table and get the id value for the newly added row insert the row that captures the "followsrelationship we will cover each of these in turn constraints in database tables as we design our table structureswe can tell the database system that we would like it to enforce few rules on us these rules help us from making mistakes and introducing incorrect data into our tables when we create our tablescur execute('''create table if not exists people (id integer primary keyname text uniqueretrieved integer)'''cur execute('''create table if not exists follows (from_id integerto_id integerunique(from_idto_id))'''