Example #1
0
    def do_read(self, line):
        """
        Usage: read <article_uid>
        Pipes article content into the system pager.

        Text column width can be configured with the width command.
        """
        then = time.time()
        response = self.c._send_request("articles/" + line)
        if response[1] != 200:
            print response[1]
            return

        data = response[0]

        if not 'content' in data:
            print None
        else:

            p = Popen(['less', '-P', data['title']], stdin=PIPE)

            try:
                duration = tconv(int(then) - int(data['created']))
                p.stdin.write('%s\n(%i paragraphs, fetched %s ago)\n%s\n\n' % \
                    (data['title'].encode("utf-8", "ignore"),
                    len(data['content'].encode("utf-8","ignore").split("\n"))/2+1,
                    duration,
                    data['url'].encode("utf-8","ignore")))

                content = data['content'].encode("utf-8", "ignore")
                # Get TTY width and wrap the text
                if self.width == "auto":
                    s = _curses.initscr()
                    width = s.getmaxyx()[1]
                    _curses.endwin()

                else:
                    width = self.width

                content = '\n'.join(
                    textwrap.wrap(content,
                                  width,
                                  break_long_words=False,
                                  replace_whitespace=False))
                p.stdin.write(content)

            except IOError as e:
                if e.errno == errno.EPIPE or e.errno == errno.EINVAL:
                    sys.stderr.write("Error writing to pipe.\n")
                else:
                    raise

            p.stdin.close()
            p.wait()
            now = time.time()
            duration = tconv(now - then)
Example #2
0
    def do_read(self,line):
        """
        Usage: read <article_uid>
        Pipes article content into the system pager.

        Text column width can be configured with the width command.
        """
        then = time.time()
        response = self.c._send_request("articles/" + line)
        if response[1] != 200:
            print response[1]
            return

        data = response[0]

        if not 'content' in data:
            print None
        else:

            p = Popen(['less', '-P', data['title']], stdin=PIPE)

            try:
                duration = tconv(int(then) - int(data['created']))
                p.stdin.write('%s\n(%i paragraphs, fetched %s ago)\n%s\n\n' % \
                    (data['title'].encode("utf-8", "ignore"),
                    len(data['content'].encode("utf-8","ignore").split("\n"))/2+1,
                    duration,
                    data['url'].encode("utf-8","ignore")))

                content = data['content'].encode("utf-8", "ignore")
                # Get TTY width and wrap the text
                if self.width == "auto":
                    s = _curses.initscr()
                    width = s.getmaxyx()[1]
                    _curses.endwin()

                else:
                    width = self.width

                content = '\n'.join(
                    textwrap.wrap(content, width, break_long_words=False, replace_whitespace=False)
                )
                p.stdin.write(content)

            except IOError as e:
                if e.errno == errno.EPIPE or e.errno == errno.EINVAL:
                    sys.stderr.write("Error writing to pipe.\n")
                else:
                    raise

            p.stdin.close()
            p.wait()
            now = time.time()
            duration = tconv(now-then)
Example #3
0
 def update(self):
     if self.article:
         feed = self.article.get('feed', None)
         heading = "%s\n%s (%s %s ago)\n%s\n\n" % \
             (self.article['title'].encode("ascii","ignore"), feed if feed else "",
             self.article['uid'], tconv(int(time.time()) - int(self.article['created'])),
             self.article['url'])
         self.change_content(0, heading)
     self.outbuffer = self.data.split('\n')[self.position:]
     self.change_content(1, '\n'.join(self.outbuffer))
Example #4
0
 def update(self):
     if self.article:
         feed = self.article.get('feed', None)
         heading = "%s\n%s (%s %s ago)\n%s\n\n" % \
             (self.article['title'].encode("ascii","ignore"), feed if feed else "",
             self.article['uid'], tconv(int(time.time()) - int(self.article['created'])),
             self.article['url'])
         self.change_content(0, heading)
     self.outbuffer = self.data.split('\n')[self.position:]
     self.change_content(1, '\n'.join(self.outbuffer))
Example #5
0
    # it runs the risk of a singular script halting the entire thing
    # in return we get to modify articles (ie machine translation) before storing.

    # Non-blocking IO will result in the most reliable performance within your scripts.
    #
    for s in app.scripts.scripts.values():
        try:
            s.execute(env={'article': article, 'feed': feed})
            article = s['article']
        except Exception, e:
            log("Error executing %s: %s" % (s.file, e.message), "error")

    commit_to_feed(feed, article)

    now = int(time.time())
    duration = tconv(now - then)
    log('%s: %s/%s: Stored %s "%s" (%s)' % \
     (feed.key.name, feed.group.name, feed.name, article.uid, article.title, duration))
    return


def fetch_article(key):
    pass


def commit_to_feed(feed, article):
    """
	 Place a new article on the api key of a feed, the feed itself,
	 and commit changes.
	"""
Example #6
0
	# it runs the risk of a singular script halting the entire thing
	# in return we get to modify articles (ie machine translation) before storing.

	# Non-blocking IO will result in the most reliable performance within your scripts.
	#
	for s in app.scripts.scripts.values():
		try:
			s.execute(env={'article':article, 'feed':feed})
			article = s['article']
		except Exception, e:
			log("Error executing %s: %s" % (s.file, e.message), "error")

	commit_to_feed(feed, article)

	now = int(time.time())
	duration = tconv(now-then)
	log('%s: %s/%s: Stored %s "%s" (%s)' % \
		(feed.key.name, feed.group.name, feed.name, article.uid, article.title, duration))
	return

def fetch_article(key):
	pass

def commit_to_feed(feed, article):
	"""
	 Place a new article on the api key of a feed, the feed itself,
	 and commit changes.
	"""

	# We give articles UIDs manually to ensure unique time data is used.
	article.uid = uid()