Exemplo n.º 1
0
    def fetch(self):
        def is_home_page(url):
            return '/' not in url.replace('//', '').strip('/')

        try:
            soup = get_soup_by_url(self.url)
        except Exception, e:
            return
Exemplo n.º 2
0
def save_note(user, url, date, tweet_id):
    soup = get_soup_by_url(url)
    if not soup:
        return
    tag = soup.find("div", {'class': 'highlightText'})
    if not tag:
        return
    text = ''.join(tag.findAll(text=True)).strip()

    remark = ''
    tag = soup.find("div", {'class': 'note'})
    if tag:
        remark = ''.join(tag.findAll(text=True)).replace('Note:', '').replace('@zzrt', '').strip()

    cover_tag = soup.find('div', {'class': 'cover'})
    tag = cover_tag.find("span", {'class': 'title'})
    if tag:
        book = ''.join(tag.findAll(text=True)).strip()
        if 'Personal Document' in book:
            book = ''
    else:
        book = ''

    tag = cover_tag.find("span", {'class': 'author'})
    if tag:
        author = ''.join(tag.findAll(text=True)).replace(' by ', '').strip()
    else:
        author = ''

    if ' ' not in text \
        and text[0] in string.ascii_letters \
        and len(text) <= 64:
        if Word.objects.filter(word=text).count() == 0:
            Word.objects.create(user=user, url=url, word=text)
    else:
        note = Note(user=user, url=url, text=text)
        note.uuid = str(uuid.uuid4())
        note.added = date or datetime.datetime.now()
        if remark:
            note.remark = remark[:128]
        if book:
            note.book = book[:128]
        if author:
            note.author = author[:128]
        note.save()

        # Delete this tweet and tweet it's content
        user_api = get_twitter_api(user=user)
        if not user_api:
        	return

        if len(text) <= 140:
            status = text
            if len(status) + len(" #note") <= 140:
                status += " #note"
            if remark and len(status) + len(remark) <= 138:
                status = remark + ": " + status
            try:
                user_api.PostUpdates(status)
                user_api.DestroyStatus(tweet_id)
            except Exception, e:
                logger.info("Error: %s tweeted: %s, delete: %s", e, status, tweet_id)
        else: