Small code clean up
parent
399e867c94
commit
679628c7fa
1
main.py
1
main.py
|
@ -1,4 +1,5 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
from morss import main, cgi_wrapper as application
|
from morss import main, cgi_wrapper as application
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
|
@ -39,9 +39,11 @@ def get_rule(link):
|
||||||
for section in config.sections():
|
for section in config.sections():
|
||||||
values = dict(config.items(section))
|
values = dict(config.items(section))
|
||||||
values['path'] = values['path'].split('\n')[1:]
|
values['path'] = values['path'].split('\n')[1:]
|
||||||
|
|
||||||
for path in values['path']:
|
for path in values['path']:
|
||||||
if fnmatch(link, path):
|
if fnmatch(link, path):
|
||||||
return values
|
return values
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,6 +117,7 @@ def pre_worker(url):
|
||||||
|
|
||||||
class Builder(object):
|
class Builder(object):
|
||||||
def __init__(self, link, data, rule=None):
|
def __init__(self, link, data, rule=None):
|
||||||
|
# data must be a unicode string
|
||||||
|
|
||||||
self.link = link
|
self.link = link
|
||||||
self.data = data
|
self.data = data
|
||||||
|
@ -130,6 +133,7 @@ class Builder(object):
|
||||||
|
|
||||||
if self.rule['mode'] == 'xpath':
|
if self.rule['mode'] == 'xpath':
|
||||||
self.doc = lxml.html.fromstring(self.data)
|
self.doc = lxml.html.fromstring(self.data)
|
||||||
|
|
||||||
elif self.rule['mode'] == 'json':
|
elif self.rule['mode'] == 'json':
|
||||||
self.doc = json.loads(self.data)
|
self.doc = json.loads(self.data)
|
||||||
|
|
||||||
|
|
|
@ -562,8 +562,6 @@ def cgi_app(environ, start_response):
|
||||||
if not options.silent:
|
if not options.silent:
|
||||||
return out
|
return out
|
||||||
|
|
||||||
log('done')
|
|
||||||
|
|
||||||
|
|
||||||
def cgi_wrapper(environ, start_response):
|
def cgi_wrapper(environ, start_response):
|
||||||
# simple http server for html and css
|
# simple http server for html and css
|
||||||
|
|
Loading…
Reference in New Issue