Created
July 13, 2011 07:33
-
-
Save vinc/1079884 to your computer and use it in GitHub Desktop.
Script calling Facebook's robot to visit URLs from a RSS feed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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