Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
else:
# we got content
# check if there is something new to watch otherwise we just return 0
seen = 0
if (action_type != "tag") and (
response["data"]["reels_media"][0]["seen"] is not None
):
seen = response["data"]["reels_media"][0]["seen"]
index = 1
if simulate is True:
for item in response["data"]["reels_media"][0]["items"]:
if item["taken_at_timestamp"] <= seen:
continue
else:
headers = {
"User-Agent": Settings.user_agent,
"X-CSRFToken": csrftoken,
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/x-www-form-urlencoded",
}
response = session.post(
"https://www.instagram.com/stories/reel/seen",
data={
"reelMediaId": item["id"],
"reelMediaOwnerId": item["owner"]["id"],
"reelId": reel_id,
"reelMediaTakenAt": item["taken_at_timestamp"],
"viewSeenAt": math.floor(time.time()),
},
headers=headers,
)
logger.info(" --> simulated watch reel # {}".format(index))
file_handler = logging.FileHandler('{}general.log'.format(self.logfolder))
file_handler.setLevel(logging.DEBUG)
extra = {"username": self.username}
logger_formatter = logging.Formatter('%(levelname)s [%(asctime)s] [%(username)s] %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
file_handler.setFormatter(logger_formatter)
logger.addHandler(file_handler)
if show_logs is True:
console_handler = logging.StreamHandler()
console_handler.setLevel(logging.DEBUG)
console_handler.setFormatter(logger_formatter)
logger.addHandler(console_handler)
logger = logging.LoggerAdapter(logger, extra)
Settings.loggers[__name__] = logger
Settings.logger = logger
return logger
if self.proxy_address and self.proxy_port > 0:
firefox_profile.set_preference('network.proxy.type', 1)
firefox_profile.set_preference('network.proxy.http',
self.proxy_address)
firefox_profile.set_preference('network.proxy.http_port',
self.proxy_port)
firefox_profile.set_preference('network.proxy.ssl',
self.proxy_address)
firefox_profile.set_preference('network.proxy.ssl_port',
self.proxy_port)
self.browser = webdriver.Firefox(firefox_profile=firefox_profile)
else:
chromedriver_location = Settings.chromedriver_location
chrome_options = Options()
chrome_options.add_argument('--dns-prefetch-disable')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--lang=en-US')
chrome_options.add_argument('--disable-setuid-sandbox')
# this option implements Chrome Headless, a new (late 2017)
# GUI-less browser. chromedriver 2.9 and above required
if self.headless_browser:
chrome_options.add_argument('--headless')
# Replaces browser User Agent from "HeadlessChrome".
user_agent = "Chrome"
chrome_options.add_argument('user-agent={user_agent}'
.format(user_agent=user_agent))
capabilities = DesiredCapabilities.CHROME
# Proxy for chrome
def get_workspace():
""" Make a workspace ready for user """
if WORKSPACE["path"]:
workspace = verify_workspace_name(WORKSPACE["path"])
else:
home_dir = get_home_path()
workspace = "{}/{}".format(home_dir, WORKSPACE["name"])
message = "Workspace in use: \"{}\"".format(workspace)
highlight_print(Settings.profile["name"],
message,
"workspace",
"info",
Settings.logger)
update_workspace(workspace)
update_locations()
return WORKSPACE
def get_database(make=False):
address = Settings.database_location
logger = Settings.logger
credentials = Settings.profile
id, name = credentials["id"], credentials['name']
address = validate_database_address()
if not os.path.isfile(address) or make:
create_database(address, logger, name)
id = get_profile(name, address, logger) if id is None or make else id
return address, id
def quota_supervisor(job, update=False):
""" Supervise activity flow through action engines and take measures"""
# --ACTION----------ENGINE--------------FILE--------------OPTION--- #
# Like `like_image` [like_util.py] jump|sleep #
# Comment `comment_image` [comment_util.py] jump|sleep #
# Follow `follow_user` [unfollow_util.py] jump|sleep #
# Unfollow `unfollow_user` [unfollow_util.py] jump|sleep #
# *Server call `update_activity` [util.py] exit|sleep #
# ----------------------------------------------------------------- #
global configuration
configuration = Settings.QS_config
if configuration and configuration["state"] is True:
# in-file global variables for the QS family
global records, logger, this_minute, this_hour, today
records = Storage.record_activity
logger = Settings.logger
this_minute, this_hour, today = get_time(["this_minute",
"this_hour",
"today"])
if update: # update the action's record in global storage
update_record(job)
else: # inspect and control the action's availability
quota_state = controller(job)
return quota_state
def highlight_print(
username=None, message=None, priority=None, level=None, logger=None
):
""" Print headers in a highlighted style """
# can add other highlighters at other priorities enriching this function
# find the number of chars needed off the length of the logger message
output_len = 28 + len(username) + 3 + len(message) if logger else len(message)
show_logs = Settings.show_logs
if priority in ["initialization", "end"]:
# OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
# E.g.: Session started!
# oooooooooooooooooooooooooooooooooooooooooooooooo
upper_char = "O"
lower_char = "o"
elif priority == "login":
# ................................................
# E.g.: Logged in successfully!
# ''''''''''''''''''''''''''''''''''''''''''''''''
upper_char = "."
lower_char = "'"
elif priority == "feature": # feature highlighter