Compare commits

..

No commits in common. "bcbc299167f1bf20abe1df357c05bd9c8116f951" and "027b1f597da6129d8199a235b244992541600d08" have entirely different histories.

View File

@ -126,16 +126,37 @@ def run(instance, access_token, fanfou_cookie, fanfou_token):
me_id = me_info['id']
me_timeline = mastodon_cli.account_statuses(
me_id, exclude_replies=True)
min_id = None
max_id = None
# first time run
# init min_id
for status in me_timeline:
if not status['reblog'] and status['visibility'] == 'public':
min_id = status['id']
logger.info(status['content'])
break
# if is in already posted status
posted_ids = []
# if file not exist, create it
with open('last_id.txt', 'r') as f:
with open('last_id.txt', 'a+') as f:
f.seek(0)
# read lines
posted_ids = f.readlines()
# remove \n
posted_ids = [x.strip() for x in posted_ids]
#print(posted_ids)
if str(min_id) not in posted_ids:
content = status['content'].replace('<br />', '\n')
content = re.sub('<.*?>', '', content)
post_fanfou(fanfou_cookie, fanfou_token, content, status['media_attachments'])
# write to file
with open('last_id.txt', 'a') as f:
f.write(str(min_id) + '\n')
posted_ids.append(min_id)
logger.info('write toot')
time.sleep(10)
min_id = posted_ids[-1] if posted_ids else None
# get every new status
while min_id:
me_timeline = mastodon_cli.account_statuses(
@ -163,9 +184,6 @@ def run(instance, access_token, fanfou_cookie, fanfou_token):
if statuses:
min_id = statuses[-1]['id']
else:
if min_id:
with open('last_id.txt', 'a') as f:
f.write(str(min_id) + '\n')
min_id = None
if __name__ == '__main__':