Skip to content

Instantly share code, notes, and snippets.

@dev4Fun
dev4Fun / bot.py
Created September 10, 2020 03:23
def fetch_posts_from_explore(self, max_id=0):
text = self.load_pre_from_url(
f"https://www.instagram.com/explore/grid/?is_prefetch=false&omit_cover_media=false&module=explore_popular&use_sectional_payload=true&cluster_id=explore_all%3A0&include_fixed_destinations=true&max_id={max_id}")
return parse_explore(text)
def load_pre_from_url(self, url):
self.open_and_switch_to_tab(url)
try:
self.wait_until(ec.presence_of_element_located((By.TAG_NAME, 'pre')), timeout=7)
return self.driver.find_element_by_tag_name('pre').text
@dev4Fun
dev4Fun / bot.py
Created September 10, 2020 03:22
# additional imports
import logging
import config
from selenium.common.exceptions import NoSuchElementException, TimeoutException
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as ec
@dev4Fun
dev4Fun / bot.py
Created September 10, 2020 03:22
from selenium.webdriver.remote.webdriver import WebDriver
class AutoLikeBot:
def __init__(self, driver: WebDriver, post_filter, running_strategy):
self.driver = driver
self.post_filter = post_filter
self.running_strategy = running_strategy
def like_from_explore(self):
import pathlib
from selenium import webdriver
import config
def configure_chrome_driver():
options = webdriver.ChromeOptions()
options.add_argument(f"user-data-dir={pathlib.Path(__file__).parent.absolute().joinpath('chrome-profile')}")
import pathlib
USERNAME = '' # instagram account
PASSWORD = '' # instagram password
# executable path for chrome driver
DRIVER_EXECUTABLE_PATH = pathlib.Path(__file__).parent.absolute().joinpath("chromedriver")
IGNORE_TAGS = [] # exact case non sensitive matching
Tue 04 10:08:23 RedditBot_1 INFO IchnagedIt1 - Processed 'I need many karmas for many things'.
Tue 04 10:08:24 RedditBot_2 INFO IchnagedIt2 - Processed 'Upvote plz im getting close to 500 karma i need 4000 doe'. Upvoted and replied to 1 comments
Tue 04 10:08:25 RedditBot_0 INFO IchnagedIt0 - Processed 'just upvote'. Upvoted and replied to 1 comments
Tue 04 10:08:27 RedditBot_1 INFO IchnagedIt1 - Processed 'Please sir'. Upvoted and replied to 1 comments
Tue 04 10:08:27 RedditBot_3 INFO IchnagedIt3 - Processed 'mmmmm'. Upvoted and replied to 2 comments
Tue 04 10:08:29 RedditBot_6 INFO IchnagedIt6 - Processed 'g i m m e k a r m a p l e a s e'. Upvoted and replied to 2 comments
# main.py
if __name__ == '__main__':
credentials = read_all_credentials()
with BotOrchestrator(credentials) as orchestrator:
orchestrator.parse_different_submissions("FreeKarma4U", limit=120)
orchestrator.log_karma()
def __init__(self, credentials: dict, reddit_client=None, all_bot_names=None):
...
self.all_bot_names = all_bot_names if all_bot_names else {username}
def _compute_comments_to_ignore(self, comments) -> dict:
to_ignore = {}
for comment in comments:
if comment.author and comment.author.name in self.all_bot_names:
to_ignore[comment.id] = comment
for reply in comment.replies:
if reply.author and reply.author.name in self.all_bot_names:
to_ignore[reply.id] = reply
return to_ignore
# orchestrator.py
import itertools
import random
from concurrent.futures import wait
from concurrent.futures.thread import ThreadPoolExecutor
from bot import RedditBot
class BotOrchestrator: