Skip to content

Instantly share code, notes, and snippets.

@troutcolor
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, https://dl.dropboxusercontent.com/u/81715/pinboard.html, from my pinboard links with thumbnails. Most of the script borrowed from http://leancrew.com/all-this/2015/12/homemade-rss-aggregator-followup. Need webkit2png
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#Most of this based on a script from http://leancrew.com/all-this/2015/12/homemade-rss-aggregator-followup/
#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 = datetime.now(homeTZ)
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('http://feeds.pinboard.in/rss/u:johnjohnston')
#print d['feed']['title']
posts=[]
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=link.replace('https://',"")
fname=fname.replace('http://',"")
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="https://dl.dropboxusercontent.com/u/81715/thumbs/{2}"><br>{0}</a></p><p></p>\n</div>'''
litems = []
#print listTemplate
#print "---------------------------------"
#print 'len'
#print len(posts)
for p in posts:
try:
r = [ x.encode('ascii') for x in p[0:] ]
except UnicodeError:
r = [ x.encode('utf-8') for x in p[0:] ]
else:
r=p
#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:] ]
litems.append(listTemplate.format(r[0],r[1],r[2]))
#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" />
<head>
<style>
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('http://johnj.info/wire106/characters/seamless_cork_board_background.jpg');
}}
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;
}}
}}
</style>
<title>Recent Pinboard</title>
<body><h1>Recent Pins</h1></h1>
<section class="rss">
{}
</section>
<p style="width:100%;clear:both">&nbsp;</p>
<script src="https://dl.dropboxusercontent.com/u/81715/thumbs/pinboard.js"></script>
</body>
</html>
'''.format(ul)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment