Skip to content

Commit

Permalink
null handling in format_readerposts -- closes #539
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazel Shanks committed Sep 6, 2020
1 parent 4b16d3b commit 8844a8f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions fanficfare/adapters/adapter_fictionlive.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def getSiteExampleURLs(cls):
"https://fiction.live/stories/Example-Story-With-UUID/00000000-0000-4000-0000-000000000000/"]

def parse_timestamp(self, timestamp):
# fiction.live date format is unix-epoch milliseconds. not a good fit for fanficfare's dateformat.
# fiction.live date format is unix-epoch milliseconds. not a good fit for fanficfare's makeDate.
# doesn't use a timezone object and returns tz-naive datetimes. I *think* I can leave the rest to fanficfare
return datetime.fromtimestamp(timestamp / 1000.0, None)

Expand Down Expand Up @@ -232,7 +232,9 @@ def getChapterText(self, url):

text = ""

for chunk in data:
for count, chunk in enumerate(data):
#logger.debug("chunk #{i}".format(i=count)) # helps to locate problem chunks in long chapters

text += "<div>" # chapter chunks aren't always well-delimited in their contents

# so appendix chunks just turn up wherever
Expand Down Expand Up @@ -414,14 +416,18 @@ def format_readerposts(self, chunk):
if dice != {}:
for uid, roll in dice.items():
output += '<div class="choiceitem">'
output += '<div class="dice">' + roll + '</div>\n'
if uid in posts:
output += posts[uid]
if roll: # optional. just because there's a list entry for it doesn't mean it has a value!
output += '<div class="dice">' + roll + '</div>\n'
if uid in posts:
post = posts[uid]
if post:
output += post
del posts[uid] # it's handled here with the roll instead of later
output += '</div>'

for post in posts.values():
output += '<div class="choiceitem">' + post + '</div>\n'
if post:
output += '<div class="choiceitem">' + post + '</div>\n'

return output

Expand All @@ -440,3 +446,11 @@ def format_unknown(self, chunk):

# TODO: verify that show_timestamps is working, check times!

# TODO: find a story that uses achievement images and implement them

# TODO: sort out updates, somehow. 'update epub if new chapters' is an awful match for fiction.live
# where chunks get just dropped at the end of chapters, and chapter-bookmarking happens later.
# updating in 'overwrite always' or 'overwrite if newer' does the right thing, but.

# TODO: pagecache. In particular, if there's any way to update stories and *not* redownload images, that'd be great.

0 comments on commit 8844a8f

Please sign in to comment.