<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Table of Contents
<p><div class="lev1 toc-item"><a href="#Summary" data-toc-modified-id="Summary-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Summary</a></div><div class="lev1 toc-item"><a href="#Version-Control" data-toc-modified-id="Version-Control-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Version Control</a></div><div class="lev1 toc-item"><a href="#Change-Log" data-toc-modified-id="Change-Log-3"><span class="toc-item-num">3&nbsp;&nbsp;</span>Change Log</a></div><div class="lev1 toc-item"><a href="#Setup" data-toc-modified-id="Setup-4"><span class="toc-item-num">4&nbsp;&nbsp;</span>Setup</a></div><div class="lev1 toc-item"><a href="#ExchangeList()" data-toc-modified-id="ExchangeList()-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>ExchangeList()</a></div><div class="lev2 toc-item"><a href="#Web-service-call" data-toc-modified-id="Web-service-call-51"><span class="toc-item-num">5.1&nbsp;&nbsp;</span>Web service call</a></div><div class="lev3 toc-item"><a href="#Gather-elements" data-toc-modified-id="Gather-elements-511"><span class="toc-item-num">5.1.1&nbsp;&nbsp;</span>Gather elements</a></div><div class="lev3 toc-item"><a href="#Get-data" data-toc-modified-id="Get-data-512"><span class="toc-item-num">5.1.2&nbsp;&nbsp;</span>Get data</a></div><div class="lev3 toc-item"><a href="#Save-to-file" data-toc-modified-id="Save-to-file-513"><span class="toc-item-num">5.1.3&nbsp;&nbsp;</span>Save to file</a></div><div class="lev3 toc-item"><a href="#Data-inspection" data-toc-modified-id="Data-inspection-514"><span class="toc-item-num">5.1.4&nbsp;&nbsp;</span>Data inspection</a></div><div class="lev2 toc-item"><a href="#Helper-function" data-toc-modified-id="Helper-function-52"><span class="toc-item-num">5.2&nbsp;&nbsp;</span>Helper function</a></div><div class="lev3 toc-item"><a href="#Usage" data-toc-modified-id="Usage-521"><span class="toc-item-num">5.2.1&nbsp;&nbsp;</span>Usage</a></div><div class="lev2 toc-item"><a href="#Client-function" data-toc-modified-id="Client-function-53"><span class="toc-item-num">5.3&nbsp;&nbsp;</span>Client function</a></div>
# Summary
Part of the blog series related to making web service calls to Eoddata.com. Overview of the web service can be found [here](http
Step1:  Change Log
Date Created
Step2:  ExchangeList()
Web service call
Step3:  Gather elements
Step4:  Get data
Step5:  Save to file
Step6:  Data inspection
Step7:  Helper function
Step8:  Usage
Step9:  Client function
<ASSISTANT_TASK:>
Python Code:
%run ../../code/version_check.py
Explanation: Table of Contents
<p><div class="lev1 toc-item"><a href="#Summary" data-toc-modified-id="Summary-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Summary</a></div><div class="lev1 toc-item"><a href="#Version-Control" data-toc-modified-id="Version-Control-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Version Control</a></div><div class="lev1 toc-item"><a href="#Change-Log" data-toc-modified-id="Change-Log-3"><span class="toc-item-num">3&nbsp;&nbsp;</span>Change Log</a></div><div class="lev1 toc-item"><a href="#Setup" data-toc-modified-id="Setup-4"><span class="toc-item-num">4&nbsp;&nbsp;</span>Setup</a></div><div class="lev1 toc-item"><a href="#ExchangeList()" data-toc-modified-id="ExchangeList()-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>ExchangeList()</a></div><div class="lev2 toc-item"><a href="#Web-service-call" data-toc-modified-id="Web-service-call-51"><span class="toc-item-num">5.1&nbsp;&nbsp;</span>Web service call</a></div><div class="lev3 toc-item"><a href="#Gather-elements" data-toc-modified-id="Gather-elements-511"><span class="toc-item-num">5.1.1&nbsp;&nbsp;</span>Gather elements</a></div><div class="lev3 toc-item"><a href="#Get-data" data-toc-modified-id="Get-data-512"><span class="toc-item-num">5.1.2&nbsp;&nbsp;</span>Get data</a></div><div class="lev3 toc-item"><a href="#Save-to-file" data-toc-modified-id="Save-to-file-513"><span class="toc-item-num">5.1.3&nbsp;&nbsp;</span>Save to file</a></div><div class="lev3 toc-item"><a href="#Data-inspection" data-toc-modified-id="Data-inspection-514"><span class="toc-item-num">5.1.4&nbsp;&nbsp;</span>Data inspection</a></div><div class="lev2 toc-item"><a href="#Helper-function" data-toc-modified-id="Helper-function-52"><span class="toc-item-num">5.2&nbsp;&nbsp;</span>Helper function</a></div><div class="lev3 toc-item"><a href="#Usage" data-toc-modified-id="Usage-521"><span class="toc-item-num">5.2.1&nbsp;&nbsp;</span>Usage</a></div><div class="lev2 toc-item"><a href="#Client-function" data-toc-modified-id="Client-function-53"><span class="toc-item-num">5.3&nbsp;&nbsp;</span>Client function</a></div>
# Summary
Part of the blog series related to making web service calls to Eoddata.com. Overview of the web service can be found [here](http://ws.eoddata.com/data.asmx).
 * ** View the master post of this series to build a secure credentials file.** It is used in all posts related to this series.
 * Download this blog post as a [jupyter notebook](https://adriantorrie.github.io/downloads/notebooks/eoddata/eoddata_web_service_calls_exchange_list.ipynb)
 * Download the [class definition file](https://adriantorrie.github.io/downloads/code/eoddata.py) for an easy to use client, which is demonstrated below
 * This post covers the `ExchangeList` call: http://ws.eoddata.com/data.asmx?op=ExchangeList
# Version Control
End of explanation
%run ../../code/eoddata.py
import pandas as pd
import requests as r
ws = 'http://ws.eoddata.com/data.asmx'
ns='http://ws.eoddata.com/Data'
with (Client()) as eoddata:
    token = eoddata.get_token()
Explanation: Change Log
Date Created: 2017-03-25
Date of Change    Change Notes
--------------    ----------------------------------------------------------------
2017-03-25        Initial draft
2017-04-02        - Changed any references for `get_exchange_list()` to `exchange_list()`
                  - Client class function returns data in fixed order now
Setup
End of explanation
session = r.Session()
call = 'ExchangeList'
kwargs = {'Token': token,}
pattern = ".//{%s}EXCHANGE"
url = '/'.join((ws, call))
response = session.get(url, params=kwargs, stream=True)
if response.status_code == 200:
    root = etree.parse(response.raw).getroot()
    
session.close()
Explanation: ExchangeList()
Web service call
End of explanation
elements = root.findall(pattern %(ns))
Explanation: Gather elements
End of explanation
exchanges = sorted(element.get('Code') for element in elements)
exchanges
Explanation: Get data
End of explanation
with open('../../data/exchanges.csv', 'w') as f:
    for element in elements:
        f.write('"%s"\n' % '","'.join(element.attrib.values()))
Explanation: Save to file
End of explanation
for item in root.items():
    print (item)
for element in root.iter():
    print(element.attrib)
Explanation: Data inspection
End of explanation
def ExchangeList(session, token):
    call = 'ExchangeList'
    kwargs = {'Token': token,}
    pattern = ".//{%s}EXCHANGE"
    url = '/'.join((ws, call))
    response = session.get(url, params=kwargs, stream=True)
    if response.status_code == 200:
        root = etree.parse(response.raw).getroot()
        
    return sorted(element.get('Code') for element in elements)
Explanation: Helper function
End of explanation
session = r.session()
exchanges = ExchangeList(session, token)
exchanges
session.close()
Explanation: Usage
End of explanation
# pandas dataframe is returned
df = eoddata.exchange_list()
df.head()
Explanation: Client function
End of explanation
<END_TASK>