try rolling our own image downloader for news

workspace
Brendan Howell 4 years ago
parent 41a1b4cd2b
commit 0faa3b3be5

@ -6,6 +6,7 @@ import json
import os
import random
import string
import tempfile
import threading
import urllib.request, urllib.parse, urllib.error
@ -318,6 +319,8 @@ class Publications(Bureau):
def fetch_og(entry):
"""
get OpenGraph data for entry
and download image
TODO: add microdata support here to get author
"""
og_data = self._get_ogdata(entry.link)
if hasattr(entry, "media_thumbnail"):
@ -327,6 +330,14 @@ class Publications(Bureau):
else:
entry.img = " "
if entry.imge != " ":
fileext = "." + entry.img.rsplit(".",1)[1]
filename = tempfile.mktemp(fileext)
print("fetching", entry.img, filename)
urllib.request.urlretrieve(entry.img, filename)
entry.img = "file://" + filename
thread = threading.Thread(target=fetch_og, args=(entry,))
threads.append(thread)
thread.start()

Loading…
Cancel
Save