refactor: 修改获取新消息逻辑
This commit is contained in:
parent
027b1f597d
commit
02a51c6bef
22
mas2ff2.py
22
mas2ff2.py
@ -126,16 +126,7 @@ 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', 'a+') as f:
|
||||
@ -144,19 +135,8 @@ def run(instance, access_token, fanfou_cookie, fanfou_token):
|
||||
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(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user