2018/07/07 17:29:59
めりー@店主
@merry
図書館でこの本借りてきた
https://www.amazon.co.jp/dp/4797387149/ref=cm_sw_r_tw_dp_U_x_KNhqBb5XVV1P7
2018/05/29 00:09:31
@do
def delete_tweet_all(self, stared_delete_flg = False, faved_delete_flg = False):
max_id = 0
endflg = False
while not endflg:
L = b.get_user_timeline(b.name, b.id, max_id)
if len(L) is 0: endflg = True
print("--------" + str(max_id) + "--------")
for t in L:
print(t.tweet_id, t.favorites_count, t.likes_count)
if not stared_delete_flg:
if t.likes_count > 0:
print("likes_count ", t.likes_count)
continue
if not faved_delete_flg:
if t.favorites_count > 0:
print("favorites_count", t.favorites_count)
continue
print("deleteるぞ")
self.destroy(t.tweet_id)
max_id = t.tweet_id
2018/05/29 00:09:16
@do
def get_user_timeline(self, username, userid, max_id=None):
url = 'http://beluga.fm/i/statuses/user_timeline.json'
param = {
'screen_name': username,
'user_id': userid
}
if max_id is not None:
param['max_id'] = max_id
data = urllib.parse.urlencode(param).encode(encoding='ascii')
rsp = self.opener.open(url, data).read().decode('utf-8')
d = json.loads(rsp)
L = []
for t in d['statuses']:
try :
tw = Timeline()
tw.tweet_id = t['id']
tw.likes_count = t['likes_count']
tw.favorites_count = t['favorites_count']
L.append(tw)
except UnicodeEncodeError as e:
print(e)
return L
2018/05/29 00:08:08
@do
def _set_authenticity_token(self, sname):
""" とりあえずユーザー情報からトークンを取得しインスタンス変数にセット
"""
url = 'http://beluga.fm/i/app/user_statuses.json'
param = {
'screen_name': sname
}
data = urllib.parse.urlencode(param).encode(encoding='ascii')
rsp = self.opener.open(url, data).read().decode('utf-8')
d = json.loads(rsp)
self.id = d['data']['user']['id']
if d['data']['authenticity_token'] is not 0:
self.authenticity_token = d['data']['authenticity_token']
return True
return False
def update(self, text):
""" 投稿
"""
url = "http://beluga.fm/i/statuses/update.json"
param = {
'authenticity_token': self.authenticity_token,
'text': text
}
data = urllib.parse.urlencode(param).encode(encoding='ascii')
rsp = self.opener.open(url, data).read().decode('utf-8')
d = json.loads(rsp)
print(d)
def destroy(self, delete_id):
""" 投稿削除
"""
url = "http://beluga.fm/i/statuses/destroy"
param = {
'screen_name': self.name,
'authenticity_token': self.authenticity_token,
'status_id': delete_id
}
data = urllib.parse.urlencode(param).encode(encoding='ascii')
rsp = self.opener.open(url, data).read().decode('utf-8')
def get_userinfo(self, sname):
""" とりあえずユーザー情報からトークンを取得しインスタンス変数にセット
"""
url = 'http://beluga.fm/i/app/user_statuses.json'
param = {
'screen_name': sname
}
if since_id is not None:
param['max_id'] = since_id
data = urllib.parse.urlencode(param).encode(encoding='ascii')
rsp = self.opener.open(url, data).read().decode('utf-8')
d = json.loads(rsp)
return L
2018/05/29 00:07:28
@do
# -*- encoding:utf-8 -*-
import os
import sys
import urllib
import json
import http.cookiejar
class beluga:
""" belugaのなんかアレ
"""
def __init__(self, name, password):
self.name = name # screen_name
self.id = 0
self.password = password # パスワード
self.authenticity_token = "" # トークン
self.cookiefile = "cookies.txt"
self.cj = http.cookiejar.LWPCookieJar()
if os.path.exists(self.cookiefile):
self.cj.load(self.cookiefile)
self.opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(self.cj))
def __del__(self):
# ホントはここでクッキー保存_save_cokkie()したいんじゃがsave()の中のopen()が定義されてないってErrorになるんじゃ
#self._save_cokkie()
pass
def _save_cokkie(self):
self.cj.save(self.cookiefile, True, True)
print("Cookie saved to "+self.cookiefile)
def _get_login_page_token(self):
""" loginページからtokenを取得する(http://beluga.fm/login)
"""
url = "http://beluga.fm/login"
d = self.opener.open(url)
res = d.read().decode('utf-8')
try:
seekstr = 'authenticity_token = "'
start_point = res.index(seekstr)
s = res[start_point + len(seekstr):]
end_point = s.index('"')
login_token = s[:end_point]
except ValueError as e:
print("login_page_token", e)
return None
return login_token
def login(self):
""" Belugaへログインする
"""
if self._set_authenticity_token(self.name):
print("login済み", self.authenticity_token)
return True
token = self._get_login_page_token()
url = "http://beluga.fm/i/account/login.json"
param = {
'screen_name': self.name,
'authenticity_token': token,
"password": self.password
}
data = urllib.parse.urlencode(param).encode(encoding='ascii')
rsp = self.opener.open(url, data).read().decode('utf-8')
d = json.loads(rsp)
print(d)
if d["success"]:
if self._set_authenticity_token(self.name):
print(self.authenticity_token)
self._save_cokkie()
return True
return False
def logout(self):
""" Belugaからログアウトする
"""
url = "http://beluga.fm/i/account/logout.json"
param = {
'authenticity_token': self.authenticity_token
}
data = urllib.parse.urlencode(param).encode(encoding='ascii')
rsp = self.opener.open(url, data).read().decode('utf-8')
d = json.loads(rsp)
print(d)
self._save_cokkie()
2018/05/28 23:50:10
@do
https://files.slack.com/files-pri/T0J7LR309-F0VPK1VLK/beluga_tools.py
今は亡きnemiが書いたbelugaのツール
見れる?