-1

ookay, so I'm in a bit of a pickle here.

This is my code:


profiles = [profiles here]
f_profiles = [formatted profiles go here, this is useless, im just doing this to make the printing stuff look more pretty]

DAILY_SCHEDULED_TIME = "6:00"


def routine():

    print(colored(f"Getting from {f_profiles}"))
    for profile in profiles:
        print(colored(f"\nFetching from: {profile}\n"))
        os.system(f"instaloader {profile} --no-video-thumbnails --no-captions --no-metadata-json --no-compress-json --no-profile-pic --dirname-pattern={os.getcwd()}\\media\\")

def attemptRoutine():
    while(1):
        try:
            routine()
            break
        except OSError as err:
            print("Routine Failed on " + "OS error: {0}".format(err))
            time.sleep(60*60)

#attemptRoutine()
schedule.every().day.at("06:00").do(attemptRoutine)

attemptRoutine()
while True:
    schedule.run_pending()  
    time.sleep(60) # wait one min

what this does is just download memes so my other script can send them as an SMS to my phone.

Essentially what my problem here is, is that this script goes on forever. It'll download 100's of photos and videos from a profile when I only really need around 12 per user.

I'm in a pickle here because It's a for loop for ever profile in profiles so I need a way to quit what im doing with one profile, so it can move on to the next in a certain amount of time.

e.g

profile 1 -> Downloading memes. 
(20 secs pass)
profile 1 -> quits -> profile 2 starts

etc and etc

but what is going on now:

profile 1 -> Downloading memes
(20 secs pass)
profile 1 -> Downloading Memes
(1 hour pass)
profile 1 -> Downloading memes
etc etc

this is because as I stated above, there are 100's of 1000's of photos and videos on the profiles. sooo, that's a bit of a prob.

How can I do this??

TL;DR I want to make a timer in a for loop. so that it could stop what its doing and continue with another object in the list (for loop) after a certain amount of time

Essentially, I want to skip to the next iteration in my for loop after n seconds.

If someone can help, please do so, any and all help would be appreciated though if you could dumb-down what I should do, how it works or things like that, that'd be appreciated also.

Thanks!

Ethan
  • 1

1 Answers1

0

If your code is utilizing instaloader, then it looks like the documentation specifies that there is a --count parameter that you could specify the number of posts to download:

--count COUNT, -c
Do not attempt to download more than COUNT posts. Applies to #hashtag, %location_id, :feed, and :saved.
j_b
  • 1,975
  • 3
  • 8
  • 14