master
やしやし 1 year ago
parent 3c85ed19ed
commit 14fdc548f8
  1. 56
      app.py

@ -0,0 +1,56 @@
from mastodon import *
import json
import sqlite3
import datetime
dbpath = "dondailytootstat.sqlite"
date = datetime.datetime.now()
year = date.year
year = str(year)
month = date.month
month = str(month)
day = date.day
day = str(day)
date=year+"-"+month+"-"+day
#MastodonのAPI認証情報を入力。アクセス権はread:accounts。
mastodon = Mastodon(
client_id = '',
access_token = '',
client_secret = '',
api_base_url = ''
)
#アカウントのIDを入力
accountid = ""
acinfores = mastodon.account(accountid)
following = acinfores["following_count"]
followers = acinfores["followers_count"]
statuses = acinfores["statuses_count"]
try:
dbconn = sqlite3.connect(dbpath)
cur = dbconn.cursor()
cur.execute('''CREATE TABLE dailystat(date,following integer,followers integer,statuses integer)''')
cur.execute("INSERT INTO dailystat VALUES (?,?,?,?)", (date, following, followers, statuses))
dbconn.close()
except:
dbconn = sqlite3.connect(dbpath)
cur = dbconn.cursor()
data = dbconn.cursor()
data.execute("SElECT * FROM dailystat")
data=data.fetchone()
cur.execute("DELETE FROM dailystat;")
cur.execute("INSERT INTO dailystat VALUES (?,?,?,?)",(date,following,followers,statuses))
dbconn.commit()
dbconn.close()
difffollowing = following - data[1]
difffollowers = followers - data[2]
diffstatuses = statuses - data[3]
difffollowing = str(difffollowing)
difffollowers = str(difffollowers)
diffstatuses = str(diffstatuses)
mastodon.toot("今日のトゥート数は"+diffstatuses+"トゥート、"+"フォロー変動数は"+difffollowing+"、フォロワー変動数は"+diffstatuses+"でした。")
Loading…
Cancel
Save