style(heatmap): lint with Black
lint with Black Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
5d271f43db
commit
5211f9cb8a
59
heatmap.py
59
heatmap.py
@ -1,24 +1,24 @@
|
||||
from pydoc import cli
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import july
|
||||
import datetime
|
||||
import logging
|
||||
from mastodon import Mastodon
|
||||
import matplotlib.pyplot as plt
|
||||
import os
|
||||
import pytz
|
||||
import time
|
||||
import os
|
||||
import datetime
|
||||
|
||||
|
||||
from mastodon import Mastodon
|
||||
import july
|
||||
|
||||
# logging.basicConfig(filename='/home/captain/dev/log/heatmap.log', level=logging.INFO)
|
||||
# logger = logging.getLogger('/home/captain/dev/log/heatmap.log')
|
||||
banner_id = 108361439460735817
|
||||
|
||||
client = Mastodon(
|
||||
access_token = 'Ug_bUMWCk3RLamOnqYIytmeB0nO6aNfjdmf06mAj2bE',
|
||||
api_base_url = 'https://nofan.xyz'
|
||||
access_token="Ug_bUMWCk3RLamOnqYIytmeB0nO6aNfjdmf06mAj2bE",
|
||||
api_base_url="https://nofan.xyz",
|
||||
)
|
||||
|
||||
fn = './heatmap.txt'
|
||||
fn = "./heatmap.txt"
|
||||
# read from file if exists
|
||||
date = []
|
||||
data = []
|
||||
@ -27,21 +27,23 @@ if os.path.exists(fn):
|
||||
data_list = f.read().splitlines()
|
||||
f.close()
|
||||
for data_ in data_list:
|
||||
date_, count = data_.split(' ')
|
||||
date_, count = data_.split(" ")
|
||||
date.append(date_)
|
||||
data.append(int(count))
|
||||
me = client.me()
|
||||
tl = client.account_statuses(me.id)
|
||||
zh = pytz.timezone('Asia/Shanghai')
|
||||
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)
|
||||
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'):
|
||||
if date_ != yesterday.strftime("%Y-%m-%d"):
|
||||
break_flag = True
|
||||
break
|
||||
if date_ not in date:
|
||||
@ -57,12 +59,12 @@ else:
|
||||
# init
|
||||
me = client.me()
|
||||
tl = client.account_statuses(me.id)
|
||||
zh = pytz.timezone('Asia/Shanghai')
|
||||
zh = pytz.timezone("Asia/Shanghai")
|
||||
|
||||
while tl:
|
||||
print(tl[0].created_at)
|
||||
for status in tl:
|
||||
date_ = status.created_at.astimezone(zh).date().strftime('%Y-%m-%d')
|
||||
date_ = status.created_at.astimezone(zh).date().strftime("%Y-%m-%d")
|
||||
if date_ not in date:
|
||||
date.append(date_)
|
||||
data.append(0)
|
||||
@ -71,28 +73,27 @@ else:
|
||||
tl = client.fetch_next(tl)
|
||||
|
||||
# write to file
|
||||
with open(fn, 'w') as f:
|
||||
with open(fn, "w") as f:
|
||||
for i in range(len(date)):
|
||||
f.write(date[i] + ' ' + str(data[i]) + '\n')
|
||||
f.write(date[i] + " " + str(data[i]) + "\n")
|
||||
f.close()
|
||||
|
||||
cleaned_date, cleaned_data = july.utils.preprocess_inputs(date, data)
|
||||
july.heatmap(cleaned_date, cleaned_data, cmap="BuGn")
|
||||
|
||||
img_path = './heatmap.png'
|
||||
plt.savefig(img_path, bbox_inches='tight')
|
||||
img_path = "./heatmap.png"
|
||||
plt.savefig(img_path, bbox_inches="tight")
|
||||
|
||||
# upload image to mastodon
|
||||
media = client.media_post(img_path)
|
||||
|
||||
headers = {}
|
||||
headers['Authorization'] = 'Bearer ' + client.access_token
|
||||
params = {
|
||||
'status': '今天浑浑噩噩了吗',
|
||||
'media_ids': [media.id]
|
||||
}
|
||||
headers["Authorization"] = "Bearer " + client.access_token
|
||||
params = {"status": "今天浑浑噩噩了吗", "media_ids": [media.id]}
|
||||
kwargs = dict(headers=headers, files={}, timeout=client.request_timeout, json=params)
|
||||
url = client.api_base_url + '/api/v1/statuses/%s/' % banner_id
|
||||
resp = client.session.request('PUT', url, **kwargs)
|
||||
url = client.api_base_url + "/api/v1/statuses/%s/" % banner_id
|
||||
resp = client.session.request("PUT", url, **kwargs)
|
||||
if resp.status_code == 200:
|
||||
client.session.request('GET', 'https://up.tunpok.com/api/push/qku6CYquGu?msg=OK&ping=')
|
||||
client.session.request(
|
||||
"GET", "https://up.tunpok.com/api/push/qku6CYquGu?msg=OK&ping="
|
||||
)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user