Skip to content

Instantly share code, notes, and snippets.

@vinc
Created July 13, 2011 07:33
Show Gist options
  • Save vinc/1079884 to your computer and use it in GitHub Desktop.
Save vinc/1079884 to your computer and use it in GitHub Desktop.
Script calling Facebook's robot to visit URLs from a RSS feed.
#!/usr/bin/env python
import feedparser
import os
import pickle
import sys
import time
import urllib
facebook_lint = 'https://developers.facebook.com/tools/lint?url='
if (len(sys.argv) != 2):
print 'Usage: %s <rss>' % sys.argv[0]
sys.exit(1)
feed = feedparser.parse(sys.argv[1])
cache = []
cache_filename = 'facebook_cache.pkl'
if os.path.isfile(cache_filename):
cache_file = open(cache_filename, 'rb')
cache = pickle.load(cache_file)
for item in feed.entries:
if item.link not in cache:
print "Call Facebook robot to visit '%s'" % item.link
cache.append(item.link)
urllib.urlopen('%s%s' % (facebook_lint, urllib.quote(item.link)))
time.sleep(5)
cache_file = open(cache_filename, 'wb')
pickle.dump(cache, cache_file)
cache_file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment