mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2026-05-05 19:11:50 +02:00
C
This should be bette
This commit is contained in:
parent
e4d5b61ef6
commit
ec6873f95f
2 changed files with 30 additions and 44 deletions
|
|
@ -165,7 +165,7 @@ class DeviantArtComSiteAdapter(BaseSiteAdapter):
|
|||
try:
|
||||
self.story.setMetadata('datePublished', makeDate(pubdate, '%b %d, %Y'))
|
||||
except:
|
||||
self.story.setMetadata('datePublished', makeDate(str(parse_relative_date_string(pubdate)), '%b %d, %Y'))
|
||||
self.story.setMetadata('datePublished', parse_relative_date_string(pubdate), '%b %d, %Y')
|
||||
|
||||
# do description here if appropriate
|
||||
|
||||
|
|
|
|||
|
|
@ -67,54 +67,40 @@ def parse_relative_date_string(reldatein):
|
|||
m = re.match(relrexp,reldatein)
|
||||
|
||||
# If the date is displayed as Yesterday
|
||||
if "Yesterday" in reldatein:
|
||||
value = unicode(int(1))
|
||||
unit = 'days'
|
||||
logger.debug("val:%s unit_string:%s unit:%s"%(value, unit, unit))
|
||||
if unit:
|
||||
kwargs = {unit: int(value)}
|
||||
|
||||
# "naive" dates without hours and seconds are created in
|
||||
# writers.base_writer.writeStory(), so we don't have to strip
|
||||
# hours and minutes from the base date. Using datetime objects
|
||||
# would result in a slightly different time (since we calculate
|
||||
# the last updated date based on the current time) during each
|
||||
# update, since the seconds and hours change.
|
||||
today = datetime.utcnow()
|
||||
time_ago = timedelta(**kwargs)
|
||||
date = today - time_ago
|
||||
|
||||
return date.strftime("%b %d, %Y")
|
||||
elif "just now" in reldatein:
|
||||
return datetime.utcnow().strftime("%b %d, %Y")
|
||||
|
||||
value=None # We could set this to 0 so we dont have to check for "just now"
|
||||
if m:
|
||||
value = m.group('val')
|
||||
unit_string = m.group('unit')
|
||||
elif "Yesterday" in reldatein:
|
||||
value = 1
|
||||
unit_string = 'days'
|
||||
elif "just now" in reldatein:
|
||||
value = 0
|
||||
unit_string = 'days'
|
||||
|
||||
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
|
||||
## that considers '2 years ago' an acceptable time stamp.
|
||||
if "year" in unit_string or unit and ('year' in unit):
|
||||
value = unicode(int(value)*365)
|
||||
unit = 'days'
|
||||
elif "month" in unit_string or unit and ('month' in unit):
|
||||
value = unicode(int(value)*31)
|
||||
unit = 'days'
|
||||
logger.debug("val:%s unit_string:%s unit:%s"%(value, unit_string, unit))
|
||||
if unit:
|
||||
kwargs = {unit: int(value)}
|
||||
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
|
||||
## that considers '2 years ago' an acceptable time stamp.
|
||||
if "year" in unit_string or unit and ('year' in unit):
|
||||
value = unicode(int(value)*365)
|
||||
unit = 'days'
|
||||
elif "month" in unit_string or unit and ('month' in unit):
|
||||
value = unicode(int(value)*31)
|
||||
unit = 'days'
|
||||
logger.debug("val:%s unit_string:%s unit:%s"%(value, unit_string, unit))
|
||||
if unit:
|
||||
kwargs = {unit: int(value)}
|
||||
|
||||
# "naive" dates without hours and seconds are created in
|
||||
# writers.base_writer.writeStory(), so we don't have to strip
|
||||
# hours and minutes from the base date. Using datetime objects
|
||||
# would result in a slightly different time (since we calculate
|
||||
# the last updated date based on the current time) during each
|
||||
# update, since the seconds and hours change.
|
||||
today = datetime.utcnow()
|
||||
time_ago = timedelta(**kwargs)
|
||||
return today - time_ago
|
||||
# "naive" dates without hours and seconds are created in
|
||||
# writers.base_writer.writeStory(), so we don't have to strip
|
||||
# hours and minutes from the base date. Using datetime objects
|
||||
# would result in a slightly different time (since we calculate
|
||||
# the last updated date based on the current time) during each
|
||||
# update, since the seconds and hours change.
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in a new issue