[Tutor] Regarding Python api script

Alan Gauld alan.gauld at yahoo.co.uk
Tue Dec 4 03:36:50 EST 2018


On 04/12/2018 01:31, Ravi Kumar wrote:
> My output api calls in python is in xml so I want the output to be in the
> database

I'm still not 100% clear but I think you are saying
that your API currently returns XML when you call it
from Python. And you want to extract the data from
the XML and store it in a SQL Server database.
Is that correct?

If so the sequence of events is:

1) Connect to web site and retrieve the data (It
   sounds like you can already do this bit)
2) Parse the XML into usable data - you need
   etree (or another parser) to do that
3) Store the data in the database. You need
   a DBAPI module to do that. You will need
   to know some SQL.

Also, for step 3 you will need to either create
a new database or use an existing one. Do you
already have a target database? Or do you need
to design and create the table(s)? That may
require more SQL.

> So is there a way where I can alter my code to get
> api responses in json format in python and then
> later move the output to  the database

The answer to that lies in the API.
Assuming it is not under your control then you need
to read the API documentation to see if there is an
option to change the output to JSON. If not you are
stuck with whatever the API gives you.

Before we can give you any more help you will need
to share some code with us. What have you got
so far?

-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos




More information about the Tutor mailing list