def main(): db = OEmbeds() for line in fileinput.input(): tweet = json.loads(line) for ent in tweet['entities']['urls']: url = ent.get('unshortened_url') or ent['expanded_url'] if 'twitter.com' in url: continue meta, exists = db.get(url) if not exists: try: meta = embed(url) db.put(url, meta) except Exception as e: logging.warn("error while looking up %s: %s", url, e) if meta: ent['oembed'] = meta print(json.dumps(tweet))
def test_no_scheme(): e = embed('https://www.youtube.com/watch?v=dQw4w9WgXcQ') assert e['title'] == 'Rick Astley - Never Gonna Give You Up (Video)'
def test_scheme(): e = embed('https://twitter.com/jack/status/20') assert e['url'] == 'https://twitter.com/jack/status/20'
def test_no_provider(): e = embed('https://inkdroid.org') assert e == None