fix(main.py): 修复图片批次总数量激素有误的问题
修复图片批次总数量激素有误的问题 Signed-off-by: Ching <loooching@gmail.com>
This commit is contained in:
parent
ea022ff1fa
commit
f60c1f03a5
8
main.py
8
main.py
@ -147,13 +147,13 @@ unsynced_photos = Photo.select().where(Photo.synced == False).order_by(Photo.cre
|
|||||||
# get titles
|
# get titles
|
||||||
unsynced_titles = set([p.title for p in unsynced_photos])
|
unsynced_titles = set([p.title for p in unsynced_photos])
|
||||||
for title in unsynced_titles:
|
for title in unsynced_titles:
|
||||||
# get photos by title
|
# get unsynced photos by title
|
||||||
photos = Photo.select().where(Photo.title == title).order_by(Photo.created_at.asc())
|
photos = Photo.select().where(Photo.title == title, Photo.synced == False).order_by(Photo.created_at.asc())
|
||||||
if len(photos) > 1:
|
if len(photos) > 1:
|
||||||
batches = [photos[i:i+4] for i in range(0, len(photos), 4)]
|
batches = [photos[i:i+4] for i in range(0, len(photos), 4)]
|
||||||
for i, batch in enumerate(batches):
|
for i, batch in enumerate(batches):
|
||||||
idx = i + 1
|
idx = i + 1
|
||||||
status = f'{title} ({idx}/{len(batches)}) \n'
|
status = f'{title} ({idx}/{len(batches)})'
|
||||||
media_ids = []
|
media_ids = []
|
||||||
for p in batch:
|
for p in batch:
|
||||||
# upload photo to mastodon
|
# upload photo to mastodon
|
||||||
@ -163,7 +163,7 @@ for title in unsynced_titles:
|
|||||||
img_id = upload_photo_to_mastodon(photo_url)
|
img_id = upload_photo_to_mastodon(photo_url)
|
||||||
if img_id:
|
if img_id:
|
||||||
media_ids.append(img_id)
|
media_ids.append(img_id)
|
||||||
status += f'{short_url} \n'
|
status += f'\n{short_url}'
|
||||||
else:
|
else:
|
||||||
logger.error('Error: {}'.format(p.title))
|
logger.error('Error: {}'.format(p.title))
|
||||||
# post to mastodon
|
# post to mastodon
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user