From 59697f1a755dfd5c91530829e9e144668f50073d Mon Sep 17 00:00:00 2001 From: sigizmund Date: Thu, 17 Dec 2009 15:16:51 +0000 Subject: [PATCH] Added adapter.py, now all working adapters must implement FanfictionSiteAdapter interface --- adapter.py | 30 ++++++++++++++++++++++++++++++ ffa.py | 3 ++- ffnet.py | 3 ++- ficwad.py | 8 +++++--- 4 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 adapter.py diff --git a/adapter.py b/adapter.py new file mode 100644 index 0000000..41e040d --- /dev/null +++ b/adapter.py @@ -0,0 +1,30 @@ +class FanfictionSiteAdapter: + def __init__(self, url): + pass + + def requiresLogin(self, url = None): + pass + + def performLogin(self, url = None): + pass + + def extractIndividualUrls(self): + pass + + def getText(self, url): + pass + + def setLogin(self, login): + pass + + def setPassword(self, password): + pass + + def getStoryName(self): + pass + + def getAuthorName(self): + pass + + def getPrintableUrl(self, url): + pass \ No newline at end of file diff --git a/ffa.py b/ffa.py index 1a5a738..b8c307e 100644 --- a/ffa.py +++ b/ffa.py @@ -18,6 +18,7 @@ import BeautifulSoup as bs import htmlentitydefs as hdefs from constants import * +from adapter import * try: import login_password @@ -25,7 +26,7 @@ except: # tough luck pass -class FFA: +class FFA(FanfictionSiteAdapter): def __init__(self, url): self.url = url parsedUrl = up.urlparse(url) diff --git a/ffnet.py b/ffnet.py index faf7b33..4ea3011 100644 --- a/ffnet.py +++ b/ffnet.py @@ -18,6 +18,7 @@ import BeautifulSoup as bs import htmlentitydefs as hdefs from constants import * +from adapter import * try: import login_password @@ -25,7 +26,7 @@ except: # tough luck pass -class FFNet: +class FFNet(FanfictionSiteAdapter): def __init__(self, url): self.url = url parsedUrl = up.urlparse(url) diff --git a/ficwad.py b/ficwad.py index 23622c2..35b3b76 100644 --- a/ficwad.py +++ b/ficwad.py @@ -10,7 +10,9 @@ import urlparse as up import BeautifulSoup as bs import htmlentitydefs as hdefs -class FicWad: +from adapter import * + +class FicWad(FanfictionSiteAdapter): def __init__(self, url): self.url = url self.host = up.urlparse(url).netloc @@ -90,7 +92,7 @@ if __name__ == '__main__': url = 'http://www.ficwad.com/story/14536' data = u2.urlopen(url).read() host = up.urlparse(url).netloc - fw = FicWad() - urls = fw.extractIndividualUrls(data, host, url) + fw = FicWad(url) + urls = fw.extractIndividualUrls() pp.pprint(urls) print(fw.getText(data)) \ No newline at end of file