-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
353ee37
commit 63fccfc
Showing
4 changed files
with
75 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from .utils import get_client, load_config, get_user_id, get_followers, calculate_sleep_time | ||
from .utils import get_client, load_config, get_user_id, get_followers, calculate_sleep_time, logger | ||
from .follow import follow_user_followers, unfollow_users | ||
from .like_media import like_recent_posts | ||
from .comment import comment_on_media |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,48 @@ | ||
import instabot | ||
import asyncio | ||
from instabot import follow_user_followers, unfollow_users, comment_on_media | ||
from instabot import logger | ||
from threading import Thread | ||
|
||
async def main(account): | ||
username = account['username'] | ||
password = account['password'] | ||
|
||
logger.info(f'Started process for {username}') | ||
|
||
async with asyncio.TaskGroup() as tg: | ||
if account['follow_users']['enabled']: | ||
cl = instabot.get_client(username, password) | ||
follow_task = tg.create_task( | ||
follow_user_followers(cl, account) | ||
) | ||
if account['unfollow_users']['enabled']: | ||
cl = instabot.get_client(username, password) | ||
unfollow_task = tg.create_task( | ||
unfollow_users(cl, account['unfollow_users']['unfollow_after_days']) | ||
) | ||
if account['comment_on_media']['enabled']: | ||
cl = instabot.get_client(username, password) | ||
comment_task = tg.create_task( | ||
comment_on_media(cl, account) | ||
) | ||
|
||
def run_account(account): | ||
asyncio.run(main(account)) | ||
|
||
async def main(accounts): | ||
for account in accounts: | ||
username = account['username'] | ||
password = account['password'] | ||
|
||
cl = instabot.get_client(username, password) | ||
|
||
async with asyncio.TaskGroup() as tg: | ||
if account['follow_users']['enabled']: | ||
follow_task = tg.create_task( | ||
follow_user_followers(cl, account) | ||
) | ||
if account['unfollow_users']['enabled']: | ||
unfollow_task = tg.create_task( | ||
unfollow_users(cl, account['unfollow_users']['unfollow_after_days']) | ||
) | ||
if account['comment_on_media']['enabled']: | ||
comment_task = tg.create_task( | ||
comment_on_media(cl, account) | ||
) | ||
|
||
print("All tasks have finished...") | ||
if __name__ == "__main__": | ||
config = instabot.load_config('config.json') | ||
|
||
# Get the accounts from the configuration file | ||
accounts = config['accounts'] | ||
asyncio.run(main(accounts)) | ||
|
||
# Create a thread for each account and run the main function | ||
account_threads = [] | ||
for account in accounts: | ||
account_thread = Thread(target=run_account, args=(account,)) | ||
account_threads.append(account_thread) | ||
account_thread.start() | ||
|
||
# Wait for all account threads to finish | ||
for account_thread in account_threads: | ||
account_thread.join() |