diff --git a/instagram_utils/management/commands/update_instagram.py b/instagram_utils/management/commands/update_instagram.py index 11c2c130f2c22d23bf625eaeefd0a1973ebdf5e4..fe532e24a7713a8fc4b5d4992ed5e71a614119bb 100644 --- a/instagram_utils/management/commands/update_instagram.py +++ b/instagram_utils/management/commands/update_instagram.py @@ -6,10 +6,7 @@ from ...services import InstagramDownloadService class Command(BaseCommand): def handle(self, *args, **options): - service = InstagramDownloadService( - app_id=settings.INSTAGRAM_APP_ID, - app_secret=settings.INSTAGRAM_APP_SECRET, - ) + service = InstagramDownloadService() service.perform_update() self.stdout.write("\nInstagram post update finished.") diff --git a/instagram_utils/services.py b/instagram_utils/services.py index f7bdb0f8160863d745d5f74c80794e9e681dcecc..2ed402108763ee552197e51eff86e2970d4b1d91 100644 --- a/instagram_utils/services.py +++ b/instagram_utils/services.py @@ -46,7 +46,15 @@ class InstagramDownloadService: profile = instaloader.Profile.from_username(loader.context, username) + post_position = 0 + for remote_post in profile.get_posts(): + if post_position == 64: + # Don't go past 64 saved posts + return + + post_position += 1 + if remote_post.is_video: logger.info( "Instagram post ID %s is a video, skipping.", remote_post.shortcode @@ -61,12 +69,17 @@ class InstagramDownloadService: continue + caption = remote_post.caption + + if len(caption) > 255: + caption = caption[:255] + "..." + local_post_instance = InstagramPost( remote_id=remote_post.shortcode, author_name=profile.full_name, author_username=profile.username, timestamp=remote_post.date_local, - caption=remote_post.caption, + caption=caption, url=f"https://instagram.com/p/{remote_post.shortcode}", ) @@ -82,8 +95,6 @@ class InstagramDownloadService: remote_post.shortcode, ) - post_position += 1 - def perform_update(self) -> None: for username in self.get_usernames(): self.parse_media_for_user(username)