In [ ]:
from textblob import TextBlob
import MySQLdb
import datetime
import time
from time import mktime
from datetime import datetime
import requests
url = (''
response = requests.get(url).json()

db = MySQLdb.connect(host='localhost',user='username',passwd='password', db='db_name')
mycursor = db.cursor()

#Empty the table of old content
mycursor.execute('''TRUNCATE TABLE no.top_news_api_tech''')

restrict = ['HIV', 'surgery', 'battered', 'thugs', 'death', 'killing', 'hit by car', 'body', 'arranged marriage', 'sexual abuse', 'self harm', 'bullying', 'severed', 'AIDS', 'bomb', 'dies', 'bombs', 'dead', 'war', 'klux', 'torture', 'slaying', 'slayed', 'slay', 'deaths', 'died', 'death', 'murder', 'sad', 'depression', 'depressed', 'anxiety', 'murdered', 'genocide', 'acid', 'attack', 'attacked', 'arson', 'fire', 'abuse', 'abused', 'victim', 'suffer', 'suffered', 'racist', 'racism', 'threat', 'threatened', 'threatening', 'attack', 'attacker', 'attacked', 'shot', 'shooting', 'killed', 'rape', 'raped', 'stab', 'stabbed', 'stabbing', 'suicide', 'abuse', 'abused', 'abuser', 'pain', 'hurt', 'injured', 'injury', 'suffer', 'suffering', 'suffered', 'bomb', 'explosion', 'hospital', 'fight']

#Populate the table with new content 
for i in response['articles']:
    if i['description'] is not None:
        if not any(res in i['title'] for res in restrict) and not any(res in i['description'] for res in restrict):
                   sentiment = round(TextBlob(i['title']+ ' ' + i['description']).sentiment.polarity, 2)
                   sql = "INSERT INTO top_news_api_tech VALUES (%s, %s, %s, %s, %s, %s)"
                   mycursor.execute(sql, (i['title'], i['url'], i['description'], i['urlToImage'], i['source']['name'], str(sentiment)))
                    print('stuff gone wrong')