Created
May 1, 2017 14:48
-
-
Save Hiroshiba/b5291efaf93e5c56a3503614edebf7d5 to your computer and use it in GitHub Desktop.
friends.nicoで全自動ニコる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
背景 | |
ドワンゴのマストドンfriends.nicoは、favouriteの代わりにニコるになっている。 | |
全部のトゥートに対してこのニコるを手動で付けているユーザーがいる。 | |
それに対抗して全自動でニコるのが一瞬流行った。 | |
そのときに適当に実装したコードがこれ。 | |
手順 | |
0) このコードをダウンロードして auto_fav.py という名前で保存する | |
1) pythonとかpipとかgccが入ってる環境を用意する | |
2) pip install Mastodon.py | |
3) pip install pycrypto | |
4) 下のとこにメルアドとパスワードを入力する | |
5) python auto_fav.py で実行 | |
6) 毎秒、新しいトゥートを全自動でニコる | |
注意 | |
たぶんこのコードは2017年5月1日限定で動く(そうなるように書いた)。 | |
当たり前ですが何があっても責任は取れません。 | |
''' | |
mail_address = 'ここにメールアドレスを入力' | |
pw = 'ここにパスワードを入力' | |
from mastodon import Mastodon | |
import time | |
import base64 | |
import datetime | |
from Crypto import Random | |
from Crypto.Cipher import AES | |
class AESCipher(object): | |
def __init__(self, key, block_size=32): | |
self.bs = block_size | |
if len(key) >= len(str(block_size)): | |
self.key = key[:block_size] | |
else: | |
self.key = self._pad(key) | |
def encrypt(self, raw): | |
raw = self._pad(raw) | |
iv = Random.new().read(AES.block_size) | |
cipher = AES.new(self.key, AES.MODE_CBC, iv) | |
return base64.b64encode(iv + cipher.encrypt(raw)) | |
def decrypt(self, enc): | |
enc = base64.b64decode(enc) | |
iv = enc[:AES.block_size] | |
cipher = AES.new(self.key, AES.MODE_CBC, iv) | |
return self._unpad(cipher.decrypt(enc[AES.block_size:])) | |
def _pad(self, s): | |
return s + (self.bs - len(s) % self.bs) * chr(self.bs - len(s) % self.bs) | |
def _unpad(self, s): | |
return s[:-ord(s[len(s)-1:])] | |
hogeee = 'hogeeeeeee' + str((datetime.datetime.today() - datetime.datetime(1, 1, 1)).days) | |
cipher = AESCipher(hogeee) | |
asdfasdf = cipher.decrypt('cmCraLcqDItws5fq02JbCTJnbAV+DCzIFrgaXI+kCsatNT4RxDGpNyA8ze6DfsMu').decode('utf') | |
Mastodon.create_app( | |
'pytooterapp', | |
to_file = 'pytooter_clientcred.txt', | |
api_base_url = 'https://friends.nico', | |
) | |
mastodon = Mastodon( | |
client_id = 'pytooter_clientcred.txt', | |
api_base_url = 'https://friends.nico', | |
) | |
mastodon.log_in( | |
mail_address, | |
pw, | |
) | |
while True: | |
tl = mastodon.timeline('local') | |
for s in tl: | |
f = s['favourited'] | |
if f is None or not f: | |
sr = mastodon.status_favourite(s[asdfasdf]) | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment