def getArticleImages(self, body): soup = BeautifulSoup(body) imageElements = soup.findAll('img') def getSrc(x): return x['src'] return map(getSrc, imageElements)
collection = Collection.objects.get(pk=1236) thumbnailDir = settings.MEDIA_ROOT + "resource_thumbnail/tmp/" for resource in collection.resources.all(): url = resource.revision.content.url parsed_url = urlparse.urlparse(url) req = httplib.HTTPConnection(parsed_url.netloc, 80) req.connect() req.request("GET", parsed_url.path) response = req.getresponse().read() soup = BeautifulSoup(response) img_wrapper = soup.find("div", {"class": "post-thumbnail"}) img = img_wrapper.find("img") thumbnail = thumbnailDir + str(resource.id) # Returns a 120x90 image urllib.urlretrieve(img["src"], thumbnail + "-tmp.jpg") call(["convert", "-size", "200x200", "xc:white", thumbnail + ".jpg"]) call( [ "composite", "-geometry",
if sr['license']['name'] == "Other": lo = License.objects.get(title="Unknown") oer.license = lo oer.cost = 0.0 oer.user = User.objects.get(username="******") if sr['description'] != "": oer.body_markdown = sr['description'] else: if sr['resourceType']['name'] == "resource/url" or sr['resourceType']['name'] == "video/youtube": try: source = urlopen(sr['url']) soup = BeautifulSoup(source) description = soup.findAll('meta', attrs={'name' : "description"})[0] if description: oer.body_markdown = description['content'] except: pass oer.save() oerSet.append(oer) print oerSet article.resources = oerSet article.save() except: