Skip to content

Commit

Permalink
regex fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
nazunalika committed May 3, 2020
1 parent f42459f commit 9175319
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 2 additions & 6 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,5 @@ Changelog
chanfeed
--------

* Changed image link on imgur
* Removed unnecessary imports
* Removed unused @staticmethod functions
* Fixed some indentation issues according to pylint
* Increment version number

* Fix regex problem for post references going to invalid threads
* Added regex for cross-linking (board + board/thread)
8 changes: 7 additions & 1 deletion chanfeed/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ def format_post(
# CHOOSE A BETTER NAME MAYBE
reply = entry
board = self.url_splitter(reply.url)['board']
current_thread = self.url_splitter(reply.url)['thread']
# create vars for all relevant pieces of the embed
chanLogoImg = "https://i.imgur.com/qwj5bL2.png"
postTimestamp = time.strftime('%m/%d/%y (%a) %H:%M:%S', time.localtime(reply.timestamp))
Expand All @@ -245,8 +246,13 @@ def format_post(
posterTrip = reply.tripcode or ""
clearComment = reply.text_comment
thumbnailURL = reply.thumbnail_url
threadURL = 'https://boards.4chan.org/%s/thread/%s' % (board, posterID)
threadURL = 'https://boards.4chan.org/%s/thread/%s' % (board, current_thread)
content = re.sub(r'>{2}(\d+)', r'[>>\1](' + threadURL + r'#p\1)', clearComment)
# I want a better way of handling these at some point, but this is the
# closest I could get to for cross-linking. It may or may not be
# consistent. I may want to try conditionals since python supports it.
content = re.sub(r'>{3}(/[a-z0-9]+/(?!\d+))', r'[>>>\1](https://boards.4chan.org\1)', content)
content = re.sub(r'>{3}(/[a-z0-9]+/)(\d+)', r'[>>>\1\2](https://boards.4chan.org\1thread/\2)', content)
embedTitle = "%s %s %s" % (posterName, poster, posterTrip)
embedDesc = "No. [%s](%s)\r\r%s" % (posterID, postURL, content)

Expand Down

0 comments on commit 9175319

Please sign in to comment.