Skip to content

Instantly share code, notes, and snippets.

@yoshi389111
Created April 22, 2021 23:11
Show Gist options
  • Save yoshi389111/4019db4642bced6e78707f5ac6be0b57 to your computer and use it in GitHub Desktop.
Save yoshi389111/4019db4642bced6e78707f5ac6be0b57 to your computer and use it in GitHub Desktop.
もふもふな記念日をqiitadonにtootする
import datetime
import sys
import urllib.request
import urllib.parse
url = "https://qiitadon.com/api/v1/statuses"
# 記念日情報. key: 'MMDD', value: 'message',
anniversaries = {
"0114": "今日はタロとジロの日ですね :dog: :dog_face:",
"0121": "今日はリスの日(アメリカ:flag-us:)ですね。 :chipmunk:",
"0131": "今日は国際シマウマの日(International Zebra Day)ですね :zebra:",
"0202": "今日は世界ダチョウの日(World Ostrich Day)ですね",
"0205": "今日はピカチュウの日ですね",
"0208": "今日はニワトリの日ですね :chicken:",
"0209": "今日はフクロウの日ですね :owl:",
"0215": "今日は世界カバの日ですね :hippopotamus:",
"0217": "今日は猫の日(イタリア:flag-it:)ですね :cat:",
"0222": "今日は猫の日(日本:flag-jp:)ですね :cat:",
"0227": "今日は Pokemon Day と、国際ホッキョクグマの日(International Polar Bear Day)ですね",
"0301": "今日はブタの日(アメリカ:flag-us:) :pig_face: と、猫の日(ロシア:flag-ru:)ですね :cat:",
"0302": "今日はミニブタの日(日本:flag-jp:)ですね :pig_face:",
"0303": "今日は世界野生動物の日(World Wildlife Day)とウサギの日(日本:flag-jp:)ですね :rabbit:",
"0311": "今日はパンダ発見の日ですね :panda_face:",
"0320": "今日は世界スズメの日(World Sparrow Day)ですね",
"0323": "今日は子犬の日(アメリカ:flag-us:)ですね :dog:",
"0403": "今日はシーサーの日(沖縄)ですね",
"0404": "今日は獅子の日(日本:flag-jp:) :lion_face: と、猫の日(台湾:flag-tw:)ですね :cat:",
"0408": "今日は忠犬ハチ公の日ですね :dog:",
"0411": "今日はペットの日(アメリカ:flag-us:)ですね :cat: :dog:",
"0412": "今日は世界ハムスターの日(World Hamster Day)ですね :hamster_face:",
"0415": "今日はイリオモテヤマネコの日ですね :cat:",
"0423": "今日は国際マヌルネコの日(International Pallas’s cat day)ですね",
"0425": "今日は世界ペンギンの日(World Penguin Day)ですね :linux:",
"0427": "今日は世界バクの日(World Tapir Day)ですね",
"0428": "今日は象の日(日本:flag-jp:)ですね :postgresql:",
"0509": "今日は悟空の日(日本:flag-jp:)ですね :monkey:",
"0513": "今日は愛犬の日(日本:flag-jp:)ですね :dog:",
"0522": "今日は補助犬の日ですね :guide_dog:",
"0604": "今日は猫をハグする日(アメリカ:flag-us:)ですね :cat_face:",
"0606": "今日はヒツジの日(日本:flag-jp:)ですね :ewe:",
"0615": "今日はオウムとインコの日ですね :christmasparrot:",
"0621": "今日は世界キリンの日(World Giraffe Day)ですね :giraffe:",
"0622": "今日は世界ラクダの日(World Camel Day)ですね :perl:",
"0714": "今日は世界チンパンジーの日(World Porcupine Day)ですね :monkey:",
"0716": "今日はモルモットの日(カナダ:flag-ca:)ですね",
"0729": "今日は国際トラの日(International Tiger Day)ですね :tiger_face:",
"0731": "今日はミックス犬の日(アメリカ:flag-us:)ですね :dog:",
"0806": "今日はハムスターの日(日本:flag-jp:)ですね :hamster_face:",
"0808": "今日は世界ネコの日(World Cat Day)ですね :cat:",
"0810": "今日はスヌーピーの日(日本:flag-jp:)と、世界ライオンの日(World Lion Day)ですね :lion_face:",
"0812": "今日は世界ゾウの日(World Elephant Day)ですね :postgresql:",
"0813": "今日は世界オオカミの日(World Wolf Day)ですね :wolf_face:",
"0817": "今日は黒ネコ感謝の日(アメリカ:flag-us:)ですね :github:",
"0819": "今日は国際オランウータンの日(International Orangutan Day)ですね :orangutan:",
"0826": "今日は世界イヌの日(World Dog Day)ですね :dog:",
"0901": "今日は国際霊長類の日(International Primates Day)ですね :monkey:",
"0904": "今日は野生動物の日(アメリカ:flag-us:)ですね",
"0906": "今日は黒猫の日(日本:flag-jp:)ですね :github:",
"0917": "今日はヤンバルクイナの日ですね",
"0922": "今日は世界サイの日(World Rhino Day)ですね :rhinoceros:",
"0924": "今日は世界ゴリラの日(World Gorilla Day)ですね :gorilla:",
"0929": "今日は招き猫の日ですね",
"1001": "今日は補助犬の日(日本:flag-jp:):guide_dog: と、黒犬の日(アメリカ:flag-us:)ですね",
"1004": "今日は世界動物の日(World Animal Day)ですね :firefox: :gopher: :qiitan:",
"1008": "今日はツシマヤマネコの日ですね :cat:",
"1016": "今日は野良猫の日(アメリカ:flag-us:)ですね :cat:",
"1018": "今日は世界オカピの日(World Okapi Day)ですね",
"1020": "今日は国際ナマケモノの日(International Sloth Day)ですね :sloth:",
"1022": "今日は世界ウォンバットの日(World Wombat Day)ですね",
"1023": "今日は国際ユキヒョウの日(International Snow Leopard Day)ですね",
"1024": "今日は文鳥の日と、国際テナガザルの日(International Gibbon Day)ですね",
"1027": "今日はテディベアズ・デーと、黒猫の日(イギリス:flag-gb:)ですね :github:",
"1028": "今日はパンダの日(日本:flag-jp:)ですね :panda_face:",
"1029": "今日は猫の日(アメリカ:flag-us:)ですね :cat:",
"1101": "今日は犬の日(日本:flag-jp:):dog: と、キティーちゃんの誕生日ですね",
"1108": "今日は信楽たぬきの日ですね",
"1111": "今日はシマリスの日(日本:flag-jp:)ですね :chipmunk:",
"1117": "今日は黒猫の日(イタリア:flag-it:)ですね :github:",
"1118": "今日は熊の日(日本:flag-jp:) :bear_face: と、ミッキーマウスの誕生日ですね",
"1121": "今日はイーブイの日(日本:flag-jp:)ですね",
"1122": "今日はペットたちに感謝する日(日本:flag-jp:)ですね :dog: :cat:",
"1129": "今日はいい肉球の日(日本:flag-jp:)ですね :paw_prints:",
"1202": "今日はミックス犬の日(アメリカ:flag-us:)ですね :dog:",
"1204": "今日は国際チーターの日(International Cheetah Day)ですね :apach_tomcat:",
"1212": "今日は世界りんご猫デー(World Apple Cats Day)ですね :apple: :cat:",
}
def emoji_to_unicode(data):
return (
data.replace(":monkey:", "\U0001f412")
.replace(":gorilla:", "\U0001f98d")
.replace(":orangutan:", "\U0001f9a7")
.replace(":dog_face:", "\U0001f436")
.replace(":dog:", "\U0001f415")
.replace(":guide_dog:", "\U0001f9ae") # 盲導犬
.replace(":wolf_face:", "\U0001f43a")
.replace(":cat_face:", "\U0001f431")
.replace(":cat:", "\U0001f408")
.replace(":lion_face:", "\U0001f981")
.replace(":tiger_face:", "\U0001f42f")
.replace(":zebra:", "\U0001f993")
.replace(":pig_face:", "\U0001f437")
.replace(":ewe:", "\U0001f411") # ヒツジ
.replace(":giraffe:", "\U0001f992")
.replace(":elephant:", "\U0001f418")
.replace(":rhinoceros:", "\U0001f98f")
.replace(":hippopotamus:", "\U0001f99b")
.replace(":mouse_face:", "\U0001f42d")
.replace(":hamster_face:", "\U0001f439")
.replace(":rabbit_face:", "\U0001f430")
.replace(":rabbit:", "\U0001f407")
.replace(":chipmunk:", "\U0001f43f")
.replace(":bear_face:", "\U0001f43b")
.replace(":koala:", "\U0001f428")
.replace(":panda_face:", "\U0001f43c")
.replace(":sloth:", "\U0001f9a5")
.replace(":paw_prints:", "\U0001f43e") # 動物の足跡
.replace(":chicken:", "\U0001f414")
.replace(":owl:", "\U0001f989")
.replace(":flag-ca:", "\U0001f1e8\U0001f1e6")
.replace(":flag-cn:", "\U0001f1e8\U0001f1f3")
.replace(":flag-de:", "\U0001f1e9\U0001f1e9")
.replace(":flag-eu:", "\U0001f1ea\U0001f1fa")
.replace(":flag-fr:", "\U0001f1eb\U0001f1f7")
.replace(":flag-it:", "\U0001f1ee\U0001f1f9")
.replace(":flag-ru:", "\U0001f1f7\U0001f1fa")
.replace(":flag-uk:", "\U0001f1ec\U0001f1e7")
.replace(":flag-uk:", "\U0001f1ec\U0001f1e7")
.replace(":flag-jp:", "\U0001f1ef\U0001f1f5")
.replace(":flag-kr:", "\U0001f1f0\U0001f1f7")
.replace(":flag-tw:", "\U0001f1f9\U0001f1fc")
.replace(":flag-us:", "\U0001f1fa\U0001f1f8")
.replace(":apple:", "\U0001f34e")
.replace(":robot_face:", "\U0001f916")
)
def main():
if len(sys.argv) != 2:
print("usage: {} ACCESS_TOKEN".format(sys.argv[0]), file=sys.stderr)
return
access_token = sys.argv[1]
message = message_of_today()
if message != "":
greet = ":robot_face: おはようございます。"
toot(emoji_to_unicode(greet + message), access_token)
# print(emoji_to_unicode(message))
def message_of_today():
today = datetime.date.today()
key = "{:0>2}{:0>2}".format(today.month, today.day)
return anniversaries[key] if key in anniversaries else ""
def toot(message, access_token):
# unlisted / public
data = "visibility=public&status=" + urllib.parse.quote(message)
headers = {
"Authorization": "Bearer " + access_token,
"Content-Type": "application/x-www-form-urlencoded",
}
req = urllib.request.Request(url, data.encode("ascii"), headers)
with urllib.request.urlopen(req) as res:
res.read()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment