Beispiel #1
0
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))
Beispiel #2
0
def test_no_scheme():
    e = embed('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
    assert e['title'] == 'Rick Astley - Never Gonna Give You Up (Video)'
Beispiel #3
0
def test_scheme():
    e = embed('https://twitter.com/jack/status/20')
    assert e['url'] == 'https://twitter.com/jack/status/20'
Beispiel #4
0
def test_no_provider():
    e = embed('https://inkdroid.org')
    assert e == None