List Info

Thread: noob question - Feedparser / Template_Utils / time filters




noob question - Feedparser / Template_Utils / time filters
user name
2007-12-23 10:19:57
I am using template_utils.feeds to parse and import feeds.

On the template it looks like this:

{% endcache %}
{% cache 5 sample_feed %}
<div class="section">
<h2>Feed</h2>
{% parse_feed "http://example.com/
feed.rss" as sample_feed %}

<ul>
{% for entry in sample_feed.entries %}
<li>{{ entry.title}}</li>
{{ entry.date }}
{% endfor %}
</ul>
</div>
{% endcache %}

That all works - (renders as Fri, 21 Dec 2007 21:22:49 +0000
) but I
can not apply any Django time filters (date, timesince,
naturalday) to
the {{entry.date }} variable. I would guess it is not
recognizing the
date as a 'date' but i can not find in the docs how to work
this.

The error is:    AttributeError at / 'unicode' object has no
attribute
'year'

thanks

Damon
--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: noob question - Feedparser / Template_Utils / time filters
user name
2007-12-23 10:34:47
On Dec 23, 2007 10:19 AM, damon.kiesowgmail.com <damonnh.com> wrote:
> That all works - (renders as Fri, 21 Dec 2007 21:22:49
+0000 ) but I
> can not apply any Django time filters (date, timesince,
naturalday) to
> the {{entry.date }} variable. I would guess it is not
recognizing the
> date as a 'date' but i can not find in the docs how to
work this.


You'll be wanting to check out the feedparser
documentation[1] to find
out what the attributes mean; in this case, for example, the
'date'
attribute is the actual literal string which appeared inside
the feed,
and so logically can't be reformatted using date operations
because
it's not a date object. You probably want the 'date_parsed'
attribute
instead, which returns a tuple suitable for constructing
various type
of date and time objects.


[1] http://feedparser.org/doc
s/


-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: noob question - Feedparser / Template_Utils / time filters
user name
2007-12-23 11:06:11
James -

Thanks, I had worked through the date_parsed items - but was
getting
the same error. Maybe I was missing some other piece at that
point. i
will give it another shot.

Using modified_parsed gave me this date (2007, 12, 21, 21,
22, 49, 4,
355, 0)  but threw an error when applying a filter:
AttributeError
at / 'time.struct_time' object has no attribute 'year'

I think I am just not familiar enough with Django's handling
of
datetime to see what I am missing here.

Damon

On Dec 23, 11:34 am, "James Bennett"
<ubernost...gmail.com> wrote:
> On Dec 23, 2007 10:19 AM, damon.kie...gmail.com
<da...nh.com> wrote:
>
> > That all works - (renders as Fri, 21 Dec 2007
21:22:49 +0000 ) but I
> > can not apply any Django time filters (date,
timesince, naturalday) to
> > the {{entry.date }} variable. I would guess it is
not recognizing the
> > date as a 'date' but i can not find in the docs
how to work this.
>
> You'll be wanting to check out the feedparser
documentation[1] to find
> out what the attributes mean; in this case, for
example, the 'date'
> attribute is the actual literal string which appeared
inside the feed,
> and so logically can't be reformatted using date
operations because
> it's not a date object. You probably want the
'date_parsed' attribute
> instead, which returns a tuple suitable for
constructing various type
> of date and time objects.
>
> [1]http://feedparser.org/doc
s/
>
> --
> "Bureaucrat Conrad, you are technically correct --
the best kind of correct."
--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: noob question - Feedparser / Template_Utils / time filters
user name
2007-12-23 13:25:08
On Dec 23, 2007 11:06 AM, damon.kiesowgmail.com <damonnh.com> wrote:
> Using modified_parsed gave me this date (2007, 12, 21,
21, 22, 49, 4,
> 355, 0)  but threw an error when applying a filter:
AttributeError
> at / 'time.struct_time' object has no attribute 'year'
>
> I think I am just not familiar enough with Django's
handling of
> datetime to see what I am missing here.

This isn't a Django thing, it's a Python thing. Unless and
until you
have something of type 'datetime.date' or
'datetime.datetime', you're
not going to be able to treat it like you do. The feed
parser is
giving you a nine-element time tuple because that's a nice
baseline
for a Python object representation -- you can feed it into
all sorts
of other standard things to get other types of objects or do
other
sorts of calculations. So go have a look at that tuple, and
at the
docs for Python's standard 'datetime' and 'time' modules,
and you
should get a feel for what you can do with it.


-- 
"Bureaucrat Conrad, you are technically correct -- the
best kind of correct."

--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: noob question - Feedparser / Template_Utils / time filters
user name
2007-12-23 14:38:03
James thanks. I have been reviewing the Python docs but
there are too
many moving parts for me at this point. I assume this can
be
accomplished within the feeds.py module fairly simply but I
am just
beginning to learn the code. I will give it a shot once I
have a bit
more experience with it.

Damon

On Dec 23, 2:25 pm, "James Bennett"
<ubernost...gmail.com> wrote:
> On Dec 23, 2007 11:06 AM, damon.kie...gmail.com
<da...nh.com> wrote:
>
> > Using modified_parsed gave me this date (2007, 12,
21, 21, 22, 49, 4,
> > 355, 0)  but threw an error when applying a
filter: AttributeError
> > at / 'time.struct_time' object has no attribute
'year'
>
> > I think I am just not familiar enough with
Django's handling of
> > datetime to see what I am missing here.
>
> This isn't a Django thing, it's a Python thing. Unless
and until you
> have something of type 'datetime.date' or
'datetime.datetime', you're
> not going to be able to treat it like you do. The feed
parser is
> giving you a nine-element time tuple because that's a
nice baseline
> for a Python object representation -- you can feed it
into all sorts
> of other standard things to get other types of objects
or do other
> sorts of calculations. So go have a look at that tuple,
and at the
> docs for Python's standard 'datetime' and 'time'
modules, and you
> should get a feel for what you can do with it.
>
> --
> "Bureaucrat Conrad, you are technically correct --
the best kind of correct."
--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: noob question - Feedparser / Template_Utils / time filters
user name
2007-12-23 20:02:04
Gotta say - a week into this project - I am loving Django.

Wrote a small custom filter:

register.filter ("fromdatetuple")
def fromdatetuple(value):
		return
datetime.datetime.fromtimestamp(time.mktime(value))
fromdatetuple.is_safe = True

And added this to the template:

{{ entry.date_parsed|fromdatetuple|timesince }} ago

And it returns:

"1 day, 22 hours ago"

On Dec 23, 3:38 pm, "damon.kie...gmail.com"
<da...nh.com> wrote:
> James thanks. I have been reviewing the Python docs but
there are too
> many moving parts for me at this point. I assume this
can be
> accomplished within the feeds.py module fairly simply
but I am just
> beginning to learn the code. I will give it a shot once
I have a bit
> more experience with it.
>
> Damon
>
> On Dec 23, 2:25 pm, "James Bennett"
<ubernost...gmail.com> wrote:
>
> > On Dec 23, 2007 11:06 AM, damon.kie...gmail.com
<da...nh.com> wrote:
>
> > > Using modified_parsed gave me this date
(2007, 12, 21, 21, 22, 49, 4,
> > > 355, 0)  but threw an error when applying a
filter: AttributeError
> > > at / 'time.struct_time' object has no
attribute 'year'
>
> > > I think I am just not familiar enough with
Django's handling of
> > > datetime to see what I am missing here.
>
> > This isn't a Django thing, it's a Python thing.
Unless and until you
> > have something of type 'datetime.date' or
'datetime.datetime', you're
> > not going to be able to treat it like you do. The
feed parser is
> > giving you a nine-element time tuple because
that's a nice baseline
> > for a Python object representation -- you can feed
it into all sorts
> > of other standard things to get other types of
objects or do other
> > sorts of calculations. So go have a look at that
tuple, and at the
> > docs for Python's standard 'datetime' and 'time'
modules, and you
> > should get a feel for what you can do with it.
>
> > --
> > "Bureaucrat Conrad, you are technically
correct -- the best kind of correct.""
--~--~---------~--~----~------------~-------~--~----~
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 htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-6]

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