title: Pulling XML from an API and saving to SQL database with Python
body: <p>Not a programmer- could use some help with understanding/best practice for bringing xml files into a SQL database. Here's some code and commentary to understand where I'm at now:</p>
  
  <pre><code>import pyodbc
  import requests
  import xml.etree.ElementTree as ET
  </code></pre>
  
  <p>Grabbing the XML file from the API:</p>
  
  <pre><code>requestURL = 'myURL.com'
  response = requests.get(requestURL)
  </code></pre>
  
  <p>This is where I start losing understanding. Mostly pieced together from various tutorials:</p>
  
  <pre><code>root = ET.fromstring(response.text)
  tree = ET.ElementTree(root)
  for child in root:
      print(child.attrib)
  </code></pre>
  
  <p>The output looks like this:</p>
  
  <pre><code>{'date': '1986-01-02', 'value': '0.90'}
  {'date': '1986-01-03', 'value': '0.99'}
  {'date': '1986-01-06', 'value': '1.07'}
  ...
  </code></pre>
  
  <p>Now I login into the database I want to write the information above into:</p>
  
  <pre><code>#establish connection with server
  conn = pyodbc.connect(driver='{SQL Server}', 
                    server=myServer, 
                    database=myDatabase,
                    user=myUsername,
                    password=myPassword)
  
  cursor = conn.cursor()
  cursor.execute('SELECT * FROM mySeries WHERE series_id = myID')
  
  for row in cursor:
      print(row)
  </code></pre>
  
  <p>Output looks like this:</p>
  
  <pre><code>(myID, '1986-01-02', Decimal('0.90'))
  (myID, '1986-01-03', Decimal('0.99'))
  (myID, '1986-01-06', Decimal('1.07'))
  ...
  </code></pre>
  
  <p>So the next step is checking the database to see what data points I'm missing (new data added daily) and appending data onto the end of the series. I'm pretty sure I should be using SQL in python to accomplish that, but I'm just a little confused on the best way to write the XML data into the database.</p>
  
  <p>Any help would be greatly appreciated.</p>