Added adapter.py, now all working adapters must implement FanfictionSiteAdapter interface

This commit is contained in:
sigizmund 2009-12-17 15:16:51 +00:00
parent a01e0e2ed6
commit 59697f1a75
4 changed files with 39 additions and 5 deletions

30
adapter.py Normal file
View file

@ -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

3
ffa.py
View file

@ -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)

View file

@ -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)

View file

@ -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))