Skip to content

Instantly share code, notes, and snippets.

@anateus
Created October 26, 2014 06:16
Show Gist options
  • Save anateus/7cf7d8eb68d81f8bb451 to your computer and use it in GitHub Desktop.
Save anateus/7cf7d8eb68d81f8bb451 to your computer and use it in GitHub Desktop.
Generate newsletter from last week of pinboard
import pinboard
import os
from datetime import datetime, timedelta
from jinja2 import Template
API_TOKEN = os.environ.get("PINBOARD_API_TOKEN")
page_template = Template("""# Cool Newsletter
A description
## Some awesome links:
{{ stories}}
Wow those were great, huh?
""")
story_template = Template("* {{ url }}{% if tags %} - [ {{ tags }}] - {% endif %}{{ description }} ")
bookmarks = []
if __name__ == "__main__":
pb = pinboard.Pinboard(API_TOKEN)
from_date = datetime.now()-timedelta(days=7)
bookmarks = pb.posts.all(fromdt=from_date)
page = page_template.render(stories='\n'.join(
story_template.render(url=b.url,
description=b.description,
tags=', '.join(b.tags)) for b in bookmarks
))
print page
pinboard==0.5.7
Jinja2==2.7.3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment