Re: modify date in django twitter app

2010-03-09 Thread het.oosten
I figured it out finally.

For anybody who is interested. I have this setup for showing multiple
tweets:

settings.py:
from django.conf.global_settings import TEMPLATE_CONTEXT_PROCESSORS

TEMPLATE_CONTEXT_PROCESSORS = TEMPLATE_CONTEXT_PROCESSORS + (
"wieskamp.verkoop.context_processors.latest_tweet",
)

TWITTER_USER = "username"
TWITTER_TIMEOUT = 3600

This context_processor:
import datetime
import time
from django.conf import settings
from django.core.cache import cache
import twitter

def latest_tweet( request ):
tweet = cache.get( 'tweet' )

if tweet:
return {"tweet": tweet}

tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER,
count=3 )
for s in tweet:
s.date =
datetime.datetime(*(time.strptime( s.created_at, "%a %b %d %H:%M:%S
+ %Y" )[0:6]))
cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT )

return {"tweet": tweet}

And this in my template:
{% if tweet %}
{% for x in tweet %}
{{ x.text|urlize}} 
{{ x.date|date:"d/m/Y" }}
{% endfor %}
{% endif %}

Thanks for the help and hints :-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-08 Thread Nick
I think this may help

http://www.magpiebrain.com/2005/08/21/formatting-dates-with-django/

try using strftime and formatting from there.

On Mar 8, 3:16 pm, "het.oosten"  wrote:
> I forgot to mention that my desired output of the date is:
> 2010-02-22 20:46:03
>
> On 8 mrt, 22:13, "het.oosten"  wrote:
>
> > I am getting somewhere now:
>
> > import datetime
> > import time
> > import twitter
>
> > tweet  = twitter.Api().GetUserTimeline('username', count=3)
> > for s in tweet:
> >         s.date = datetime.datetime(*(time.strptime( s.created_at,"%a
> > %b %d %H:%M:%S + %Y" )[0:6]))
> > print [x.text for x in tweet]
> > print [y.date for y in tweet]
>
> > However the output is now:
> > [datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2,
> > 22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)]
>
> > I still miss a little thing to completeanybody a little hint?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-08 Thread het.oosten
I forgot to mention that my desired output of the date is:
2010-02-22 20:46:03

On 8 mrt, 22:13, "het.oosten"  wrote:
> I am getting somewhere now:
>
> import datetime
> import time
> import twitter
>
> tweet  = twitter.Api().GetUserTimeline('username', count=3)
> for s in tweet:
>         s.date = datetime.datetime(*(time.strptime( s.created_at,"%a
> %b %d %H:%M:%S + %Y" )[0:6]))
> print [x.text for x in tweet]
> print [y.date for y in tweet]
>
> However the output is now:
> [datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2,
> 22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)]
>
> I still miss a little thing to completeanybody a little hint?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-08 Thread het.oosten
I am getting somewhere now:

import datetime
import time
import twitter

tweet  = twitter.Api().GetUserTimeline('username', count=3)
for s in tweet:
s.date = datetime.datetime(*(time.strptime( s.created_at,"%a
%b %d %H:%M:%S + %Y" )[0:6]))
print [x.text for x in tweet]
print [y.date for y in tweet]

However the output is now:
[datetime.datetime(2010, 3, 1, 16, 51, 55), datetime.datetime(2010, 2,
22, 20, 46, 3), datetime.datetime(2010, 2, 20, 10, 16, 2)]

I still miss a little thing to completeanybody a little hint?

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-08 Thread het.oosten
Thank you for the reply. When i add the [0] to tweet, the date
conversion is only applied to the last tweet

On 7 mrt, 23:24, Daniel Roseman  wrote:
> On Mar 7, 9:57 pm, "het.oosten"  wrote:
>
>
>
> > I am almost done implementing tweets on my site using a tutorial which
> > a found 
> > here:http://www.omh.cc/blog/2008/aug/4/adding-your-twitter-status-django-s...
>
> > The problem is that i want to modify the date output when i retrieve
> > multiple tweets. The example above is written for retrieving only one
> > most recent tweet from twitter.
>
> > The context_preprocessor i have now is (mostly taken from the site
> > above):
>
> > import datetime
> > import time
> > from django.conf import settings
> > from django.core.cache import cache
> > import twitter
>
> > def latest_tweet( request ):
> >     tweet = cache.get( 'tweet' )
>
> >     if tweet:
> >         return {"tweet": tweet}
>
> >     tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER,
> > count=3 )
> >     tweet.date = datetime.datetime(*(time.strptime( tweet.created_at,
> > "%a %b %d %H:%M:%S + %Y" )[0:6]))
> >     cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT )
>
> >     return {"tweet": tweet}
>
> > This results in the following error:
> > AttributeError: 'list' object has no attribute 'created_at'
>
> > The twitter api let me call a human readable date in the template
> > using relative_created_at. Unfortunately the output is in English.
>
> > Any idea how i get an easy readable date?
>
> > The output is now:
> > Fri Oct 30 10:18:53 + 2009
>
> > Or:
> > about 6 days ago
> > When i use relative_created_at
>
> I don't know the Twitter API, but you're calling GetUserTimeline with
> a count of 3, which presumably returns a list of 3 items. The list
> itself doesn't have a 'created_at' attribute, hence the error. Perhaps
> if you did:
>
>     tweet = twitter.Api().GetUserTimeline(settings.TWITTER_USER,
> count=3) [0]
>
> you would have better luck.
> --
> DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



Re: modify date in django twitter app

2010-03-07 Thread Daniel Roseman
On Mar 7, 9:57 pm, "het.oosten"  wrote:
> I am almost done implementing tweets on my site using a tutorial which
> a found 
> here:http://www.omh.cc/blog/2008/aug/4/adding-your-twitter-status-django-s...
>
> The problem is that i want to modify the date output when i retrieve
> multiple tweets. The example above is written for retrieving only one
> most recent tweet from twitter.
>
> The context_preprocessor i have now is (mostly taken from the site
> above):
>
> import datetime
> import time
> from django.conf import settings
> from django.core.cache import cache
> import twitter
>
> def latest_tweet( request ):
>     tweet = cache.get( 'tweet' )
>
>     if tweet:
>         return {"tweet": tweet}
>
>     tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER,
> count=3 )
>     tweet.date = datetime.datetime(*(time.strptime( tweet.created_at,
> "%a %b %d %H:%M:%S + %Y" )[0:6]))
>     cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT )
>
>     return {"tweet": tweet}
>
> This results in the following error:
> AttributeError: 'list' object has no attribute 'created_at'
>
> The twitter api let me call a human readable date in the template
> using relative_created_at. Unfortunately the output is in English.
>
> Any idea how i get an easy readable date?
>
> The output is now:
> Fri Oct 30 10:18:53 + 2009
>
> Or:
> about 6 days ago
> When i use relative_created_at

I don't know the Twitter API, but you're calling GetUserTimeline with
a count of 3, which presumably returns a list of 3 items. The list
itself doesn't have a 'created_at' attribute, hence the error. Perhaps
if you did:

tweet = twitter.Api().GetUserTimeline(settings.TWITTER_USER,
count=3) [0]

you would have better luck.
--
DR.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.



modify date in django twitter app

2010-03-07 Thread het.oosten
I am almost done implementing tweets on my site using a tutorial which
a found here:
http://www.omh.cc/blog/2008/aug/4/adding-your-twitter-status-django-site/

The problem is that i want to modify the date output when i retrieve
multiple tweets. The example above is written for retrieving only one
most recent tweet from twitter.

The context_preprocessor i have now is (mostly taken from the site
above):

import datetime
import time
from django.conf import settings
from django.core.cache import cache
import twitter

def latest_tweet( request ):
tweet = cache.get( 'tweet' )

if tweet:
return {"tweet": tweet}

tweet = twitter.Api().GetUserTimeline( settings.TWITTER_USER,
count=3 )
tweet.date = datetime.datetime(*(time.strptime( tweet.created_at,
"%a %b %d %H:%M:%S + %Y" )[0:6]))
cache.set( 'tweet', tweet, settings.TWITTER_TIMEOUT )

return {"tweet": tweet}

This results in the following error:
AttributeError: 'list' object has no attribute 'created_at'

The twitter api let me call a human readable date in the template
using relative_created_at. Unfortunately the output is in English.

Any idea how i get an easy readable date?

The output is now:
Fri Oct 30 10:18:53 + 2009

Or:
about 6 days ago
When i use relative_created_at

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.