in the main loop of the programwe prompt the user for twitter account name or "quitto exit the program if the user enters twitter accountwe retrieve the list of friends and statuses for that user and add each friend to the database if not already in the database if the friend is already in the listwe add to the friends field in the row in the database if the user presses enterwe look in the database for the next twitter account that we have not yet retrievedretrieve the friends and statuses for that accountadd them to the database or update themand increase their friends count once we retrieve the list of friends and statuseswe loop through all of the user items in the returned json and retrieve the screen_name for each user then we use the select statement to see if we already have stored this particular screen_name in the database and retrieve the friend count (friendsif the record exists countnew countold for in js['users'friend ['screen_name'print(friendcur execute('select friends from twitter where name limit '(friendtrycount cur fetchone()[ cur execute('update twitter set friends where name ?'(count+ friendcountold countold exceptcur execute('''insert into twitter (nameretrievedfriendsvalues ? )'''friendcountnew countnew print('new accounts=',countnew,revisited=',countoldconn commit(once the cursor executes the select statementwe must retrieve the rows we could do this with for statementbut since we are only retrieving one row (limit )we can use the fetchone(method to fetch the first (and onlyrow that is the result of the select operation since fetchone(returns the row as tuple (even though there is only one field)we take the first value from the tuple using to get the current friend count into the variable count if this retrieval is successfulwe use the sql update statement with where clause to add to the friends column for the row that matches the friend' account notice that there are two placeholders ( question marksin the sqland the second parameter to the execute(is two-element tuple that holds the values to be substituted into the sql in place of the question marks if the code in the try block failsit is probably because no record matched the where name clause on the select statement so in the except blockwe use the sql insert statement to add the friend' screen_name to the table with an indication that we have not yet retrieved the screen_name and set the friend count to one