-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathdocker_quickstart.py
More file actions
83 lines (67 loc) · 3.23 KB
/
docker_quickstart.py
File metadata and controls
83 lines (67 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import json
import os
import traceback
import logging
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from urllib3.exceptions import NewConnectionError, ProtocolError, MaxRetryError
from include import Bot
from include.proxy import get_proxy
# Write your automation here
# Stuck ? Look at the github page or the examples in the examples folder
# If you want to enter your Instagram Credentials directly just enter
# username=<your-username-here> and password=<your-password> into InstaPy
# e.g like so InstaPy(username="instagram", password="test1234")
def selenium_driver(selenium_url):
mobile_emulation = {"deviceName": "iPhone 5"}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--incognito')
chrome_options.add_argument("start-maximized") # open Browser in maximized mode
chrome_options.add_argument("disable-infobars") # disabling infobars
chrome_options.add_argument("--disable-extensions") # disabling extensions
chrome_options.add_argument("--no-sandbox")
chrome_options.add_argument("--disable-dev-shm-usage") # overcome limited resource problems
chrome_options.add_experimental_option("excludeSwitches", ['enable-automation'])
chrome_options.add_experimental_option("mobileEmulation", mobile_emulation)
selenium_driver = webdriver.Remote(command_executor=selenium_url,
desired_capabilities=chrome_options.to_capabilities())
return selenium_driver
def run(count=0):
global bot
try:
bot = Bot(multi_logs=True, selenium_local_session=False,
proxy_address_port=get_proxy(os.environ.get('INSTA_USER')), disable_image_load=True)
selenium_url = "http://%s:%d/wd/hub" % (os.environ.get('SELENIUM', 'selenium'), 4444)
bot.set_selenium_remote_session(logger=logging.getLogger(), selenium_url=selenium_url, selenium_driver=selenium_driver(selenium_url))
bot.login()
bot.set_settings()
bot.act()
except (NewConnectionError, WebDriverException) as exc:
bot.logger.warning("Exception in run: %s; try again: count=%s" % (exc, count))
if count > 3:
print("Exception in run(): %s \n %s" % (exc, traceback.format_exc()))
report_exception(exc)
else:
run(count=count + 1)
except (ProtocolError, MaxRetryError) as exc:
bot.logger.error("Abort because of %s; \n%s" % (exc, traceback.format_exc()))
return
except Exception as exc:
print("Exception in run(): %s \n %s" % (exc, traceback.format_exc()))
report_exception(exc)
finally:
print("END")
bot.end()
def report_exception(exc, subject="%s: Excepiton: %s"):
email = os.environ.get("DEV_EMAIL")
api = os.environ.get("API")
if email and api:
import requests
requests.post("%s/api/mail/" % api,
json.dumps({"username": "ERROR", "email": email,
"subject": subject % (
os.environ.get('INSTA_USER', 'UnknownUser'), exc),
"body": "%s" % traceback.format_exc(),
"once": True
}))
run()