great thats helpful thanks
On 29 May 2008, at 10:29, Eric Abrahamsen wrote:
>
> Sure. Add instances of your Feed class in the admin. Then in your
> standalone script, the one that runs under your regular django
> environment, do this:
>
> from ubermicro.shows.models import Feed
>
> feeds = Feed.objects.all()
> for feed in feeds:
> f = feedparser.parse(feed.link)
> for item in f['entries']:
> # continue as below
>
>
> So you'll add Feeds in the admin, but your standalone script will add
> FeedItems automatically; you'll probably just leave those alone in the
> admin. Part of the standalone script should clear old FeedItems from
> the database when you don't need them anymore.
>
> E
>
> On May 29, 2008, at 5:08 PM, sebastian stephenson wrote:
>
>>
>> well umm. can I add urls though the admin interface?
>> On 28 May 2008, at 19:42, Eric Abrahamsen wrote:
>>
>>>
>>> What I was originally suggesting you do (which of course might not
>>> turn out to be the best solution) is use feedparser to read feed
>>> urls,
>>> and save those feeds into your database. That way, you wouldn't be
>>> using feedparser at all in your views, just regular database
>>> queries.
>>>
>>> If your models include Feed and FeedItem (FeedItem having a
>>> foreignkey
>>> to a Feed), then feed parser will do something like this:
>>>
>>> f = feedparser.parse('http://somefeed.url')
>>> feed = Feed.objects.get(link=f.feed.link) # f.feed provides
>>> information corresponding to one Feed instance
>>> for item in f['entries']: # entries are all the items under a
>>> particular feed
>>> it, created = FeedItem.objects.get_or_create(title=item.title,
>>> link=item.link, desc=item.description, date=item.date_parsed,
>>> id=item.id, feed=feed)
>>>
>>> Repeat the above for every url in your list of feed urls. Note: this
>>> code goes in your standalone script running on a cron job, NOT in
>>> your
>>> views or whatever other normal part of your django code base. That
>>> will put RSS feed items into your database, your views.py pulls them
>>> out again as per normal django methods:
>>>
>>> feed = Feed.objects.get(link=somelinkvalue)
>>> items = feed.feeditem_set.all()
>>> return render_to_response(template, {'items':items})
>>>
>>> That's how it ought it work, in my opinion. Note that it's late
>>> here,
>>> and I've been drinking, so there may be some inaccuracies in the
>>> above. I concur with the general consensus, that you need to start
>>> with some simple CGI scripts and python basics, and move up from
>>> there. That said, good luck!
>>>
>>> E
>>>
>>>
>>> On May 28, 2008, at 11:45 PM, sebey wrote:
>>>
>>>>
>>>> please much suggestions thank you
>>>>
>>>> On May 28, 4:37 pm, sebastian stephenson <[EMAIL PROTECTED]> wrote:
>>>>> great finally some help thank you so much!
>>>>> On 28 May 2008, at 15:20, Rajesh Dhawan wrote:
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>> On May 28, 6:30 am, sebey <[EMAIL PROTECTED]> wrote:
>>>>>>> from django.http import HttpResponse
>>>>>>> import feedparser
>>>>>>> from ubermicro.shows.models import show
>>>>>
>>>>>>> def show_page(request):
>>>>>>> """this is where we take what we need form the rss feeds in
>>>>>>> the
>>>>>>> data base"""
>>>>>>> query = show.objects.filter(show_feed__contains="http://")
>>>>>>> podcast = feedparser.parse(query)
>>>>>
>>>>>> It seems that you are making feedparser parse an instance of a
>>>>>> Django
>>>>>> ORM query. I think what you want to do is to make it parse a URL.
>>>>>> May
>>>>>> be something like this:
>>>>>
>>>>>> for q in query:
>>>>>> podcast = feedparser.parse(q.show_feed)
>>>>>> if podcast.entries:
>>>>>> show_latest_title = podcast.entries[0].title
>>>>>
>>>>>> This will do it for all objects in your query. So you will
>>>>>> have to
>>>>>> collect that list of titles etc. in a collection of some kind
>>>>>> (list,
>>>>>> dict, etc.) and pass it on to your template.
>>>>>
>>>>>>> #show_about = podcast.feed.description
>>>>>>> show_latest_title = podcast.entries[0].title
>>>>>
>>>>>> The above statement assumes that there is at least one entry in
>>>>>> the
>>>>>> feed. That may not be always true. So, you should consider
>>>>>> testing
>>>>>> that first. Something like:
>>>>>
>>>>>> if podcast.entries:
>>>>>> show_latest_title = podcast.entries[0].title
>>>>>
>>>>>>> #show_latest = podcast.entries[0].description
>>>>>
>>>>>>> return HttpResponse(show_latest_title)
>>>>>
>>>>>>> this code is what I think its doing is that I am grabing the rss
>>>>>>> url
>>>>>>> then using feedparser (http://www.feedparser.org) to get rss
>>>>>>> element
>>>>>>> such as <description> and such but every time I try to do this I
>>>>>>> get
>>>>>>> this error
>>>>>
>>>>>>> Traceback (most recent call last):
>>>>>>> File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
>>>>>>> python2.5/
>>>>>>> site-packages/django/core/handlers/base.py" in get_response
>>>>>>> 77. response = callback(request, *callback_args,
>>>>>>> **callback_kwargs)
>>>>>>> File "/Users/sebey/Sites/ubermicro/../ubermicro/shows/views.py"
>>>>>>> in
>>>>>>> show_page
>>>>>>> 10. show_latest_title = podcast.entries[0].title
>>>>>
>>>>>>> IndexError at /shows/
>>>>>>> list index out of range
>>>>>>> I am to django programing web dev etc. but I guess that the
>>>>>>> query
>>>>>>> I am
>>>>>>> useing is not correct so I what should I do thanks
>>>>>
>>>>>> -Rajesh
>>>>>
>>>>> see ya
>>>>>
>>>>> sebey
>>>>>
>>>
>>>
>>>>
>>
>> see ya
>>
>> sebey
>>
>>
>>
>>>
>
>
> >
see ya
sebey
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---