On 8/31/06, Iwan Memruk <[EMAIL PROTECTED]> 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~----------~----~----~----~------~----~------~--~---