Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
mtill committed Oct 7, 2013
1 parent 012f554 commit 399c6bb
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions MailWebsiteChanges.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,22 @@ def toAbsoluteURIs(trees, baseuri):
tag.attrib[uriAttribute[1]] = urllib.parse.urljoin(baseuri, tag.attrib[uriAttribute[1]])


def parseSite(uri, contenttype, contentxpath, titlexpath, contentregex, titleregex, enc):
def parseSite(site):
content, titles, warning = None, None, None

uri = site['uri']
contenttype = site.get('type', 'html')
contentregex = site.get('contentregex', '')
titleregex = site.get('titleregex', '')
enc = site.get('encoding', defaultEncoding)

contentxpath = site.get('contentxpath', '')
if contentxpath == '' and site.get('contentcss', '') != '':
contentxpath = GenericTranslator().css_to_xpath(site.get('contentcss'))
titlexpath = site.get('titlexpath', '')
if titlexpath == '' and site.get('titlecss', '') != '':
titlexpath = GenericTranslator().css_to_xpath(site.get('titlecss'))

try:
if contentxpath == '' and titlexpath == '':
file = urllib.request.urlopen(uri)
Expand Down Expand Up @@ -209,14 +222,7 @@ def pollWebsites():
for site in config.sites:

print('polling site [' + site['shortname'] + '] ...')
contentxpath = site.get('contentxpath', '')
if contentxpath == '' and site.get('contentcss'):
contentxpath = GenericTranslator().css_to_xpath(site.get('contentcss'))
titlexpath = site.get('titlexpath', '')
if titlexpath == '' and site.get('titlecss'):
titlexpath = GenericTranslator().css_to_xpath(site.get('titlecss'))

parseResult = parseSite(site['uri'], site.get('type', 'html'), contentxpath, titlexpath, site.get('contentregex', ''),site.get('titleregex', ''), site.get('encoding', defaultEncoding))
parseResult = parseSite(site)

if parseResult['warning']:
subject = '[' + site['shortname'] + '] WARNING'
Expand Down Expand Up @@ -280,14 +286,7 @@ def pollWebsites():
if dryrun:
for site in config.sites:
if site['shortname'] == dryrun:
contentxpath = site.get('contentxpath', '')
if contentxpath == '' and site.get('contentcss'):
contentxpath = GenericTranslator().css_to_xpath(site.get('contentcss'))
titlexpath = site.get('titlexpath', '')
if titlexpath == '' and site.get('titlecss'):
titlexpath = GenericTranslator().css_to_xpath(site.get('titlecss'))

parseResult = parseSite(site['uri'], site.get('type', 'html'), contentxpath, titlexpath, site.get('contentregex', ''),site.get('titleregex', ''), site.get('encoding', defaultEncoding))
parseResult = parseSite(site)
print(parseResult)
break
else:
Expand Down

0 comments on commit 399c6bb

Please sign in to comment.