update bot using online version
This commit is contained in:
parent
a43c462ae9
commit
a45459dedc
@ -8,8 +8,8 @@ import logging
|
|||||||
from mastodon import Mastodon
|
from mastodon import Mastodon
|
||||||
import traceback
|
import traceback
|
||||||
|
|
||||||
logging.basicConfig(filename='jandan.log', level=logging.INFO)
|
logging.basicConfig(filename='/home/captain/dev/log/jandan.log', level=logging.INFO)
|
||||||
logger = logging.getLogger('jandan.log')
|
logger = logging.getLogger('/home/captain/dev/log/jandan.log')
|
||||||
|
|
||||||
mastodon = Mastodon(
|
mastodon = Mastodon(
|
||||||
access_token = 'TFBqF_7eLHP1Lr8zqegAnKUBT3mq1_qU2zHOn7aX5sU',
|
access_token = 'TFBqF_7eLHP1Lr8zqegAnKUBT3mq1_qU2zHOn7aX5sU',
|
||||||
@ -33,13 +33,13 @@ def ramdom_ua():
|
|||||||
|
|
||||||
def load_id():
|
def load_id():
|
||||||
id_list = []
|
id_list = []
|
||||||
with open('id_list') as f:
|
with open('/home/captain/dev/id_list') as f:
|
||||||
id_list = f.read().splitlines()
|
id_list = f.read().splitlines()
|
||||||
f.close()
|
f.close()
|
||||||
return id_list
|
return id_list
|
||||||
|
|
||||||
def save_id(id_list):
|
def save_id(id_list):
|
||||||
with open('id_list', 'wb') as f:
|
with open('/home/captain/dev/id_list', 'wb') as f:
|
||||||
for item in id_list:
|
for item in id_list:
|
||||||
f.write(("%s\n" % item).encode())
|
f.write(("%s\n" % item).encode())
|
||||||
f.close()
|
f.close()
|
||||||
@ -57,7 +57,6 @@ def toot():
|
|||||||
session.headers.update(ramdom_ua())
|
session.headers.update(ramdom_ua())
|
||||||
|
|
||||||
while page_count and jandan_pic_url:
|
while page_count and jandan_pic_url:
|
||||||
# import ipdb; ipdb.set_trace()
|
|
||||||
resp = session.get(jandan_pic_url)
|
resp = session.get(jandan_pic_url)
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
@ -90,6 +89,7 @@ def toot():
|
|||||||
|
|
||||||
status_list.reverse()
|
status_list.reverse()
|
||||||
for status in status_list:
|
for status in status_list:
|
||||||
|
#import ipdb; ipdb.set_trace()
|
||||||
if status['id'] not in id_list:
|
if status['id'] not in id_list:
|
||||||
id_list.insert(0, status['id'])
|
id_list.insert(0, status['id'])
|
||||||
if len(id_list) > 100:
|
if len(id_list) > 100:
|
||||||
@ -102,10 +102,10 @@ def toot():
|
|||||||
mime_type = 'image/jpeg'
|
mime_type = 'image/jpeg'
|
||||||
if img.lower().split('.')[-1] == 'gif':
|
if img.lower().split('.')[-1] == 'gif':
|
||||||
mime_type = 'image/gif'
|
mime_type = 'image/gif'
|
||||||
r = session.get(img)
|
resp = session.get(img)
|
||||||
logger.info((status['id'], status['status'], img, mime_type))
|
logger.info((status['id'], status['status'], img, mime_type))
|
||||||
try:
|
try:
|
||||||
toot_resp = mastodon.media_post(r.content, mime_type)
|
toot_resp = mastodon.media_post(resp.content, mime_type)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
if toot_resp.get('id'):
|
if toot_resp.get('id'):
|
||||||
|
|||||||
@ -29,13 +29,13 @@ tvdl_url = 'https://tvdl-api.saif.dev/'
|
|||||||
|
|
||||||
def load_id():
|
def load_id():
|
||||||
id_ = None
|
id_ = None
|
||||||
with open('/home/captain/dev/tmp/setu_dm') as f:
|
with open('/home/captain/dev/setu_dm') as f:
|
||||||
id_ = f.read()
|
id_ = f.read()
|
||||||
f.close()
|
f.close()
|
||||||
return id_
|
return id_
|
||||||
|
|
||||||
def save_id(id_):
|
def save_id(id_):
|
||||||
with open('/home/captain/dev/tmp/setu_dm', 'wb') as f:
|
with open('/home/captain/dev/setu_dm', 'wb') as f:
|
||||||
f.write(("%s\n" % id_).encode())
|
f.write(("%s\n" % id_).encode())
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
@ -56,6 +56,7 @@ def post_mentions():
|
|||||||
content = soup.get_text().split(account_name)[-1].strip()
|
content = soup.get_text().split(account_name)[-1].strip()
|
||||||
media_ids = []
|
media_ids = []
|
||||||
if content.startswith('http'):
|
if content.startswith('http'):
|
||||||
|
#import ipdb; ipdb.set_trace()
|
||||||
logging.info('get url %s', content)
|
logging.info('get url %s', content)
|
||||||
try:
|
try:
|
||||||
url = urlparse(content)
|
url = urlparse(content)
|
||||||
@ -79,11 +80,11 @@ def post_mentions():
|
|||||||
mime_type = 'image/gif'
|
mime_type = 'image/gif'
|
||||||
toot_resp = mastodon.media_post(r.content, mime_type)
|
toot_resp = mastodon.media_post(r.content, mime_type)
|
||||||
else:
|
else:
|
||||||
f = open('/home/captain/dev/tmp/temp_download_file.%s' % ext, 'wb')
|
f = open('/home/captain/dev/temp_download_file.%s' % ext, 'wb')
|
||||||
f.write(r.content)
|
f.write(r.content)
|
||||||
f.close()
|
f.close()
|
||||||
mime_type = None
|
mime_type = None
|
||||||
toot_resp = mastodon.media_post('/home/captain/dev/tmp/temp_download_file.%s' % ext, mime_type)
|
toot_resp = mastodon.media_post('/home/captain/dev/temp_download_file.%s' % ext, mime_type)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
if toot_resp.get('id'):
|
if toot_resp.get('id'):
|
||||||
@ -94,22 +95,24 @@ def post_mentions():
|
|||||||
|
|
||||||
media_ids = []
|
media_ids = []
|
||||||
for media in mention['status']['media_attachments']:
|
for media in mention['status']['media_attachments']:
|
||||||
|
#import ipdb; ipdb.set_trace()
|
||||||
mime_type = 'image/jpeg'
|
mime_type = 'image/jpeg'
|
||||||
if media['type'] == 'video':
|
if media['type'] == 'video':
|
||||||
resp = requests.get(media['url'])
|
resp = requests.get(media['url'])
|
||||||
if resp.status_code != 200:
|
if resp.status_code != 200:
|
||||||
continue
|
continue
|
||||||
f = open('/home/captain/dev/tmp/temp_video.mp4', 'wb')
|
f = open('/home/captain/dev/temp_video.mp4', 'wb')
|
||||||
f.write(resp.content)
|
f.write(resp.content)
|
||||||
f.close()
|
f.close()
|
||||||
|
mime_type = None
|
||||||
try:
|
try:
|
||||||
toot_resp = mastodon.media_post('/home/captain/dev/tmp/temp_video.mp4', mime_type)
|
toot_resp = mastodon.media_post('/home/captain/dev/temp_video.mp4', mime_type)
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
clip = VideoFileClip('/home/captain/dev/tmp/temp_video.mp4')
|
clip = VideoFileClip('/home/captain/dev/temp_video.mp4')
|
||||||
clip.write_gif('/home/captain/dev/tmp/temp_gif.gif')
|
clip.write_gif('/home/captain/dev/temp_gif.gif')
|
||||||
mime_type = 'image/gif'
|
mime_type = 'image/gif'
|
||||||
toot_resp = mastodon.media_post('/home/captain/dev/tmp/temp_gif.gif', mime_type)
|
toot_resp = mastodon.media_post('/home/captain/dev/temp_gif.gif', mime_type)
|
||||||
except:
|
except:
|
||||||
continue
|
continue
|
||||||
if toot_resp.get('id'):
|
if toot_resp.get('id'):
|
||||||
@ -138,3 +141,4 @@ while True:
|
|||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
logger.error(traceback.format_exc())
|
logger.error(traceback.format_exc())
|
||||||
time.sleep(10)
|
time.sleep(10)
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user