Beispiel #1
0
    def generate_output(self):
        d = datetime.datetime.now()

        #only request events that start within the next 24 hours
        params = {'start-min': datetimetostr(d),
                  'start-max': datetimetostr(d + datetime.timedelta(1)),
                  'orderby': 'starttime',
                  'sortorder': 'ascending'}
        self.url = '%s?%s' % (self.url, urllib.urlencode(params))
        xml = BSS(download_page(self.url), 
                  selfClosingTags=['category', 'content', 'link'])

        #only parse entry title and start time
        entries = [(e.title.text, 
                    get_datetime(e.find('gd:when')['starttime']))
                    for e in xml.findAll('entry')]
        if len(entries) == 0:  return 'You have no scheduled events for today.'

        output = []
        for content, start_time in entries:
            #use different templates for all day events vs events with a start
            #time
            if type(start_time) == datetime.date:
                output.append(self.allday_tmpl.substitute(
                    {'content': content}))
            else:
                output.append(self.timed_tmpl.substitute(
                    {'content': content, 
                     'start_time': start_time.strftime('%I:%M %p')}))
        return ''.join(output) 
Beispiel #2
0
    def generate_output(self):
        #download email feed and parse xml
        xml = BSS(self._download_feed(), selfClosingTags=['link'])
    
        #for each email, generate output subbing the sender and the subject
        emails = [self.email_tmpl.substitute({'sender': e.author.nameTag.text,
                  'subject': e.title.text}) for e in xml.findAll('entry')]

        #substitute all of the email templates into one output string
        self.output = self.gmail_tmpl.substitute(
            {'unread_count': xml.fullcount.text, 'emails': '\n'.join(emails)})

        return self.output