Hi.
I'm wondering how to setup a scheduler.
I tried the Automate with Schedule
Schedule is an in-process scheduler for periodic jobs that uses the builder pattern for configuration. Schedule lets you run Python functions periodically at pre-determined intervals using a simple, human-friendly syntax.
pip install schedule
from instapy import InstaPy
import schedule
import time
def job():
try:
session = InstaPy(selenium_local_session=False) # Assuming running in Compose
session.set_selenium_remote_session(selenium_url='http://selenium:4444/wd/hub')
session.login()
session.set_do_comment(enabled=True, percentage=20)
session.set_comments(['Well done!'])
session.set_do_follow(enabled=True, percentage=5, times=2)
session.like_by_tags(['love'], amount=100, media='Photo')
session.end()
except:
import traceback
print(traceback.format_exc())
schedule.every().day.at("6:35").do(job)
schedule.every().day.at("16:22").do(job)
while True:
schedule.run_pending()
time.sleep(1)
but they don't really make sense to me.
I also looked into https://github.com/Tkd-Alex/Telegram-InstaPy-Scheduling but that's not making much sense to me on how to get a token. Could anyone provide me with some clues?
@tkd-alex ?
I'm sorry it's a pretty basic question, but where do I put this?
from instapy import InstaPy
import schedule
import timedef job():
try:
session = InstaPy(selenium_local_session=False) # Assuming running in Compose
session.set_selenium_remote_session(selenium_url='http://selenium:4444/wd/hub')
session.login()
session.set_do_comment(enabled=True, percentage=20)
session.set_comments(['Well done!'])
session.set_do_follow(enabled=True, percentage=5, times=2)
session.like_by_tags(['love'], amount=100, media='Photo')
session.end()
except:
import traceback
print(traceback.format_exc())schedule.every().day.at("6:35").do(job)
schedule.every().day.at("16:22").do(job)while True:
schedule.run_pending()
time.sleep(1)
when I try to run the first line as a command and I get this error
The program 'import' can be found in the following packages:
- imagemagick
- graphicsmagick-imagemagick-compat
Try: apt install
Am I meant to install it in the instapy.py file?
Just kind of confused and not finding many support documents about it.
Sorry I'm such a noob! Any resources would be awesome
Much appreciated.
Anyone? 馃様
@brookton Hey, I would simply use a cronjob to do that.
you can setup a cronjob with crontab -e. This will open up an editor window where you have to specify dates.
E.g. you can do that
35 6 * * * cd /InstaPy && python3.5 quickstart.py
22 16 * * * cd /InstaPy && python3.5 quickstart.py
@brookton I think this is way easier to work with and actually close to as customizable as schedule
E.g you could simply do
0 */4 * * * cd /InstaPy && python3.5 quickstart.py
To run it every 4 hours
Thank you so much Tim! It does indeed make sense now I was making it a bit too complicated.
Appreciated!
@brookton Do you think we can close this issue? 馃槈
Most helpful comment
@brookton I think this is way easier to work with and actually close to as customizable as schedule
E.g you could simply do
0 */4 * * * cd /InstaPy && python3.5 quickstart.py
To run it every 4 hours