MCPcopy Index your code
hub / github.com/clips/pattern / download

Method download

pattern/web/__init__.py:1936–1950  ·  view source on GitHub ↗

Downloads an item from MediaWikiArticle.media and returns the content. Note: images on Wikipedia can be quite large, and this method uses screen-scraping, so Wikipedia might not like it that you download media in this way. To save the media in a file:

(self, media, **kwargs)

Source from the content-addressed store, hash-verified

1934class WikipediaArticle(MediaWikiArticle):
1935
1936 def download(self, media, **kwargs):
1937 """ Downloads an item from MediaWikiArticle.media and returns the content.
1938 Note: images on Wikipedia can be quite large, and this method uses screen-scraping,
1939 so Wikipedia might not like it that you download media in this way.
1940 To save the media in a file:
1941 data = article.download(media)
1942 open(filename+extension(media),"w").write(data)
1943 """
1944 url = "http://%s.wikipedia.org/wiki/File:%s" % (self.__dict__.get("language", "en"), media)
1945 if url not in cache:
1946 time.sleep(1)
1947 data = URL(url).download(**kwargs)
1948 data = re.search(r"upload.wikimedia.org/.*?/%s" % media, data)
1949 data = data and URL("http://" + data.group(0)).download(**kwargs) or None
1950 return data
1951
1952 def __repr__(self):
1953 return "WikipediaArticle(title=%s)" % repr(self.title)

Callers

nothing calls this directly

Calls 5

URLClass · 0.85
getMethod · 0.45
downloadMethod · 0.45
searchMethod · 0.45
groupMethod · 0.45

Tested by

no test coverage detected