mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Merge branch 'remove_utcnow' of https://github.com/salty-horse/calibre
This commit is contained in:
commit
1e2e2acc44
@ -5,7 +5,7 @@ __copyright__ = '2013-2015, Eddie Lau'
|
||||
__Date__ = ''
|
||||
|
||||
from calibre import (__appname__, force_unicode, strftime)
|
||||
from calibre.utils.date import now as nowf
|
||||
from calibre.utils.date import now as nowf, utcnow
|
||||
import os
|
||||
import datetime
|
||||
import re
|
||||
@ -43,7 +43,7 @@ class AppleDaily(BasicNewsRecipe):
|
||||
dict(name='link')]
|
||||
|
||||
def get_dtlocal(self):
|
||||
dt_utc = datetime.datetime.utcnow()
|
||||
dt_utc = utcnow()
|
||||
# convert UTC to local hk time - at HKT 6am, all news are available
|
||||
return dt_utc + datetime.timedelta(8.0 / 24) - datetime.timedelta(6.0 / 24)
|
||||
|
||||
|
@ -16,7 +16,7 @@ from collections import OrderedDict
|
||||
from calibre.web.feeds.recipes import BasicNewsRecipe
|
||||
from calibre.utils.cleantext import clean_ascii_chars
|
||||
from calibre.ebooks.BeautifulSoup import NavigableString
|
||||
from calibre.utils.date import dt_factory, local_tz
|
||||
from calibre.utils.date import dt_factory, local_tz, utcfromtimestamp
|
||||
|
||||
regex_date_only = re.compile(r"""(?:January|February|March|April|
|
||||
{8}May|June|July|August|September|October|November|
|
||||
@ -216,7 +216,7 @@ class HoustonChronicle(BasicNewsRecipe):
|
||||
summary = self.get_article_description_from_doc(soup)
|
||||
article_date = self.get_published_time_from_doc(soup)
|
||||
if article_date is not None:
|
||||
article_timestamp = float((article_date - datetime.utcfromtimestamp(0)).total_seconds())
|
||||
article_timestamp = float((article_date - utcfromtimestamp(0)).total_seconds())
|
||||
article.date = article_timestamp
|
||||
article.utctime = dt_factory(article_date.timetuple(), assume_utc=True, as_utc=True)
|
||||
article.localtime = article.utctime.astimezone(local_tz)
|
||||
|
@ -182,9 +182,8 @@ class SCMP(BasicNewsRecipe):
|
||||
body = v
|
||||
|
||||
authors = [content_service[a["id"]]["name"] for a in content["authors"]]
|
||||
date_published = datetime.utcfromtimestamp(
|
||||
content["publishedDate"] / 1000
|
||||
).replace(tzinfo=timezone.utc)
|
||||
date_published = datetime.fromtimestamp(
|
||||
content["publishedDate"] / 1000, timezone.utc)
|
||||
date_published_loc = date_published.astimezone(
|
||||
timezone(offset=timedelta(hours=8)) # HK time
|
||||
)
|
||||
|
@ -26,7 +26,7 @@ Change Log:
|
||||
2011/12/29 -- first version done
|
||||
'''
|
||||
|
||||
from calibre.utils.date import now as nowf
|
||||
from calibre.utils.date import now as nowf, utcnow
|
||||
import os
|
||||
import datetime
|
||||
import re
|
||||
@ -82,7 +82,7 @@ class STHKRecipe(BasicNewsRecipe):
|
||||
auto_cleanup = False
|
||||
|
||||
def get_dtlocal(self):
|
||||
dt_utc = datetime.datetime.utcnow()
|
||||
dt_utc = utcnow()
|
||||
# convert UTC to local hk time - at HKT 4.00am, all news are available
|
||||
dt_local = dt_utc + \
|
||||
datetime.timedelta(8.0 / 24) - datetime.timedelta(4.0 / 24)
|
||||
|
@ -14,6 +14,7 @@ szmobil.sueddeutsche.de/
|
||||
|
||||
from calibre import strftime
|
||||
import datetime
|
||||
from calibre.utils.date import utcnow
|
||||
from calibre.web.feeds.recipes import BasicNewsRecipe
|
||||
import re
|
||||
|
||||
@ -28,7 +29,7 @@ class SZmobil(BasicNewsRecipe):
|
||||
publication_type = u'newspaper'
|
||||
category = u'news, politics, Germany'
|
||||
cover_url = 'https://zeitung.sueddeutsche.de/szdigital/public/issue/previewimage?size=l&issueId=' + \
|
||||
(datetime.datetime.utcnow() + datetime.timedelta(hours=1)
|
||||
(utcnow() + datetime.timedelta(hours=1)
|
||||
).strftime("%Y-%m-%d") + '&targetVersion=3&productId=sz'
|
||||
no_stylesheets = True
|
||||
oldest_article = 2
|
||||
|
@ -11,6 +11,7 @@ www.sueddeutsche.de/sz/
|
||||
from calibre.web.feeds.news import BasicNewsRecipe
|
||||
from calibre import strftime
|
||||
import datetime
|
||||
from calibre.utils.date import utcnow
|
||||
|
||||
|
||||
class SueddeutcheZeitung(BasicNewsRecipe):
|
||||
@ -26,7 +27,7 @@ class SueddeutcheZeitung(BasicNewsRecipe):
|
||||
remove_empty_feeds = True
|
||||
delay = 1
|
||||
cover_url = 'https://zeitung.sueddeutsche.de/szdigital/public/issue/previewimage?size=l&issueId=' + \
|
||||
(datetime.datetime.utcnow() + datetime.timedelta(hours=1)
|
||||
(utcnow() + datetime.timedelta(hours=1)
|
||||
).strftime("%Y-%m-%d") + '&targetVersion=3&productId=sz'
|
||||
PREFIX = 'http://epaper.sueddeutsche.de'
|
||||
INDEX = PREFIX + '/app/epaper/textversion/'
|
||||
|
@ -5,7 +5,7 @@
|
||||
import bz2
|
||||
import os
|
||||
import sys
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from urllib.request import urlopen
|
||||
|
||||
|
||||
@ -49,7 +49,7 @@ def get_data():
|
||||
ans = {
|
||||
'common_user_agents': common,
|
||||
'user_agents_popularity': ua_freq_map,
|
||||
'timestamp': datetime.utcnow().isoformat() + '+00:00',
|
||||
'timestamp': datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
ans['desktop_platforms'] = list(all_desktop_platforms(ans['common_user_agents']))
|
||||
return ans
|
||||
|
@ -437,7 +437,7 @@ def fetch_plugins(old_index):
|
||||
else:
|
||||
if entry.name in old_index:
|
||||
ans[entry.name] = old_index[entry.name]
|
||||
log('Failed to get plugin', entry.name, 'at', datetime.utcnow().isoformat(), 'with error:')
|
||||
log('Failed to get plugin', entry.name, 'at', datetime.now().isoformat(), 'with error:')
|
||||
log(plugin)
|
||||
# Move staged files
|
||||
for plugin in ans.values():
|
||||
@ -646,7 +646,7 @@ def main():
|
||||
raise SystemExit('Exiting on user interrupt')
|
||||
except Exception:
|
||||
import traceback
|
||||
log('Failed to run at:', datetime.utcnow().isoformat())
|
||||
log('Failed to run at:', datetime.now().isoformat())
|
||||
log(traceback.format_exc())
|
||||
raise SystemExit(1)
|
||||
|
||||
|
@ -104,7 +104,7 @@ def parse_date(date_string, assume_utc=False, as_utc=True, default=None):
|
||||
if isinstance(date_string, bytes):
|
||||
date_string = date_string.decode(preferred_encoding, 'replace')
|
||||
if default is None:
|
||||
func = datetime.utcnow if assume_utc else datetime.now
|
||||
func = utcnow if assume_utc else now
|
||||
default = func().replace(day=15, hour=0, minute=0, second=0, microsecond=0,
|
||||
tzinfo=_utc_tz if assume_utc else _local_tz)
|
||||
if iso_pat().match(date_string) is not None:
|
||||
@ -190,10 +190,7 @@ def qt_from_dt(d, as_utc=False, assume_utc=False):
|
||||
|
||||
|
||||
def fromtimestamp(ctime, as_utc=True):
|
||||
dt = datetime.utcfromtimestamp(ctime).replace(tzinfo=_utc_tz)
|
||||
if not as_utc:
|
||||
dt = dt.astimezone(_local_tz)
|
||||
return dt
|
||||
return datetime.fromtimestamp(ctime, _utc_tz if as_utc else _local_tz)
|
||||
|
||||
|
||||
def fromordinal(day, as_utc=True):
|
||||
@ -250,16 +247,16 @@ def as_utc(date_time, assume_utc=True):
|
||||
|
||||
|
||||
def now():
|
||||
return datetime.now().replace(tzinfo=_local_tz)
|
||||
return datetime.now(_local_tz)
|
||||
|
||||
|
||||
def utcnow():
|
||||
return datetime.utcnow().replace(tzinfo=_utc_tz)
|
||||
return datetime.now(_utc_tz)
|
||||
|
||||
|
||||
def utcfromtimestamp(stamp):
|
||||
try:
|
||||
return datetime.utcfromtimestamp(stamp).replace(tzinfo=_utc_tz)
|
||||
return datetime.fromtimestamp(stamp, _utc_tz)
|
||||
except Exception:
|
||||
# Raised if stamp is out of range for the platforms gmtime function
|
||||
# For example, this happens with negative values on windows
|
||||
|
Loading…
x
Reference in New Issue
Block a user