Skip to content

Instantly share code, notes, and snippets.

Last active January 10, 2016 11:36
Show Gist options
  • Save troutcolor/d3de499f8a4626b1c3a0 to your computer and use it in GitHub Desktop.
Save troutcolor/d3de499f8a4626b1c3a0 to your computer and use it in GitHub Desktop.
A python script that makes a webpage,, from my pinboard links with thumbnails. Most of the script borrowed from Need webkit2png
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Most of this based on a script from
#I added the thumbnailing with webkit2png and cut it down to one feed.
#TODO clean up old images, don't regenerate existing images, spearate css from template
import feedparser
import time
from datetime import datetime, timedelta
import pytz
from subprocess import call
import os
import re
utc = pytz.utc
homeTZ = pytz.timezone('Europe/London')
dt =
if dt.hour < 2:
dt = dt - timedelta(hours=48)
dt = dt - timedelta(hours=48)
start = dt.replace(hour=0, minute=0, second=0, microsecond=0)
#start give a couple of days ago
d = feedparser.parse('')
#print d['feed']['title']
for e in d['entries']:
when = e['updated_parsed']
when = utc.localize(datetime.fromtimestamp(time.mktime(when)))
if when > start:
title= e['title']
link= e['link']
fname=re.sub(r'\W+', '',fname)
fname=fname+ '-clipped.png'
#fname will hold the name of the png file
posts.append(( title, link, fname))
#use webkit2png to get a screenshot
#edited version of webkit2png to handle el capitain's problems with https/http
os.system("'/Users/john/Dropbox/_working on/webkit2png' --ignore-ssl-check -C -D /Users/john/Dropbox/Public/thumbs/ " +link +" > /dev/null 2>&1")
listTemplate = '''<div>
<p class="title"><a href="{1}"><img src="{2}"><br>{0}</a></p><p></p>\n</div>'''
litems = []
#print listTemplate
#print "---------------------------------"
#print 'len'
#print len(posts)
for p in posts:
r = [ x.encode('ascii') for x in p[0:] ]
except UnicodeError:
r = [ x.encode('utf-8') for x in p[0:] ]
#I had to add all this stuff because of problems with utf-8 that I don't full understand
#print "RRRR "
#print r
#r = [ x.encode('ascii') for x in p[0:] ]
#print litems.append(listTemplate.format(p0,p1))
ul = '\n \n'.join(litems)
#print ul
print '''<html>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width" />
body {{
-webkit-box-shadow: inset 10px 10px 5px 0px rgba(0,0,0,0.75);
-moz-box-shadow: inset 10px 10px 5px 0px rgba(0,0,0,0.75);
box-shadow: inset 10px 10px 5px 0px rgba(0,0,0,0.75);;padding:0px;margin:0px;border:solid 26px #fff;background:#ccc;;background-image: url('');
h1 {{
font-family: Arial, "MS Trebuchet", sans-serif;color:#fff;padding:20px
section.rss div {{ margin:20px 50px;float:left;background:#fff;padding:20px;width:220px;height:200px;box-shadow: 10px 10px 5px rgba(100,100,100,0.6);-webkit-box-shadow: 10px 10px 5px rgba(100,100,100,0.6);-moz-box-shadow: 10px 10px 5px rgba(100,100,100,0.6);
background-image: url('thumbtack.png');
background-repeat: no-repeat;
background-position: top right;
overflow: hidden;
.rss {{
.title {{
font-weight: bold;
font-family: Helvetica, Sans-serif;
font-size: 90%;
margin-bottom: .25em;
.title a {{
text-decoration: none;
color: black;
.info {{
font-size: 85%;
margin-top: 0;
margin-left: .5em;
img {{
max-width: 700px;
@media screen and (max-width:667px) {{
body {{
font-size: 200%;
width: 650px;
background-color: white;
.rss li {{
line-height: normal;
img {{
max-width: 600px;
<title>Recent Pinboard</title>
<body><h1>Recent Pins</h1></h1>
<section class="rss">
<p style="width:100%;clear:both">&nbsp;</p>
<script src=""></script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment