Skip to content

Commit

Permalink
Configure Web Server Compatibility
Browse files Browse the repository at this point in the history
Update to v1.4
  • Loading branch information
davidwickerhf committed Oct 21, 2020
1 parent c84b835 commit 069be28
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
37 changes: 22 additions & 15 deletions instaclient/client/instaclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import NoSuchElementException, TimeoutException
import time
import time, os

from instaclient.utilities.utilities import *
from instaclient.errors import *
Expand All @@ -15,31 +15,38 @@

class InstaClient:
CHROMEDRIVER=1
def __init__(self, username: str=None, password: str=None, driver: int=CHROMEDRIVER):
LOCAHOST=1
WEB_SERVER=2
def __init__(self, driver_type: int=CHROMEDRIVER, host=None):
"""
Creates an instance of instaclient class.
Args:
You can omit the username and password if you prefer to insert them in the client.login() method:
username:str: The username of the user
password:str: The password of the user
driver_location:str: Path of the driver file (must be in the root folder of your project)
wait_time:int: (Seconds) time to wait before raising driver exception
driver_type:int:
InstaClient.CHROMEDRIVER for a Chrome instance
host:int:
InstaClient.LOCALHOST for testing / running locally
InstaClient.WEB_SERVER for production / running on a web server
Attributes:
driver: Instance of the Selenium Webdriver (defaults to Chrome)
logged_in:bool: Boolean whether current user is logged in or not. Defaults to False
"""

self.username = username
self.password = password

try:
if driver == self.CHROMEDRIVER:
self.driver = webdriver.Chrome('instaclient/drivers/chromedriver.exe')
if driver_type == self.CHROMEDRIVER:
if host in (None, self.LOCAHOST):
# Running on web server
chrome_options = webdriver.ChromeOptions()
chrome_options.binary_location = os.environ.get("GOOGLE_CHROME_BIN")
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-dev-shm-usage")
chrome_options.add_argument("--no-sandbox")
self.driver = webdriver.Chrome(executable_path=os.environ.get("CHROMEDRIVER_PATH"), chrome_options=chrome_options)
else:
# Running locally
self.driver = webdriver.Chrome('instaclient/drivers/chromedriver.exe')
else:
raise InvaildDriverError(driver)
raise InvaildDriverError(driver_type)
self.driver.maximize_window()
except Exception as error:
raise error
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
setup(
name = 'instaclient', # How you named your package folder (MyLib)
packages = find_packages(exclude=['tests']), # Chose the same as "name"
version = '1.3', # Start with a small number and increase it with every change you make
version = '1.4', # Start with a small number and increase it with every change you make
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
description = 'Instagram client built with Python 3.8 and the Selenium package.',
long_description=README,
long_description_content_type="text/markdown",
author = 'David Wicker', # Type in your name
author_email = 'davidwickerhf@gmail.com', # Type in your E-Mail
url = 'https://github.com/wickerdevs/py-instaclient', # Provide either the link to your github or to your website
download_url = 'https://github.com/wickerdevs/py-instaclient/archive/v1.3.tar.gz', # I explain this later on
download_url = 'https://github.com/wickerdevs/py-instaclient/archive/v1.4.tar.gz', # I explain this later on
keywords = ['INSTAGRAM', 'BOT', 'INSTAGRAM BOT', 'INSTAGRAM CLIENT'], # Keywords that define your package best
install_requires=[ # I get to this in a second
'selenium',
Expand Down

0 comments on commit 069be28

Please sign in to comment.