User Tools

Site Tools


canto

Canto integration

Description

Displays feeds form Canto.

Python

#!/usr/bin/env python

# Copyright (C) 2009 Aldrik Dunbar

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.


# TODO:
# - add a update feeds button
# - add a way of changing filters/tags
# - add a elegant way to set articles as read

import sys
import socket
from canto import canto
from jinja2 import Template

template = """
set html_endmarker = <EOF>
js var run = Uzbl.run;
set mode = 1
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html id="uzbl_canto">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<title>Feeds</title>
		<script type="application/javascript">
			/* got access to run */
			run = null;
		</script>
	</head>
	<body>
		<h1>News Feeds</h1>
		{% for item in list %}
		{% if loop.first %}
			{% set feed = item["canto_state"][0] %}
			<div>
			<h2>{{ feed }}</h2>
			<ul>
		{% elif feed != item["canto_state"][0] %}
			{% set feed = item["canto_state"][0] %}
			</ul>
			</div>
			<div>
			<h2>{{ feed }}</h2>
			<ul>
		{% endif %}
				<li id="{{ item["id"] }}">
					<!-- only using target _blank because uzbl's html mode breaks history -->
					<h3><a href="{{ item["link"] }}" target="_blank">{{ item["title"] }}</a></h3>
					{% if item["summary_detail"]["type"] == "text/html" %}
					{{ item["summary_detail"]["value"].replace("'", "&#39;") }}
					{% else %}
					<pre>{{ item["summary_detail"]["value"].replace("'", "&#39;") }}</pre>
					{% endif %}
				</li>
		{% if loop.last %}
			</ul>
			</div>
		{% endif %}
		{% endfor %}
	</body>
</html>
<EOF>

"""

class Gui:
	def __init__(self, cfg, list, tags, register, deregister):
		output = Template(template).render(list=list)
		try:
			sock_path = sys.argv[5]
		except IndexError:
			import subprocess
			p = subprocess.Popen(["uzbl", "-c", "-"], stdin=subprocess.PIPE)
			p.communicate(output)
		else:
			sock = socket.socket(socket.AF_UNIX)
			sock.connect(sock_path)
			sock.send(output.encode("utf-8"))

canto.Gui = Gui
sys.argv[0] = "canto"
canto.Main()

# vim: set noet ff=unix

External Canto

Here is a Canto link_handler that opens the feed item in the most recently focused uzbl-browser:

In your Canto config:

link_handler("echo \"uri %u\" > `cat $XDG_CACHE_HOME/uzbl/uzbl_in_focus_fifo`")

In your Uzbl config:

@on_event FOCUS_GAINED sh 'echo "$4" >$XDG_CACHE_HOME/uzbl/uzbl_in_focus_fifo'
canto.txt · Last modified: 2016/08/31 14:10 (external edit)