Skip to content

Commit

Permalink
Merge branch 'bugmaschine-main'
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmXinu committed Jan 23, 2023
2 parents 50c85d4 + 8545036 commit 5ce7aa5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
8 changes: 7 additions & 1 deletion fanficfare/adapters/adapter_deviantartcom.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from .base_adapter import BaseSiteAdapter, makeDate
from fanficfare.htmlcleanup import stripHTML
from .. import exceptions as exceptions
from fanficfare.dateutils import parse_relative_date_string

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -159,7 +160,12 @@ def extractChapterUrlsAndMetadata(self):
# self.story.setMetadata('status', 'Completed')

pubdate = soup.select_one('time').get_text()
self.story.setMetadata('datePublished', makeDate(pubdate, '%b %d, %Y'))

# Maybe do this better, but this works
try:
self.story.setMetadata('datePublished', makeDate(pubdate, '%b %d, %Y'))
except:
self.story.setMetadata('datePublished', parse_relative_date_string(pubdate))

# do description here if appropriate

Expand Down
12 changes: 11 additions & 1 deletion fanficfare/dateutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,19 @@ def parse_relative_date_string(reldatein):
# discards trailing ' ago' if present
m = re.match(relrexp,reldatein)

unit_string=None # use as a switch to do unit calc
# matches <number> <word>
if m:
value = m.group('val')
unit_string = m.group('unit')

# If the date is displayed as Yesterday
elif "Yesterday" in reldatein:
value = 1
unit_string = 'days'
elif "just now" in reldatein:
return datetime.utcnow()

if unit_string:
unit = unit_to_keyword.get(unit_string)
logger.debug("val:%s unit_string:%s unit:%s"%(value, unit_string, unit))
## I'm not going to worry very much about accuracy for a site
Expand All @@ -93,6 +102,7 @@ def parse_relative_date_string(reldatein):
today = datetime.utcnow()
time_ago = timedelta(**kwargs)
return today - time_ago

# This is "just as wrong" as always returning the current
# date, but prevents unneeded updates each time
logger.warning('Failed to parse relative date string: %r, falling back to unix epoche', reldatein)
Expand Down

0 comments on commit 5ce7aa5

Please sign in to comment.