I'm getting this error:
TypeError: get_browser() missing 1 required positional argument: 'self'
But I can't work out what the error is. I've only ever learnt to program in Fortran (!) so I'm feeling a bit in the dark here.
I don't know if it's obvious to you what's going wrong from the copy & paste below? It's my mashup of the Taz Digiabo & the get_browser you referenced??
Many thanks!
Spoiler:
Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__license__ = 'GPL v3'
__copyright__ = '2010, Lars Jacob jacob.lars at gmail.com'
__docformat__ = 'restructuredtext de'
'''
KB The Monthly
'''
import os
import zipfile
from calibre.web.feeds.news import BasicNewsRecipe
from calibre.ptempfile import PersistentTemporaryFile
try:
from urllib.request import HTTPBasicAuthHandler, build_opener, install_opener, urlopen
from urllib.error import HTTPError
except ImportError:
from urllib2 import HTTPBasicAuthHandler, build_opener, install_opener, urlopen, HTTPError
class KBMonthly(BasicNewsRecipe):
title = u'KBM'
description = u'Attempting to download'
language = 'EN'
lang = 'en-EN'
__author__ = 'Kate'
needs_subscription = True
conversion_options = {
'no_default_epub_cover': True
}
# def build_index(self):
# domain = "https://www.themonthly.com.au"
#
# url = domain + "/ebook/"
#
# auth_handler = HTTPBasicAuthHandler()
# auth_handler.add_password(realm='TAZ-ABO',
# uri=url,
# user=self.username,
# passwd=self.password)
# opener = build_opener(auth_handler)
# install_opener(opener)
#
# try:
# f = urlopen(url)
# except HTTPError:
# self.report_progress(0, _('Can\'t login to download issue'))
# raise ValueError('Failed to login, check your username and'
# ' password')
def get_browser(self):
br = BasicNewsRecipe.get_browser()
if self.username is not None and self.password is not None:
br.open('https://www.themonthly.com.au/ebook/')
br.select_form(name='login')
br['USERID'] = self.username
br['PASSWORD'] = self.password
br.submit()
return br
tmp = PersistentTemporaryFile(suffix='.epub')
self.report_progress(0, _('downloading epub'))
tmp.write(f.read())
tmp.close()
zfile = zipfile.ZipFile(tmp.name, 'r')
self.report_progress(0, _('extracting epub'))
zfile.extractall(self.output_dir)
tmp.close()
index = os.path.join(self.output_dir, 'content.opf')
self.report_progress(1, _('epub downloaded and extracted'))
return index
calibre_most_common_ua = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36'