forked from samuelclay/NewsBlur
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Text view. Needs a few tweaks and a premium only view.
- Loading branch information
1 parent
9303e3d
commit 36028cc
Showing
14 changed files
with
255 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import requests | ||
import zlib | ||
from django.conf import settings | ||
from vendor.readability import readability | ||
from utils import log as logging | ||
|
||
|
||
class TextImporter: | ||
|
||
def __init__(self, story, request=None): | ||
self.story = story | ||
self.request = request | ||
|
||
@property | ||
def headers(self): | ||
return { | ||
'User-Agent': 'NewsBlur Content Fetcher - %s ' | ||
'(Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_1) ' | ||
'AppleWebKit/534.48.3 (KHTML, like Gecko) Version/5.1 ' | ||
'Safari/534.48.3)' % ( | ||
settings.NEWSBLUR_URL | ||
), | ||
'Connection': 'close', | ||
} | ||
|
||
def fetch(self): | ||
html = requests.get(self.story.story_permalink, headers=self.headers) | ||
original_text_doc = readability.Document(html.text) | ||
content = original_text_doc.summary() | ||
if content: | ||
self.story.original_text_z = zlib.compress(content) | ||
self.story.save() | ||
logging.user(self.request, "~SN~FYFetched ~FGoriginal text~FY: now ~SB%s bytes~SN vs. was ~SB%s bytes" % ( | ||
len(unicode(content)), | ||
len(zlib.decompress(self.story.story_content_z)) | ||
)) | ||
else: | ||
logging.user(self.request, "~SN~FRFailed~FY to fetch ~FGoriginal text~FY: was ~SB%s bytes" % ( | ||
len(zlib.decompress(self.story.story_content_z)) | ||
)) | ||
|
||
return content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.