Compare commits

..

No commits in common. "9815794a9712087ea985a3cf427be90751a7aff8" and "2fe3e0b8ee15ac99025f1e4ebca8b147f97be1e1" have entirely different histories.

4 changed files with 19 additions and 25 deletions

View File

@ -221,7 +221,7 @@ class GZIPHandler(BaseHandler):
def detect_encoding(data, resp=None): def detect_encoding(data, resp=None):
enc = detect_raw_encoding(data, resp) enc = detect_raw_encoding(data, resp)
if enc.lower() == 'gb2312': if enc == 'gb2312':
enc = 'gbk' enc = 'gbk'
return enc return enc
@ -261,10 +261,14 @@ class EncodingFixHandler(BaseHandler):
if 200 <= resp.code < 300 and maintype == 'text': if 200 <= resp.code < 300 and maintype == 'text':
data = resp.read() data = resp.read()
enc = self.encoding or detect_encoding(data, resp) if not self.encoding:
enc = detect_encoding(data, resp)
else:
enc = self.encoding
data = data.decode(enc, 'replace') if enc:
data = data.encode(enc) data = data.decode(enc, 'replace')
data = data.encode(enc)
fp = BytesIO(data) fp = BytesIO(data)
old_resp = resp old_resp = resp
@ -651,8 +655,5 @@ class MySQLCacheHandler(BaseCache):
if __name__ == '__main__': if __name__ == '__main__':
req = adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://morss.it') req = adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://morss.it')
if sys.flags.interactive: if not sys.flags.interactive:
print('>>> Interactive shell: try using `req`')
else:
print(req['data'].decode(req['encoding'])) print(req['data'].decode(req['encoding']))

View File

@ -780,9 +780,6 @@ if __name__ == '__main__':
req = crawler.adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://www.nytimes.com/', follow='rss') req = crawler.adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://www.nytimes.com/', follow='rss')
feed = parse(req['data'], url=req['url'], encoding=req['encoding']) feed = parse(req['data'], url=req['url'], encoding=req['encoding'])
if sys.flags.interactive: if not sys.flags.interactive:
print('>>> Interactive shell: try using `feed`')
else:
for item in feed.items: for item in feed.items:
print(item.title, item.link) print(item.title, item.link)

View File

@ -351,8 +351,5 @@ if __name__ == '__main__':
req = crawler.adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://morss.it') req = crawler.adv_get(sys.argv[1] if len(sys.argv) > 1 else 'https://morss.it')
article = get_article(req['data'], url=req['url'], encoding_in=req['encoding'], encoding_out='unicode') article = get_article(req['data'], url=req['url'], encoding_in=req['encoding'], encoding_out='unicode')
if sys.flags.interactive: if not sys.flags.interactive:
print('>>> Interactive shell: try using `article`')
else:
print(article) print(article)

View File

@ -33,8 +33,7 @@
} }
header { header {
text-align: justify; text-align: center;
text-align-last: center;
border-bottom: 1px solid silver; border-bottom: 1px solid silver;
} }
@ -113,6 +112,7 @@
} }
header > form { header > form {
text-align: center;
margin: 1%; margin: 1%;
} }
@ -176,7 +176,7 @@
<select> <select>
<option value="">full-text</option> <option value="">full-text</option>
<option value=":proxy">original</option> <option value=":proxy">original</option>
<option value=":clip" title="original + full-text: keep the original description above the full article. Useful for reddit feeds for example, to keep the comment links">combined (?)</option> <option value=":clip">original + full-text</option>
</select> </select>
feed as feed as
<select> <select>
@ -185,12 +185,12 @@
<option value=":html">HTML</option> <option value=":html">HTML</option>
<option value=":csv">CSV</option> <option value=":csv">CSV</option>
</select> </select>
using the using
<select> <select>
<option value="">standard</option> <option value="">the standard link</option>
<option value=":firstlink" title="Pull the article from the first available link in the description, instead of the standard link. Useful for Twitter feeds for example, to get the articles referred to in tweets rather than the tweet itself">first (?)</option> <option value=":firstlink" title="Useful for Twitter feeds for example, to get the articles referred to in tweets rather than the tweet itself">the first link from the description (?)</option>
</select> </select>
link and and
<select> <select>
<option value="">keep</option> <option value="">keep</option>
<option value=":nolink:noref">remove</option> <option value=":nolink:noref">remove</option>
@ -199,8 +199,7 @@
<input type="hidden" value="" name="extra_options"/> <input type="hidden" value="" name="extra_options"/>
</form> </form>
<p>You can find a <em>preview</em> of the feed below. You need a <em>feed reader</em> for optimal use</p> <p>Click <a href="/">here</a> to go back to morss</p>
<p>Click <a href="/">here</a> to go back to morss and/or to use the tool on another feed</p>
</header> </header>
<div id="header" dir="auto"> <div id="header" dir="auto">