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)
| 1934 | class 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) |