Skip to content

Commit 3cb0f4b

Browse files
committed
pep8
1 parent 7261316 commit 3cb0f4b

19 files changed

Lines changed: 418 additions & 625 deletions

goose/Configuration.py

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,49 @@
2020
See the License for the specific language governing permissions and
2121
limitations under the License.
2222
"""
23+
24+
2325
class Configuration(object):
24-
26+
2527
def __init__(self):
2628
# this is the local storage path used to place
2729
# images to inspect them, should be writable
2830
self.localStoragePath = "/tmp/goosetmp"
29-
31+
3032
# What's the minimum bytes for an image we'd accept is,
3133
# alot of times we want to filter out the author's little images
3234
# in the beginning of the article
3335
self.minBytesForImages = 4500
34-
36+
3537
# set this guy to false if you don't care about getting images,
3638
# otherwise you can either use the default
3739
# image extractor to implement the ImageExtractor
3840
# interface to build your own
3941
self.enableImageFetching = True
40-
42+
4143
# path to your imagemagick convert executable,
4244
# on the mac using mac ports this is the default listed
4345
self.imagemagickConvertPath = "/opt/local/bin/convert"
44-
46+
4547
# path to your imagemagick identify executable
4648
self.imagemagickIdentifyPath = "/opt/local/bin/identify"
47-
49+
4850
# used as the user agent that
4951
# is sent with your web requests to extract an article
5052
# self.browserUserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2)"\
5153
# " AppleWebKit/534.52.7 (KHTML, like Gecko) "\
5254
# "Version/5.1.2 Safari/534.52.7"
5355
self.browserUserAgent = 'Goose/1.0'
54-
56+
5557
# TODO
5658
self.publishDateExtractor = None
57-
59+
5860
# TODO
5961
self.additionalDataExtractor = None
60-
61-
62+
6263
def getPublishDateExtractor(self):
6364
return self.publishDateExtractor
64-
65+
6566
def setPublishDateExtractor(self, extractor):
6667
"""\
6768
Pass in to extract article publish dates.
@@ -70,10 +71,10 @@ def setPublishDateExtractor(self, extractor):
7071
if not extractor:
7172
raise ValueError("extractor must not be null!")
7273
self.publishDateExtractor = extractor
73-
74+
7475
def getAdditionalDataExtractor(self):
7576
return self.additionalDataExtractor
76-
77+
7778
def setAdditionalDataExtractor(self, extractor):
7879
"""\
7980
Pass in to extract any additional data not defined within
@@ -82,5 +83,3 @@ def setAdditionalDataExtractor(self, extractor):
8283
if not extractor:
8384
raise ValueError("extractor must not be null!")
8485
self.additionalDataExtractor = extractor
85-
86-

goose/Crawler.py

Lines changed: 19 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -31,37 +31,36 @@
3131
from goose.images.UpgradedImageExtractor import UpgradedImageIExtractor
3232
from goose.network import HtmlFetcher
3333

34+
3435
class CrawlCandidate(object):
35-
36+
3637
def __init__(self, config, url, rawHTML):
3738
self.config = config
3839
self.url = url
3940
self.rawHTML = rawHTML
4041

4142

42-
4343
class Crawler(object):
44-
44+
4545
def __init__(self, config):
4646
self.config = config
4747
self.logPrefix = "crawler:"
48-
48+
4949
def crawl(self, crawlCandidate):
5050
article = Article()
51-
51+
5252
parseCandidate = URLHelper.getCleanedUrl(crawlCandidate.url)
5353
rawHtml = self.getHTML(crawlCandidate, parseCandidate)
54-
54+
5555
if rawHtml is None:
5656
return article
57-
57+
5858
doc = self.getDocument(parseCandidate.url, rawHtml)
59-
60-
59+
6160
extractor = self.getExtractor()
6261
docCleaner = self.getDocCleaner()
6362
outputFormatter = self.getOutputFormatter()
64-
63+
6564
# article
6665
article.finalUrl = parseCandidate.url
6766
article.linkhash = parseCandidate.linkhash
@@ -81,7 +80,7 @@ def crawl(self, crawlCandidate):
8180
article.tags = extractor.extractTags(article)
8281
# # before we do any calcs on the body itself let's clean up the document
8382
article.doc = docCleaner.clean(article)
84-
83+
8584
# big stuff
8685
article.topNode = extractor.calculateBestNodeBasedOnClustering(article)
8786
if article.topNode is not None:
@@ -91,43 +90,37 @@ def crawl(self, crawlCandidate):
9190
if self.config.enableImageFetching:
9291
imageExtractor = self.getImageExtractor(article)
9392
article.topImage = imageExtractor.getBestImage(article.rawDoc, article.topNode)
94-
93+
9594
article.topNode = extractor.postExtractionCleanup(article.topNode)
9695
article.cleanedArticleText = outputFormatter.getFormattedText(article.topNode)
97-
96+
9897
return article
99-
98+
10099
def getHTML(self, crawlCandidate, parsingCandidate):
101100
if crawlCandidate.rawHTML:
102101
return crawlCandidate.rawHTML
103102
else:
104103
# fetch HTML
105104
html = HtmlFetcher().getHtml(self.config, parsingCandidate.url)
106105
return html
107-
108-
106+
109107
def getImageExtractor(self, article):
110108
httpClient = None
111109
return UpgradedImageIExtractor(httpClient, article, self.config)
112-
113-
110+
114111
def getOutputFormatter(self):
115112
return StandardOutputFormatter()
116-
117-
113+
118114
def getDocCleaner(self):
119115
return StandardDocumentCleaner()
120-
121-
116+
122117
def getDocument(self, url, rawHtml):
123118
doc = Parser.fromstring(rawHtml)
124119
return doc
125-
126-
120+
127121
def getExtractor(self):
128122
return StandardContentExtractor()
129-
130-
123+
131124
def releaseResources(self, article):
132125
directory = self.config.localStoragePath
133126
for fname in os.listdir(directory):
@@ -137,7 +130,3 @@ def releaseResources(self, article):
137130
except OSError:
138131
# TODO better log handeling
139132
pass
140-
141-
142-
143-

goose/Goose.py

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,43 @@
2525
from goose.Crawler import CrawlCandidate
2626
from goose.Crawler import Crawler
2727

28+
2829
class Goose(object):
2930
"""\
30-
31+
3132
"""
3233
def __init__(self, config=None):
3334
self.config = config or Configuration()
3435
self.initializeEnvironment()
35-
36-
36+
3737
def extractContent(self, url=None, rawHTML=None):
3838
"""\
3939
Main method to extract an article object from a URL,
4040
pass in a url and get back a Article
4141
"""
4242
cc = CrawlCandidate(self.config, url, rawHTML)
4343
return self.sendToActor(cc)
44-
45-
44+
4645
def shutdownNetwork(self):
4746
pass
48-
49-
47+
5048
def sendToActor(self, crawlCandiate):
5149
crawler = Crawler(self.config)
5250
article = crawler.crawl(crawlCandiate)
5351
return article
54-
55-
52+
5653
def initializeEnvironment(self):
5754
# test if config.localStoragePath
5855
# is a directory
5956
if not os.path.isdir(self.config.localStoragePath):
6057
os.makedirs(self.config.localStoragePath)
61-
58+
6259
if not os.path.isdir(self.config.localStoragePath):
6360
raise Exception(self.config.localStoragePath +
6461
" directory does not seem to exist, "
6562
"you need to set this for image processing downloads"
6663
)
67-
64+
6865
# test to write a dummy file to the directory
6966
# to check is directory is writtable
7067
path = '%s/test.txt' % self.config.localStoragePath
@@ -77,7 +74,3 @@ def initializeEnvironment(self):
7774
" directory is not writeble, "
7875
"you need to set this for image processing downloads"
7976
)
80-
81-
82-
83-

goose/Video.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
limitations under the License.
2222
"""
2323

24+
2425
class Video(object):
25-
26+
2627
def __init_(self):
27-
pass
28+
pass

0 commit comments

Comments
 (0)