def render_tweet_html(tweet):
date_format = '%B %-d, %Y'
context = {
'body': process_tweet_text(tweet),
'date': date.fromtimestamp(tweet.created_at_in_seconds).strftime(date_format)
}
return jinja2.Environment(
loader=jinja2.FileSystemLoader('./')
).get_template('release_template.html').render(context)
python类fromtimestamp()的实例源码
def today():
"""Return the current local time.
This is equivalent to date.fromtimestamp(time.time())"""
def fromtimestamp(timestamp):
"""Return the local date from a POSIX timestamp (like time.time())
This may raise ValueError, if the timestamp is out of the range of
values supported by the platform C localtime() function. It's common
for this to be restricted to years from 1970 through 2038. Note that
on non-POSIX systems that include leap seconds in their notion of a
timestamp, leap seconds are ignored by fromtimestamp().
"""
def today():
"""Return the current local datetime, with tzinfo None.
This is equivalent to datetime.fromtimestamp(time.time()).
See also now(), fromtimestamp().
"""
def utcfromtimestamp(timestamp):
"""Return the UTC datetime from the POSIX timestamp with tzinfo None.
This may raise ValueError, if the timestamp is out of the range of
values supported by the platform C gmtime() function. It's common for
this to be restricted to years in 1970 through 2038.
See also fromtimestamp().
"""
def __init__(self, name, group, ds_id, start_time, end_time, data):
super(PopulationTimeline, self).__init__({
'name': name,
'group': group,
'data_source_id': ds_id,
'start_time': start_time,
'end_time': end_time,
'data': [(date.fromtimestamp(x[0]/1000), x[1]) for x in data]
})
def cacheForFuture(self, headers):
ten_years = 315569260
headers.setRawHeaders("Cache-Control",["max-age={}".format(ten_years)])
headers.setRawHeaders("Last-Modified",["Mon, 29 Jun 1998 02:28:12 GMT"]) # it was modifed long ago, so is most likely fresh
in_ten_years = date.fromtimestamp(time.time() + ten_years)
headers.setRawHeaders("Expires",[in_ten_years.strftime("%a, %d %b %Y %H:%M:%S GMT")])
def cacheForFuture(self, headers):
ten_years = 315569260
headers.setRawHeaders("Cache-Control",["max-age={}".format(ten_years)])
headers.setRawHeaders("Last-Modified",["Mon, 29 Jun 1998 02:28:12 GMT"]) # it was modifed long ago, so is most likely fresh
in_ten_years = date.fromtimestamp(time.time() + ten_years)
headers.setRawHeaders("Expires",[in_ten_years.strftime("%a, %d %b %Y %H:%M:%S GMT")])
def cacheForFuture(self, headers):
ten_years = 315569260
headers.setRawHeaders("Cache-Control",["max-age="+str(ten_years)])
headers.setRawHeaders("Last-Modified",["Mon, 29 Jun 1998 02:28:12 GMT"]) # it was modifed long ago, so is most likely fresh
in_ten_years = date.fromtimestamp(time.time() + ten_years)
headers.setRawHeaders("Expires",[in_ten_years.strftime("%a, %d %b %Y %H:%M:%S GMT")])
def available_data_range(self, frequency):
if frequency != 'tick':
raise NotImplementedError
s = date.today()
e = date.fromtimestamp(2147483647)
return s, e
def get_after(self, timestamp, s=None):
"""
Find all the (available) logs that are after the given time stamp.
Override this function in class LogFileOutput.
Parameters:
timestamp(datetime.datetime): lines before this time are ignored.
s(str or list): one or more strings to search for.
If not supplied, all available lines are searched.
Yields:
(dict): the parsed data of lines with timestamps after this date in the
same format they were supplied.
"""
search_by_expression = self._valid_search(s)
for line in self.lines:
# If `s` is not None, keywords must be found in the line
if s and not search_by_expression(line):
continue
info = self._parse_line(line)
try:
logtime = date.fromtimestamp(float(info.get('timestamp', 0)))
if logtime > timestamp:
yield info
except:
pass
def today():
"""Return the current local time.
This is equivalent to date.fromtimestamp(time.time())"""
def fromtimestamp(timestamp):
"""Return the local date from a POSIX timestamp (like time.time())
This may raise ValueError, if the timestamp is out of the range of
values supported by the platform C localtime() function. It's common
for this to be restricted to years from 1970 through 2038. Note that
on non-POSIX systems that include leap seconds in their notion of a
timestamp, leap seconds are ignored by fromtimestamp().
"""
def today():
"""Return the current local datetime, with tzinfo None.
This is equivalent to datetime.fromtimestamp(time.time()).
See also now(), fromtimestamp().
"""
def utcfromtimestamp(timestamp):
"""Return the UTC datetime from the POSIX timestamp with tzinfo None.
This may raise ValueError, if the timestamp is out of the range of
values supported by the platform C gmtime() function. It's common for
this to be restricted to years in 1970 through 2038.
See also fromtimestamp().
"""
def load_file(guid):
file = None
try:
file = get_box_store().getNote(dev_token, guid, True, True, False, False)
except Exception, e:
return None
file_content = parse_file(file.content)
return {
'title': file.title,
'content': base64.b64decode(file_content + '=' * (-len(file_content) % 4)),
'created': date.fromtimestamp(file.created / 100).strftime('%d/%m/%Y')
}
def datetime_format(time):
return datetime.fromtimestamp(int(str(time)[:-3])).strftime('%Y-%m-%d %H:%M:%S')
def message(request):
json_str = ((request.body).decode('utf-8'))
received_json_data = json.loads(json_str)
meal = received_json_data['content']
daystring = ["?", "?", "?", "?", "?", "?", "?"]
today = datetime.datetime.today().weekday()
nextdaystring = ["?", "?", "?", "?", "?", "?", "?"]
today_date = datetime.date.today().strftime("%m? %d? ")
tomorrow_date = date.fromtimestamp(time.time() + 60 * 60 * 24).strftime("%m? %d? ")
if meal == '??' or meal == '??' or meal == '??':
return JsonResponse({
'message': {
'text': today_date + daystring[today] + '?? ' + meal + ' ?????. \n \n' + crawl(request)
},
'keyboard': {
'type': 'buttons',
'buttons': ['??', '??', '??', '??? ??', '??? ??', '??? ??']
}
})
if meal == '??? ??' or meal == '??? ??' or meal == '??? ??':
return JsonResponse({
'message': {
'text': '[' + meal + '] \n' + tomorrow_date + nextdaystring[today] + '?? ?? ?????. \n \n' + crawl(request)
},
'keyboard': {
'type': 'buttons',
'buttons': ['??', '??', '??', '??? ??', '??? ??', '??? ??']
}
})
# message ?? ??? ??? ??
def cacheForFuture(self, headers):
ten_years = 315569260
headers.setRawHeaders("Cache-Control",["max-age={}".format(ten_years)])
headers.setRawHeaders("Last-Modified",["Mon, 29 Jun 1998 02:28:12 GMT"]) # it was modifed long ago, so is most likely fresh
in_ten_years = date.fromtimestamp(time.time() + ten_years)
headers.setRawHeaders("Expires",[in_ten_years.strftime("%a, %d %b %Y %H:%M:%S GMT")])
def cacheForFuture(self, headers):
ten_years = 315569260
headers.setRawHeaders("Cache-Control",["max-age="+str(ten_years)])
headers.setRawHeaders("Last-Modified",["Mon, 29 Jun 1998 02:28:12 GMT"]) # it was modifed long ago, so is most likely fresh
in_ten_years = date.fromtimestamp(time.time() + ten_years)
headers.setRawHeaders("Expires",[in_ten_years.strftime("%a, %d %b %Y %H:%M:%S GMT")])