feat(heatmap): 计算昨日 status 数量并记录
计算昨日 status 数量并记录 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
ffb514da65
commit
5d271f43db
27
heatmap.py
27
heatmap.py
@ -7,6 +7,7 @@ from mastodon import Mastodon
|
|||||||
import pytz
|
import pytz
|
||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import datetime
|
||||||
|
|
||||||
# logging.basicConfig(filename='/home/captain/dev/log/heatmap.log', level=logging.INFO)
|
# logging.basicConfig(filename='/home/captain/dev/log/heatmap.log', level=logging.INFO)
|
||||||
# logger = logging.getLogger('/home/captain/dev/log/heatmap.log')
|
# logger = logging.getLogger('/home/captain/dev/log/heatmap.log')
|
||||||
@ -29,6 +30,28 @@ if os.path.exists(fn):
|
|||||||
date_, count = data_.split(' ')
|
date_, count = data_.split(' ')
|
||||||
date.append(date_)
|
date.append(date_)
|
||||||
data.append(int(count))
|
data.append(int(count))
|
||||||
|
me = client.me()
|
||||||
|
tl = client.account_statuses(me.id)
|
||||||
|
zh = pytz.timezone('Asia/Shanghai')
|
||||||
|
|
||||||
|
while tl:
|
||||||
|
print(tl[0].created_at)
|
||||||
|
break_flag = False
|
||||||
|
for status in tl:
|
||||||
|
date_ = status.created_at.astimezone(zh).date().strftime('%Y-%m-%d')
|
||||||
|
yesterday = datetime.datetime.now(pytz.timezone('Asia/Shanghai')).date() - datetime.timedelta(days=1)
|
||||||
|
# break if date is not yesterday
|
||||||
|
if date_ != yesterday.strftime('%Y-%m-%d'):
|
||||||
|
break_flag = True
|
||||||
|
break
|
||||||
|
if date_ not in date:
|
||||||
|
date.append(date_)
|
||||||
|
data.append(0)
|
||||||
|
data[date.index(date_)] += 1
|
||||||
|
if break_flag:
|
||||||
|
break
|
||||||
|
time.sleep(1)
|
||||||
|
tl = client.fetch_next(tl)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
# init
|
# init
|
||||||
@ -54,10 +77,10 @@ else:
|
|||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
cleaned_date, cleaned_data = july.utils.preprocess_inputs(date, data)
|
cleaned_date, cleaned_data = july.utils.preprocess_inputs(date, data)
|
||||||
july.heatmap(cleaned_date, cleaned_data, title='', cmap="BuGn")
|
july.heatmap(cleaned_date, cleaned_data, cmap="BuGn")
|
||||||
|
|
||||||
img_path = './heatmap.png'
|
img_path = './heatmap.png'
|
||||||
plt.savefig(img_path)
|
plt.savefig(img_path, bbox_inches='tight')
|
||||||
|
|
||||||
# upload image to mastodon
|
# upload image to mastodon
|
||||||
media = client.media_post(img_path)
|
media = client.media_post(img_path)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user