本文整理汇总了Python中arrow.Arrow.fromtimestamp方法的典型用法代码示例。如果您正苦于以下问题:Python Arrow.fromtimestamp方法的具体用法?Python Arrow.fromtimestamp怎么用?Python Arrow.fromtimestamp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arrow.Arrow
的用法示例。
在下文中一共展示了Arrow.fromtimestamp方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: user_action_stat
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import fromtimestamp [as 别名]
def user_action_stat(interval,user_out_name,song_out_name):
#统计用户三日的数据量
## step 1: 读入数据
base_time = 1426348800 #3-15-0-0-0的unix时间戳
base_time_stamp = Arrow.fromtimestamp(base_time)
interval_seconds = interval * 24 * 3600
parts = load_csv_as_dict('%s/data_source/%s' %(PROJECT_PATH,'mars_tianchi_user_actions.csv'))
user_dict = defaultdict(
lambda: defaultdict(lambda: defaultdict(lambda: 0.0))) # 默认dict的一个trick!
song_dict = defaultdict(lambda:defaultdict(lambda:defaultdict(lambda:0.0)))
count = 0
## step 2:统计数据
for part in parts:
user_id = part['user_id']
song_id = part['song_id']
action_type = part['action_type']
gmt_create = eval(part['gmt_create'])
date_interval_belong = int((Arrow.fromtimestamp(gmt_create) - base_time_stamp).total_seconds())/interval_seconds
user_dict[user_id][date_interval_belong][action_type] += 1
song_dict[song_id][date_interval_belong][action_type] += 1
count += 1
if count % 1000 == 0:
print 'statistical %s records' % count
print 'total users: %s' % len(user_dict)
print 'total songs: %s' % len(song_dict)
## step 3:写入到feature文件
fs = open('%s/feature/%s.csv' % (PROJECT_PATH,user_out_name),'w')
fs.write('user_id,date_interval_%s ,plays,downloads,favors\n' % interval)
count = 0
for user in user_dict:
date_dict = user_dict[user]
for date in date_dict:
action = date_dict[date]
fs.write('%s,%s,%s,%s,%s\n' % (user,date,action['1'],action['2'],action['3']))
count = count + 1
if count % 1000 == 0:
print 'write %s length' % count
fs.close()
print 'user_dict is write done'
fs = open('%s/feature/%s.csv' % (PROJECT_PATH,song_out_name),'w')
fs.write('song_id,date_interval_%s,plays,downloads,favors\n' % interval)
count = 0
for song in song_dict:
date_dict = song_dict[song]
for date in date_dict:
action = date_dict[date]
fs.write('%s,%s,%s,%s,%s\n' % (song,date,action['1'],action['2'],action['3']))
count += 1
if count % 1000 == 0:
print 'write %s length' % count
fs.close()
print 'song_dict is write done'
示例2: validate_token
# 需要导入模块: from arrow import Arrow [as 别名]
# 或者: from arrow.Arrow import fromtimestamp [as 别名]
def validate_token(token):
if not isinstance(token, str):
raise TypeError('token은 반드시 `str` 이여야합니다.')
secret_key = get_secret_key()
s = JSONWebSignatureSerializer(secret_key)
try:
data = s.loads(token.encode('utf-8'))
except BadSignature as e:
raise InvalidTokenError('잘못된 token입니다.')
expired_at = Arrow.fromtimestamp(data['expired_at'])
now = utcnow()
if expired_at < now:
raise ExpiredTokenError('만료된 token입니다.')
return data