From 436e8df4c978a48cdfbef8c66657989db1c61205 Mon Sep 17 00:00:00 2001 From: taizan-hokuto <55448286+taizan-hokuto@users.noreply.github.com> Date: Tue, 28 Jan 2020 22:36:53 +0900 Subject: [PATCH] Simplify getting timestamp --- pytchat/paramgen/arcparam.py | 1 - pytchat/paramgen/liveparam.py | 8 ++------ pytchat/processors/speed_calculator.py | 5 ++--- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/pytchat/paramgen/arcparam.py b/pytchat/paramgen/arcparam.py index 2ac64e0..e91ba74 100644 --- a/pytchat/paramgen/arcparam.py +++ b/pytchat/paramgen/arcparam.py @@ -1,6 +1,5 @@ from base64 import urlsafe_b64encode as b64enc from functools import reduce -import calendar, datetime, pytz import math import random import urllib.parse diff --git a/pytchat/paramgen/liveparam.py b/pytchat/paramgen/liveparam.py index 9965cfa..a091b11 100644 --- a/pytchat/paramgen/liveparam.py +++ b/pytchat/paramgen/liveparam.py @@ -1,6 +1,6 @@ from base64 import urlsafe_b64encode as b64enc from functools import reduce -import calendar, datetime, pytz +import time import random import urllib.parse @@ -141,11 +141,7 @@ def _build(video_id, _ts1, _ts2, _ts3, _ts4, _ts5, topchat_only): def _times(past_sec): - def unixts_now(): - now = datetime.datetime.now(pytz.utc) - return calendar.timegm(now.utctimetuple()) - - n = unixts_now() + n = int(time.time()) _ts1= n - random.uniform(0,1*3) _ts2= n - random.uniform(0.01,0.99) diff --git a/pytchat/processors/speed_calculator.py b/pytchat/processors/speed_calculator.py index 504762a..a3431b3 100644 --- a/pytchat/processors/speed_calculator.py +++ b/pytchat/processors/speed_calculator.py @@ -3,7 +3,7 @@ speed_calculator.py チャットの勢いを算出するChatProcessor Calculate speed of chat. """ -import calendar, datetime, pytz +import time from .chat_processor import ChatProcessor class RingQueue: """ @@ -143,8 +143,7 @@ class SpeedCalculator(ChatProcessor, RingQueue): ''' チャットデータがない場合に空のデータをキューに投入する。 ''' - timestamp_now = calendar.timegm(datetime.datetime. - now(pytz.utc).utctimetuple()) + timestamp_now = int(time.time()) self.put({ 'chat_count':0, 'starttime':int(timestamp_now),