title: Trying to collect API data and send to local mysql
body: <p>I cannot get this script that i created to work.
  it needs to collect API data (returns a JSON)
  and i want to save specific data to MYSQL</p>
  
  <p>played around with the code and didnt get it to work...
  various "expected an indented block" errors</p>
  
  <pre><code>from __future__ import print_function
  import requests
  import re
  import MySQLdb
  import json
  
  data = requests.get('https://newsapi.org/v2/top-headlines?country=us&amp;apiKey=xxxxxxxxxxxxxxxxxxxx')
  
  HOST = "localhost"
  USER = "root"
  PASSWD = "user"
  DATABASE = "something"
  
  def store_data(articles, source, auther, title, description, url, timestamp, content):
          db = MySQLdb.connect(host = HOST, user = USER, passwd = PASSWD, db = DATABASE, charset = "utf8")
  cursor = db.cursor()
  insert_query = MySQLdb.escape_string("INSERT INTO table (articles, source, auther, title, description, url, timestamp, content) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)")
  cursor.execute(insert_query, (articles, source, auther, title, description, url, timestamp, content))
  db.commit()
  cursor.close()
  db.close()
  return
  
          # db = MySQLdb.connect(host = HOST, user = USER, passwd = PASSWD, db = DATABASE, charset = "utf8")# cursor = db.cursor()
  
  def on_data(self, data): #This is the meat of the script...it connects to your mongoDB and stores the tweet
  try:
  datajson = json.loads(data) #  grab the wanted data from the Tweet
  articles = datajson['articles']
  source = datajson['articles']['source']['name']
  auther = datajson['articles']['auther']
  title = datajson['articles']['title']
  description = datajson['articles']['description']
  url = datajson['articles']['url']
  timestamp = parser.parse(datajson['articles']['publishedAt'])
  content = datajson['articles']['content']
  
  # insert the data into the MySQL database
  store_data(articles, source, auther, title, description, url, timestamp, content)
  except Exception as e:
          print(e)
  </code></pre>
  
  <p>i expect the output to be stored into a mysql table... but i get error while trying to run the script.
  Also i need to make it run endlessly untill ill kill the process/session....</p>