Example #1
0
    def loadEntry(self) :
        row = 1
        displayRows = []
        backupRow = 0
        ceSheet = self.sheet
        # set datestr to practice that is in sheet's last row, or to today's practice
        while row < ceSheet.nrows :
            val = ceSheet.cell_value(row, self.pubCol)
            if val:
                valDate = xldate_as_tuple(val, 0) #Magic number means Datemode since 1900 instead of 1904. Stupid proprietary Excel Dates.
                datestr = "%02d/%02d/%04d" % (valDate[1], valDate[2], valDate[0])
                backupRow = row
                if datestr == currdate:
                    displayRows.append(row)
            row+=1

        if not backupRow :
            print >> stderr, "WARNING: No practices found for any date"
            exit(0)

        if not displayRows :
            return False;
            print >> stderr, "WARNING: Today's Daily Practice not found - checked %d rows for \"%s\"" % (row, currdate)

        for row in displayRows :
            name =  texify(toascii(ceSheet.cell_value(row, self.nameCol)))
            practice =  texify(re.compile(r'\r?\n').sub(' ', toascii(ceSheet.cell_value(row, self.quoteCol))))
            category = texify(toascii(ceSheet.cell_value(row, self.catCol)))
            if not category :
                category = 'Next Jump Teachings'
            url = texify(toascii(ceSheet.cell_value(row, self.urlCol)))
        self.article = Section("", name, category, practice, url, None, 'article')
        return self.article
Example #2
0
 def from_item(cls, item) :
     title = toascii(unicode(item.title.string))
     contributor = toascii(unicode(item.find('dc:creator').string))
     href = toascii(unicode(item.link.string))
     category = toascii(unicode(item.category.string))
     content = ''
     paragraphs = item.find('content:encoded')
     paragraphs = BeautifulSoup(unicode(paragraphs.string)).findAll('p')
     i = 0
     h = HTMLParser()
     while i<len(paragraphs) :
         toAdd = h.unescape(toascii(unicode(strip_tags(unicode(paragraphs[i])))).strip()) 
         if len(toAdd) > 0 :
             content = content + ' ' + toAdd
         i+=1
     content = re.compile(r'\r?\n').sub(' ', content)
     xml = item
     return cls(title, contributor, category, content, href, xml)
def cleanup(text):
    """ This function cleans up the text a bit, and removes newlines."""

    data = text.decode('utf8')
    data = ununicode.toascii(data)  # a useful function that does some simple unicode replacements
    data = data.replace('\r', '')  # windows newline in some files
    data = data.replace('\n', ' ')  # turn newline into space
    data = data.strip()  # strip remaining white space chars from edges
    return data
Example #4
0
def output_encode(s, encoding):
    if encoding == 'ascii' and has_ununicode:
        #return unicodedata.normalize('NFKD', s).encode('ascii', 'ignore')
        # valid values in encode are replace and ignore
        return ununicode.toascii(s,
                                 in_encoding=encoding,
                                 errfilename=os.path.join(outdir, "errors"))
    elif isinstance(s, unicode):
        return s.encode('utf-8', 'backslashreplace')
    else:
        return s
Example #5
0
def output_encode(s, encoding):
    if encoding == 'ascii' and has_ununicode:
        #return unicodedata.normalize('NFKD', s).encode('ascii', 'ignore')
        # valid values in encode are replace and ignore
        return ununicode.toascii(s,
                                 in_encoding=encoding,
                                 errfilename=os.path.join(outdir,
                                                          "errors"))
    elif isinstance(s, unicode):
        return s.encode('utf-8', 'backslashreplace')
    else:
        return s
Example #6
0
        print "in PING"
        s.send("PONG %s\r\n" % data.split(' ')[1])

    if 'PRIVMSG' in command:
        if 'bot' in text:
           s.send("PRIVMSG %s : I am here!\r\n" % CHAN)

    if 'twitter' in text:
        s.send('PRIVMSG %s : Twitter sucks\r\n' % CHAN)
    
    if 'TWEET' in text:
        stati = api.GetPublicTimeline()
        ut = [(st.user.name,st.text) for st in stati]

        for u, t in ut:
           tweet = '['+ununicode.toascii(u) + '] ' + ununicode.toascii(t) + '\r\n'
           print 'PRIVMSG %s :%s' % (CHAN, tweet)
           s.send('PRIVMSG %s :%s' % (CHAN, tweet))

        if len(ut) == 0:
           s.send('PRIVMSG %s : Sorry, no tweets right now!' % (CHAN))
  

    if 'BYE' in data:
        s.send('PRIVMSG %s : You want me gone? \r\n' % CHAN)
        time.sleep(1)
        s.send('PRIVMSG %s : Leaving now! \r\n' % CHAN)
        s.send('PART %s : Leaving now! \r\n' % CHAN)
        time.sleep(1)
        s.send('QUIT Leaving, bye!\r\n')
        break
Example #7
0
        if 'bot' in text:
           time.sleep(1)
           s.send("PRIVMSG %s : Me too!\r\n" % CHAN)

    if 'twitter' in text:
        time.sleep(1)
        s.send('PRIVMSG %s : shush, you!\r\n' % CHAN)
    
    if 'tweet' in text:
        stati = api.GetSearch('mongodb')
        ut = [(st.user.name,st.text) for st in stati]

        print ut

        for t in ut:
           tweet = ununicode.toascii(t[1]) + '\r\n'
           print 'PRIVMSG %s :%s' % (CHAN, tweet)
           s.send('PRIVMSG %s :%s' % (CHAN, tweet))

        if len(ut) == 0:
           s.send('PRIVMSG %s : Sorry, no tweets right now!' % (CHAN))
  

    if 'bye' in data:
        s.send('PRIVMSG %s : You want me gone? \r\n' % CHAN)
        time.sleep(1)
        s.send('PRIVMSG %s : Leaving now! \r\n' % CHAN)
        s.send('PART %s : Leaving now! \r\n' % CHAN)
        time.sleep(1)
        s.send('QUIT Leaving, bye!\r\n')
        break
Example #8
0
        print "in PING"
        s.send("PONG %s\r\n" % data.split(' ')[1])

    if 'PRIVMSG' in command:
        if 'bot' in text:
            s.send("PRIVMSG %s : I am here!\r\n" % CHAN)

    if 'twitter' in text:
        s.send('PRIVMSG %s : Twitter sucks\r\n' % CHAN)

    if 'TWEET' in text:
        stati = api.GetPublicTimeline()
        ut = [(st.user.name, st.text) for st in stati]

        for u, t in ut:
            tweet = '[' + ununicode.toascii(u) + '] ' + ununicode.toascii(
                t) + '\r\n'
            print 'PRIVMSG %s :%s' % (CHAN, tweet)
            s.send('PRIVMSG %s :%s' % (CHAN, tweet))

        if len(ut) == 0:
            s.send('PRIVMSG %s : Sorry, no tweets right now!' % (CHAN))

    if 'BYE' in data:
        s.send('PRIVMSG %s : You want me gone? \r\n' % CHAN)
        time.sleep(1)
        s.send('PRIVMSG %s : Leaving now! \r\n' % CHAN)
        s.send('PART %s : Leaving now! \r\n' % CHAN)
        time.sleep(1)
        s.send('QUIT Leaving, bye!\r\n')
        break