diff --git a/jandan_toot.py b/jandan_toot.py index 44c99fb..bd000c2 100644 --- a/jandan_toot.py +++ b/jandan_toot.py @@ -8,8 +8,8 @@ import logging from mastodon import Mastodon import traceback -logging.basicConfig(filename='jandan.log', level=logging.INFO) -logger = logging.getLogger('jandan.log') +logging.basicConfig(filename='/home/captain/dev/log/jandan.log', level=logging.INFO) +logger = logging.getLogger('/home/captain/dev/log/jandan.log') mastodon = Mastodon( access_token = 'TFBqF_7eLHP1Lr8zqegAnKUBT3mq1_qU2zHOn7aX5sU', @@ -33,13 +33,13 @@ def ramdom_ua(): def load_id(): id_list = [] - with open('id_list') as f: + with open('/home/captain/dev/id_list') as f: id_list = f.read().splitlines() f.close() return 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: f.write(("%s\n" % item).encode()) f.close() @@ -57,7 +57,6 @@ def toot(): session.headers.update(ramdom_ua()) while page_count and jandan_pic_url: - # import ipdb; ipdb.set_trace() resp = session.get(jandan_pic_url) if resp.status_code != 200: time.sleep(10) @@ -90,6 +89,7 @@ def toot(): status_list.reverse() for status in status_list: + #import ipdb; ipdb.set_trace() if status['id'] not in id_list: id_list.insert(0, status['id']) if len(id_list) > 100: @@ -102,10 +102,10 @@ def toot(): mime_type = 'image/jpeg' if img.lower().split('.')[-1] == 'gif': mime_type = 'image/gif' - r = session.get(img) + resp = session.get(img) logger.info((status['id'], status['status'], img, mime_type)) try: - toot_resp = mastodon.media_post(r.content, mime_type) + toot_resp = mastodon.media_post(resp.content, mime_type) except: continue if toot_resp.get('id'): diff --git a/setu.py b/setu_toot.py similarity index 81% rename from setu.py rename to setu_toot.py index 23acda1..9ef02a1 100644 --- a/setu.py +++ b/setu_toot.py @@ -29,13 +29,13 @@ tvdl_url = 'https://tvdl-api.saif.dev/' def load_id(): id_ = None - with open('/home/captain/dev/tmp/setu_dm') as f: + with open('/home/captain/dev/setu_dm') as f: id_ = f.read() f.close() return 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.close() @@ -56,6 +56,7 @@ def post_mentions(): content = soup.get_text().split(account_name)[-1].strip() media_ids = [] if content.startswith('http'): + #import ipdb; ipdb.set_trace() logging.info('get url %s', content) try: url = urlparse(content) @@ -77,13 +78,13 @@ def post_mentions(): if ext.lower() in ['jpg', 'jpeg', 'gif']: if ext == 'gif': mime_type = 'image/gif' - toot_resp = mastodon.media_post(r.content, mime_type) + toot_resp = mastodon.media_post(r.content, mime_type) else: - f = open('/home/captain/dev/tmp/temp_download_file.%s' % ext, 'wb') - f.write(r.content) - f.close() - mime_type = None - toot_resp = mastodon.media_post('/home/captain/dev/tmp/temp_download_file.%s' % ext, mime_type) + f = open('/home/captain/dev/temp_download_file.%s' % ext, 'wb') + f.write(r.content) + f.close() + mime_type = None + toot_resp = mastodon.media_post('/home/captain/dev/temp_download_file.%s' % ext, mime_type) except: continue if toot_resp.get('id'): @@ -94,22 +95,24 @@ def post_mentions(): media_ids = [] for media in mention['status']['media_attachments']: + #import ipdb; ipdb.set_trace() mime_type = 'image/jpeg' if media['type'] == 'video': resp = requests.get(media['url']) if resp.status_code != 200: 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.close() + mime_type = None 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: try: - clip = VideoFileClip('/home/captain/dev/tmp/temp_video.mp4') - clip.write_gif('/home/captain/dev/tmp/temp_gif.gif') + clip = VideoFileClip('/home/captain/dev/temp_video.mp4') + clip.write_gif('/home/captain/dev/temp_gif.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: continue if toot_resp.get('id'): @@ -138,3 +141,4 @@ while True: except Exception as ex: logger.error(traceback.format_exc()) time.sleep(10) +