Using a webservice as the datasource

7 views
Skip to first unread message

Iwan Memruk

unread,
Aug 31, 2006, 2:29:00 AM8/31/06
to django...@googlegroups.com
Hi,

I'm currently evaluating various web frameworks for my future project. I need an admin interface for a distributed system, in which the data is going to be fetched not from an SQL source but from a SOAP webservice or perhaps a couple of them. Has anyone got any experience of doing that with Django? How would you estimate the effort necessary for adapting Django to use webservices as the data source? What would be your approach?

--
Thanks,
Iwan

Julio Nobrega

unread,
Aug 31, 2006, 7:00:58 AM8/31/06
to django...@googlegroups.com
On 8/31/06, Iwan Memruk <iwan....@gmail.com> wrote:
> Hi,

>
> Has anyone got any experience of doing that with Django? How
> would you estimate the effort necessary for adapting Django to use
> webservices as the data source? What would be your approach?

I am using Django with the Yahoo API. There's even a python module
to make web searches and other Yahoo stuff (*verrry* easy to use).

What I did is create a model replicating every field from the
returned data, then my view requests something and I obj.save() it,
making it available on the admin interface. Something like (this is
for Yahoo news search):

from yahoo.search.news import NewsSearch
srch = NewsSearch('yahoo_app_id', query = 'something', results = 50,
language = 'en')

for news in srch.parse_results():
publish_date = datetime.fromtimestamp(float(news.PublishDate))
thumbnail = news.Thumbnail
if thumbnail is not None:
thumbnail = thumbnail['Url'].encode('utf-8')

try:
obj = News.objects.get(slug = slugify(news.Title)[0:50].encode('utf-8'))
except News.DoesNotExist:
obj = News(slug = slugify(news.Title)[0:50].encode('utf-8'))
obj.title = news.Title[0:125].encode('utf-8')
obj.summary = news.Summary.encode('utf-8')
obj.click_url = news.ClickUrl.encode('utf-8')
obj.news_source = news.NewsSource.encode('utf-8')
obj.news_source_url = news.NewsSourceUrl.encode('utf-8')
obj.language = news.Language.encode('utf-8')
obj.publish_date = publish_date.__str__()
obj.thumbnail = thumbnail
obj.save()

Then I grab some news from the DB:

news_list = News.objects.all().order_by('?')[0:3]

The encode('utf-8') was necessary because Mysql was complaining
about the data, don't know if it'll happen with your DB/server
configuration.

--
Julio Nobrega - http://www.inerciasensorial.com.br

Iwan Memruk

unread,
Aug 31, 2006, 7:38:28 AM8/31/06
to django...@googlegroups.com
Thanks Julio!

What I thought of though was a Django application completely without own DB.
It would fetch the data using one set of WS operations, and save them back using another set of operations.
These are not some public web services, but application-specific ones, which have their own WSDLs and are deployed as a part of the application.
Perhaps that is a bit out of scope for Django, but I still have hope that it is possible to tweak Django a bit to be able to reuse all the nice Django features which are decoupled from the datasource.

        obj.language = news.Language.encode ('utf-8')

        obj.publish_date = publish_date.__str__()
        obj.thumbnail = thumbnail
        obj.save()

  Then I grab some news from the DB:

news_list = News.objects.all().order_by('?')[0:3]

  The encode('utf-8') was necessary because Mysql was complaining
about the data, don't know if it'll happen with your DB/server
configuration.

--
Julio Nobrega - http://www.inerciasensorial.com.br




--
Iwan
Reply all
Reply to author
Forward
0 new messages