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
// NumberGuessingGame.cpp : Defines the entry point for the console application. | |
// This is an easy game which asks user a number to guess in [1, 100] range and tries to find that number with no more than 7 questiosn :) | |
#include "stdafx.h" | |
#include "std_lib_facilities.h" | |
bool binary_search(int min, int max, int guess_num) | |
{ | |
string verify; | |
cout << "Is the number you are guessing less than "<<guess_num<<"? (`yes` or `no`)\n"; |
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
def interact_by_URL(self, | |
urls=[], | |
media=None, | |
interact=False): | |
""" Interact on images at given URLs """ | |
if self.aborting: | |
return self | |
self.logger.info("Starting to interact by given URLs\n") |
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
"""Module which handles the follow features like unfollowing and following""" | |
import time | |
import os | |
import random | |
import json | |
import csv | |
import sqlite3 | |
from datetime import datetime, timedelta | |
from math import ceil |
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
def emergency_exit(browser, username, logger): | |
""" Raise emergency if the is no connection to server OR user is not logged in """ | |
# ping server | |
connection_state = ping_server("instagram.com") | |
if connection_state == False: | |
logger.error("{} is not connected to the server!".format(username)) | |
return True | |
else: |
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
def ping_server(host): | |
""" | |
Returns True if host (str) responds to a ping request. | |
Remember that a host may not respond to a ping (ICMP) request even if the host name is valid. | |
""" | |
# Ping command count option as function of OS | |
param = "-n" if system().lower()=="windows" else "-c" | |
# Building the command. Ex: "ping -c 1 google.com" | |
command = ' '.join(["ping", param, '1', str(host)]) |
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
def find_user_id(browser, username, logger): | |
try: | |
user_id = browser.execute_script( | |
"return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.owner.id") | |
except WebDriverException: | |
try: | |
browser.execute_script("location.reload()") | |
user_id = browser.execute_script( | |
"return window._sharedData.entry_data.PostPage[0].graphql.shortcode_media.owner.id") | |
except WebDriverException: |
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
@contextmanager | |
def new_tab(browser): | |
""" USE once a host tab must remain untouched and yet needs extra data- get from guest tab """ | |
try: | |
# add a guest tab | |
browser.execute_script("window.open()") | |
# switch to the guest tab | |
browser.switch_to.window(browser.window_handles[1]) | |
yield |
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
def explicit_wait(browser, track, ec_params, logger, timeout=35, notify=True): | |
""" | |
Explicitly wait until expected condition validates | |
:param browser: webdriver instance | |
:param track: short name of the expected condition | |
:param ec_params: expected condition specific parameters - [param1, param2] | |
:param logger: the logger instance | |
""" | |
# list of available tracks: |
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
def truncate_float(number, precision, round=False): | |
""" Truncate (shorten) a floating point value at given precision """ | |
# don't allow a negative precision [by mistake?] | |
precision = abs(precision) | |
if round: | |
# python 2.7+ supported method [recommended] | |
short_float = round(number, precision) |