This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import csv | |
def create_articles(path): | |
temp = [] | |
file = open(path, 'r') | |
for line in file: | |
arr = line.split(',') | |
#print(arr[0][-4:].lower()) | |
if arr[0][-4:].lower() == '.pdf': | |
ext = 'pdf' | |
else: | |
ext = 'html' | |
temp.append(Article(arr[0], arr[1], ext)) | |
return temp | |
def save_as_html(url, title, ext): | |
try: | |
urllib.request.urlretrieve(url, 'html/' + title + "." + ext) | |
except: | |
print("error happend on ", url) | |
def main(): | |
articles = create_articles('instapaper-export.csv') | |
articles.pop(0) | |
print(len(articles)) | |
for a in articles: | |
print('saving article number', articles.index(a), 'title:', a.title, 'and extention', a.ext) | |
save_as_html(a.url,str(articles.index(a)) + '-' + a.title, a.ext) | |
class Article: | |
def __init__(self, url, title, extention): | |
self.url = url | |
self.title = title | |
self.ext = extention | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This simply takes the csv you get as an export from your Instapaper account and saves it as a html page or a pdf page if the url ends in .pdf