<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="#CountryList()" data-toc-modified-id="CountryList()-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>CountryList()</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:  CountryList()
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="#CountryList()" data-toc-modified-id="CountryList()-5"><span class="toc-item-num">5&nbsp;&nbsp;</span>CountryList()</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_country_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 `CountryList` call: http://ws.eoddata.com/data.asmx?op=CountryList
# 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-04-02
Date of Change    Change Notes
--------------    ----------------------------------------------------------------
2017-04-02        Initial draft
Setup
End of explanation
session = r.Session()
call = 'CountryList'
kwargs = {'Token': token,}
pattern = ".//{%s}CountryBase"
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: CountryList()
Web service call
End of explanation
elements = root.findall(pattern %(ns))
Explanation: Gather elements
End of explanation
countries = sorted((element.get('Code'), element.get('Name')) for element in elements)
countries
Explanation: Get data
End of explanation
with open('../../data/countries.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 CountryList(session, token):
    call = 'CountryList'
    kwargs = {'Token': token,}
    pattern = ".//{%s}CountryBase"
    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'), element.get('Name')) for element in elements)
Explanation: Helper function
End of explanation
session = r.session()
countries = CountryList(session, token)
session.close()
countries[:10]
Explanation: Usage
End of explanation
# pandas dataframe is returned
df = eoddata.country_list()
df.head()
Explanation: Client function
End of explanation
<END_TASK>