-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patches, code and config's structure reformatted and added new features
Code structure reformatted Config.ini structure reformatted Added force_search and specific_file as parameters to config Patch - Clicking on a random user while scrolling down Patch - Scrolling up a bit while scrolling down Added 'ctrl+c' (SIGINT) to stop execution and save all work done until the moment New informative messages in CLI Waiting time more efficient and cleaner README.md edited Solved patch by executing JavaScript to scroll down
- Loading branch information
Showing
8 changed files
with
559 additions
and
290 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
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from .browser import Tab | ||
from .instagram_bot import Bot |
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
|
||
from selenium import webdriver # type: ignore | ||
from typing import Optional | ||
from sys import platform | ||
|
||
class Browser: | ||
def __init__(self, window:bool=True, binary_location:Optional[str]=None, default_lang:bool=False, **kwargs): | ||
|
||
if platform == 'linux' or platform == 'linux2': | ||
driver_file_name = 'chrome_linux' | ||
elif platform == 'win32': | ||
driver_file_name = 'chrome_windows.exe' | ||
elif platform == 'darwin': | ||
driver_file_name = 'chrome_mac' | ||
|
||
driver_path = os.path.join(os.getcwd() , f'drivers{os.path.sep}{driver_file_name}') | ||
|
||
os.chmod(driver_path , 0o755) | ||
|
||
options = webdriver.ChromeOptions() | ||
|
||
if not default_lang: | ||
options.add_experimental_option('prefs', {'intl.accept_languages': 'en,en_US'}) | ||
|
||
options.headless = not window ; | ||
|
||
if binary_location: | ||
options.binary_location = binary_location | ||
|
||
|
||
self.driver = webdriver.Chrome(executable_path=driver_path, options=options) | ||
|
||
|
||
class Tab: | ||
|
||
def __init__(self, driver:webdriver.Chrome, url:str): | ||
self.driver = driver | ||
self.url = url | ||
|
||
|
||
def new_tab(self, url:str='https://www.google.com'): | ||
|
||
''' | ||
Opens a new tab on Browser | ||
Args: | ||
- url : to navigate after openning tab | ||
''' | ||
|
||
self.driver.execute_script(f'window.open(\'{url}\');') | ||
self.driver.switch_to.window(self.driver.window_handles[-1]) | ||
|
||
|
||
def close_tab(self): | ||
|
||
''' | ||
Close the last tab on Browser | ||
''' | ||
|
||
self.driver.close() | ||
self.driver.switch_to.window(self.driver.window_handles[-1]) # could write 'main' but later on could be modified | ||
|
||
|
||
def __enter__(self): | ||
self.new_tab(self.url) | ||
|
||
|
||
def __exit__(self, *exc): | ||
self.close_tab() |
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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Iterator, List | ||
from itertools import chain | ||
|
||
class Comments: | ||
|
||
def __init__(self, iter_connections:Iterator[str], parts_expr:List[str]): | ||
self.iter_connections = iter_connections | ||
self.parts_expr = parts_expr | ||
|
||
def generate(self) -> Iterator[str]: | ||
|
||
''' | ||
Generates every comment from an expression and a list of connections | ||
''' | ||
|
||
last_part = self.parts_expr[-1] | ||
|
||
while True: | ||
|
||
if len(self.parts_expr) == 1: | ||
yield last_part | ||
|
||
else: | ||
|
||
try: | ||
|
||
users = next(self.iter_connections) | ||
except StopIteration: | ||
return | ||
|
||
comment = ''.join(chain.from_iterable(zip(self.parts_expr, users))) | ||
|
||
yield (comment + last_part).replace(r'\@', '@') |
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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from contextlib import contextmanager | ||
from selenium import webdriver # type: ignore | ||
|
||
class ImplicitlyWait: | ||
def __init__(self, driver:webdriver, timeout:int): | ||
self.driver = driver | ||
self.timeout = timeout | ||
|
||
def enable(self): | ||
|
||
''' | ||
Enable implicitly wait so it doesn't throw errors without waiting some time in order to let the element appear | ||
''' | ||
|
||
self.driver.implicitly_wait(self.timeout) | ||
|
||
def disable(self): | ||
|
||
''' | ||
Disable implicitly wait so it doesn't wait for the element to appear. This can cause errors if not handled with a 'Explicitly Wait' | ||
''' | ||
|
||
self.driver.implicitly_wait(0) | ||
|
||
@contextmanager | ||
def ignore(self): | ||
|
||
''' | ||
Ingore implicitly wait in the current block of code by disabling and enabling again when finished | ||
''' | ||
|
||
try: | ||
yield self.disable() | ||
finally: | ||
self.enable() |
Oops, something went wrong.