Skip to content

Instantly share code, notes, and snippets.

View uluQulu's full-sized avatar
🚙
Coding ...

Şəhriyar Cəfər Qulu uluQulu

🚙
Coding ...
  • Azərbaycan
View GitHub Profile
@uluQulu
uluQulu / guessed_Number_finder.cpp
Last active May 11, 2018 17:06
Finds the guessed number in range [0, 128) with less than 7 questions
// 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";
@uluQulu
uluQulu / interact_by_URL.py
Created June 10, 2018 15:33
A new feature to do all kind of interactions on given URLs
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")
@uluQulu
uluQulu / web_address_navigator.py
Created August 16, 2018 13:45
fgisslen - selenium TimeoutExeption handling
def web_adress_navigator(browser, link):
"""Checks and compares current URL of web page and the URL to be navigated and if it is different, it does navigate"""
total_timeouts = 0
try:
current_url = browser.current_url
except WebDriverException:
try:
current_url = browser.execute_script("return window.location.href")
except WebDriverException:
@uluQulu
uluQulu / unfollow_util.py
Created August 23, 2018 01:05
Uncertain state handling for @tompicca
"""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
@uluQulu
uluQulu / emergency_exit.py
Created August 23, 2018 01:07
Emergency exit if there is a serious situation
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:
@uluQulu
uluQulu / ping_server.py
Last active August 23, 2018 17:13
A universal server ping tool
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)])
@uluQulu
uluQulu / find_user_id.py
Created August 28, 2018 13:56
Finds user ID from page content
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:
@uluQulu
uluQulu / new_tab.py
Last active September 1, 2018 16:49
Open a new tab; Do stuff in it; Close it
@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
@uluQulu
uluQulu / explicit_wait.py
Last active October 29, 2018 19:44
Generic explicit wait function for InstaPy to be used with selenium webdriver
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:
@uluQulu
uluQulu / truncate_float.py
Last active November 4, 2018 17:18
Truncate (shorten) a floating point value at given precision.
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)