Skip to content

Instantly share code, notes, and snippets.

@YuzuRyo61
Created July 19, 2019 11:32
Show Gist options
  • Save YuzuRyo61/46cf93bca177d36d80ef17f260ffd5d2 to your computer and use it in GitHub Desktop.
Save YuzuRyo61/46cf93bca177d36d80ef17f260ffd5d2 to your computer and use it in GitHub Desktop.
よろしくお願いしまぁぁぁすっ!!ができる簡易スクリプト
[
{
"method": "mastodon",
"address": "example.com",
"token": "abcdefg1234567890"
},
{
"method": "misskey",
"address": "example.com",
"token": "abcdefg1234567890"
}
]
# 最新版の以下のパッケージが必要です。pipでインストールしてください。
Misskey.py==2.0.0
Mastodon.py==1.4.5
#!/usr/bin/env python3
# よろしくお願いしまぁぁぁすっ!!
# ができる簡易スクリプト
import os
import json
import sys
from mastodon import Mastodon
from Misskey import Misskey
def ynbool(text):
text = text.lower()
if text in ("y", "ye", "yes", "1", "true"):
return True
elif text in ("n", "no", "0", "false"):
return False
else:
return None
if __name__ == "__main__":
if os.path.isfile("account.json"):
with open("account.json", "r") as ajf:
account = json.load(ajf)
masi = []
misi = []
for act in account:
if act["method"] == "mastodon":
try:
newMasi = Mastodon(access_token=act["token"], api_base_url=act["address"])
cred = newMasi.account_verify_credentials()
masi.append( newMasi )
print("Fetched Account (Mastodon): @{0}@{1}".format(cred["acct"], act["address"]))
except:
print("Initialize error (Mastodon)")
sys.exit(2)
elif act["method"] == "misskey":
try:
newMisi = Misskey(address=act["address"], i=act["token"])
cred = newMisi.i()
misi.append( newMisi )
print("Fetched Account (Misskey): @{0}@{1}".format(cred["username"], act["address"]))
except:
print("Initialize error (Misskey)")
sys.exit(3)
if masi == [] and misi == []:
print("No accounts.")
sys.exit(4)
text = input("Message (Default: よろしくお願いしまぁぁぁすっ!!): ")
if text == "":
text = "よろしくお願いしまぁぁぁすっ!!"
print(f"Will post message: {text}")
submitbool = input("Transmit?(Y/n): ")
if submitbool == "":
submitbool = "Y"
if ynbool(submitbool):
for ma in masi:
ma.toot(text)
for mi in misi:
mi.notes_create(text)
print("Complete!")
sys.exit()
else:
sys.exit()
else:
print("account.json was not found")
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment