Skip to content

Instantly share code, notes, and snippets.

@james-see
Created January 2, 2015 03:26
Show Gist options
  • Save james-see/478310ca5ec8704dd589 to your computer and use it in GitHub Desktop.
Save james-see/478310ca5ec8704dd589 to your computer and use it in GitHub Desktop.
getpins.py
# this script gets your most recent pinboard items
# set your username and tag of interest
# it copies a markdown formatted list to the clipboard for easy export
# the script gets the most recent five items by default
# code by James Campbell @jamescampbell on twitter
import feedparser
import console
import clipboard
import webbrowser
#global defaults
used = "jamescampbell" # pinboard username
#functions
#this function gets inputs with custom prompts
def inputer(prompt):
value = None
while value is None:
try:
value = raw_input(prompt)
except ValueError:
print 'Please enter a tag'
value = None
return value
#get pinboard tag of interest
tag = inputer("what tag to find?: ")
#get number of recent pins with that tag
pincount = inputer("how many to find?: ")
#html string to get public rss pinboard
htmlstr = "http://feeds.pinboard.in/rss/u:" + used + "/t:" + tag + "?count=" + pincount
#make the doughnuts
d = feedparser.parse(htmlstr)
#print d['feed']['title'] #test working
htmllinks="recent links of interest \n"
i=0 # count for markdown list
for entry in d.entries:
i = i + 1 # list number in output
try:
entrydesc = entry.description
except:
entrydesc = "no description"
htmllinks += str(i) + " [" + entry.title + "]" + "(" + entry.link + ") \n" + entrydesc + "\n\n"
clipboard.set(htmllinks)
webbrowser.open('workflow://')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment