List Info

Thread: Using a webservice as the datasource




Using a webservice as the datasource
user name
2006-08-31 06:29:00
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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users"; group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to django-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Using a webservice as the datasource
user name
2006-08-31 11:00:58
On 8/31/06, Iwan Memruk <iwan.memrukgmail.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.inercia
sensorial.com.br

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at http://gr
oups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

Using a webservice as the datasource
user name
2006-08-31 11:38:28
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.

On 8/31/06, Julio Nobrega <gmail.com">inertegmail.com> wrote:

On 8/31/06, Iwan Memruk <gmail.com">iwan.memrukgmail.com> wrote:
>; Hi,
>
&gt; 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?

 &nbsp;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).

&nbsp; 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():
 &nbsp; &nbsp;publish_date = datetime.fromtimestamp (float(news.PublishDate))
 ; &nbsp; thumbnail = news.Thumbnail
   ; if thumbnail is not None:
&nbsp; &nbsp; thumbnail = thumbnail['Url'].encode('utf-8')

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

  Then I grab some news from the DB:

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

&nbsp; 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Django users"; group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to django-users-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/django-users
-~----------~----~----~----~------~----~------~--~---

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )