'Display the Tweets on a Simile Timeline
http://www.simile-widgets.org/wiki/Reference_Documentation_for_Timeline'

@staticmethod
def twitter_timeline(r, **attr):

    if ((r.representation == 'html') and (r.name == 'twitter_result')):
        response = current.response
        s3 = response.s3
        appname = r.application
        s3.scripts.append(('/%s/static/scripts/simile/timeline/timeline-api.js' % appname))
        if s3.debug:
            s3.scripts.append(('/%s/static/scripts/S3/s3.timeline.js' % appname))
        else:
            s3.scripts.append(('/%s/static/scripts/S3/s3.timeline.min.js' % appname))
        if r.record:
            rows = [r.record]
        else:
            rows = r.resource.select(['date', 'body'], limit=2000, as_rows=True)
        data = {'dateTimeFormat': 'iso8601'}
        now = r.utcnow
        tl_start = tl_end = now
        events = []
        import re
        for row in rows:
            start = (row.date or '')
            if start:
                if (start < tl_start):
                    tl_start = start
                if (start > tl_end):
                    tl_end = start
                start = start.isoformat()
            title = re.sub('(?<=^|(?<=[^a-zA-Z0-9-_\\.]))@([A-Za-z]+[A-Za-z0-9]+)|RT', '', row.body)
            if (len(title) > 30):
                title = title[:30]
            events.append({'start': start, 'title': title, 'description': row.body})
        data['events'] = events
        data = json.dumps(data, separators=SEPARATORS)
        code = ''.join(('S3.timeline.data=', data, '\nS3.timeline.tl_start="', tl_start.isoformat(), '"\nS3.timeline.tl_end="', tl_end.isoformat(), '"\nS3.timeline.now="', now.isoformat(), '"\n'))
        s3.js_global.append(code)
        item = DIV(_id='s3timeline', _class='s3-timeline')
        output = dict(item=item)
        if attr.get('rheader'):
            rheader = attr['rheader'](r)
            if rheader:
                output['rheader'] = rheader
        output['title'] = current.T('Twitter    Timeline')
        response.view = 'timeline.html'
        return output
    else:
        r.error(405, current.ERROR.BAD_METHOD)
