async def set_channel(self, ctx): content = ctx.message.content.split() if len(content) <= 1: await ctx.send("Please specify a channel id.") return if not content[1].isdigit(): await ctx.send("Please use a valid id.") return channel = self.bot.get_channel(int(content[1])) if not channel: await ctx.send("Please use a valid id.") return if not isinstance(channel, discord.VoiceChannel): await ctx.send("Please use a voice channel id.") return if self.data[str(ctx.guild.id)]["main"] is not None: self.logger.warning( f"Channel already set {self.data[str(ctx.guild.id)]['main']}.") self.logger.info(f"Set main channel <{channel.name}.{channel.id}>") self.data[str(ctx.guild.id)]['main'] = channel.id await ctx.send("Main channel set.") update_json(self.data) update_data(self.data)
async def on_voice_state_update(member, before, after): # if the user connects to the set voice channel... if after.channel and after.channel.id == data[str( member.guild.id)]['main']: category = bot.get_channel(after.channel.category_id) # create a new channel, named after the member name, set permissions, and move the member to it change = await member.guild.create_voice_channel( f"{member.name}'s channel", category=category) await change.set_permissions(member, view_channel=True, connect=True) await member.move_to(change) logger.info( f"{member.name} joined and was moved to \"{member.name}'s channel\"" ) # update the data data[str(member.guild.id)]["channels"][str(change.id)] = member.id # if the user disconnects from a personnal voice channel if before.channel and str(before.channel.id) in data[str( member.guild.id)]["channels"]: if not len( before.channel.members ): # if there is no more users in the voice channel, delete it data[str(member.guild.id)]['channels'].pop(str(before.channel.id)) await before.channel.delete(reason='Last member leave') logger.info( f"Personnal voice channel \"{before.channel.name}\" is empty so it has been deleted." ) update_json(data) update_data(data)
def save_posts(self, user_id, results): updater_posts = utils.update_json(self.filename) updater_user = utils.update_json(self.filename2) for result in results: if result.id_str in updater_posts.data: updater_posts.data[result.id_str]["liked_by"] += [user_id] updater_posts.data[result.id_str]["liked_by"] = list(set(updater_posts.data[result.id_str]["liked_by"])) continue hashtags = [hashtag["text"] for hashtag in result.entities["hashtags"]] if "hashtags" in result.entities else [] media = [media["media_url_https"] for media in result.entities["media"]] if "media" in result.entities else [] dic = { result.id_str:{ "creator_id": result.user.id, "created_at":result.created_at, "liked_by": [user_id], "text": result.full_text, "hashtags": hashtags, "media": media} } updater_posts.data.update(dic) if user_id in updater_user.data: updater_user.data[user_id]["posts_liked"]+=[result.id_str] updater_user.data[user_id]["posts_liked"] = list(set(updater_user.data[user_id]["posts_liked"])) updater_posts.write() updater_user.write()
def users_likes(self): updater = utils.update_json("users_likes.json") user_ids_obj = utils.update_json("users.json") user_ids = user_ids_obj.data.keys() for id in user_ids: if id not in updater.data: updater.data[id] = {"posts_liked": [], "posts_posted": []} updater.write()
async def on_guild_join(guild): update_data(data) data[str(guild.id)] = {"main": None, "channels": {}} game = discord.Game(f"Manage {len(bot.guilds)} servers") await bot.change_presence(activity=game) update_json(data)
async def on_guild_remove(guild): update_data(data) del data[str(guild.id)] game = discord.Game(f"Manage {len(bot.guilds)} servers") await bot.change_presence(activity=game) update_json(data)
async def unset_channel(self, ctx): self.data[str(ctx.guild.id)]['main'] = None await ctx.send("Main channel reset.") self.logger.info("Main channel reset.") update_json(self.data) update_data(self.data)
def create_copies(): s = search_users.search() s.users_likes() file = utils.update_json("users_likes.json") for i in p.KEYWORDS: filename = "users_likes" + str(i) + ".json" duplicate = utils.update_json(filename) duplicate.data = file.data duplicate.write()
async def on_ready(): update_data(data) logger.info(f"Bot logged as {bot.user.name}") for guild in bot.guilds: if str(guild.id) not in data.keys(): data[str(guild.id)] = {"main": None, "channels": {}} game = discord.Game(f"Manage {len(bot.guilds)} servers") await bot.change_presence(activity=game) update_json(data)
async def owner(self, ctx): perm = self.perm(ctx) if perm: return await ctx.send(perm) update_data(self.data) guild_id = str(ctx.guild.id) if len(ctx.message.mentions): self.data[guild_id]['channels'][str(ctx.author.voice.channel.id)] = ctx.message.mentions[0].id await ctx.message.channel.send(f"Owner successfully changed to {ctx.message.mentions[0].name}.") update_json(self.data)
def add_user(username): """Function adds new user with username. If user exist - return false, if user doesn't exist it creates json file with 'username'.json name and writes to it an empty array. Sets active user to new user.""" if utils.is_user_exist(username): return False else: utils.update_json([], 'data/' + username + ".json") set_fields_options(username) return True
def exit_handler(): # stop recording input unhook_mouse() unhook_keyboard() # log end of session update_json( session_file, { "length": time.time() - start, # Length in seconds, preserved for accuracy "end": time.time() }) stop_recording() return 1
async def on_ready(): update_data(data) logger.info(f"Bot logged as {bot.user.name}") for guild in bot.guilds: if str(guild.id) not in data.keys(): data[str(guild.id)] = {"main": None, "channels": {}} game = discord.Game(f"Manage {len(bot.guilds)} servers") await bot.change_presence(activity=game) update_json(data) # handling the existence of the data.json file if not os.path.exists('data.json'): with open('data.json', 'w') as data: data.write('{}')
def check(self, query, page): file = utils.update_json("users.json") for id in file.data.keys(): if str(file.data[id]["query"]) == str(query) and str( file.data[id]["page"]) == str(page): print("already queried") return 0 return 1
def set_path_to_user_settings(file_types, user_config_file_path): """ Let's the end-user to set a file path for the file_types (new exceptional file_types). Updates the user_config_file with the new file_type and the path the user sets. Parameters: --- file_types: list List of new exceptional file_types user_config_file_path: str Path of the user_config JSON file """ path_info = {} print() print( f"OOPS! Unable to find path for few files types like ( {', '.join(file_types)} )" ) print('Please Provide Your Input for those File Types') if input('Wanna Continue [Y/N]?').lower() == 'y': print('*' * 10) print('*' * 10) print('Press s to Skip your Input') print( 'Press p (or) ENTER for directly storing the file in its Parent Directory' ) print('*' * 10) print('*' * 10) total_extensions = len(file_types) for i, extension in enumerate(file_types): print(f"[{i + 1}/{total_extensions}] - {extension}") path = input('\tRelative Path: ') if path.lower() == 's': print('\t\tIGNORED') continue elif path == '' or path.lower() == 'p': path = usc.PARENT path_info[extension] = path print('*' * 10) existing_path_info = utils.load_json(user_config_file_path) # Merging the current configuration the user enters with the existing user configuration updated_path_info = utils.merge_dictionaries(existing_path_info, path_info) # Updating the user_config file with the updated configuration utils.update_json(user_config_file_path, updated_path_info)
def pytest_generate_tests(metafunc): env = "prd-10" if metafunc.config.option.env is not None: env = metafunc.config.option.env if 'env' in metafunc.fixturenames: metafunc.parametrize("env", [env]) if 'username' in metafunc.fixturenames: if metafunc.config.option.username is not None: metafunc.parametrize("username", [metafunc.config.option.username]) else: metafunc.parametrize("username", [ metafunc.config._variables["environments"][env]["data"] ["users"]["default"]["username"] ]) if 'password' in metafunc.fixturenames: if metafunc.config.option.password is not None: metafunc.parametrize("password", [metafunc.config.option.password]) else: metafunc.parametrize("password", [ metafunc.config._variables["environments"][env]["data"] ["users"]["default"]["password"] ]) if 'domain' in metafunc.fixturenames and metafunc.config.option.domain is not None: metafunc.parametrize('domain', [metafunc.config.option.domain]) if 'browsertype' in metafunc.fixturenames and metafunc.config.option.browsertype is not None: metafunc.parametrize("browsertype", [metafunc.config.option.browsertype]) if 'client_id' in metafunc.fixturenames and metafunc.config.option.client_id is not None: metafunc.parametrize("client_id", [metafunc.config.option.client_id]) if 'client_secret' in metafunc.fixturenames and metafunc.config.option.client_secret is not None: metafunc.parametrize("client_secret", [metafunc.config.option.client_secret]) if 'scopes' in metafunc.fixturenames and metafunc.config.option.scopes is not None: metafunc.parametrize("scopes", [metafunc.config.option.scopes]) if 'api_key' in metafunc.fixturenames and metafunc.config.option.api_key is not None: metafunc.parametrize("api_key", [metafunc.config.option.api_key]) if type(metafunc.config.option.tdata) == str: user_test_data = metafunc.config.option.tdata.split(".") utils.update_json(metafunc.config._variables, user_test_data[:-1], user_test_data[-1])
def start_logging(game): global start start = time.time() # log start time with open(session_file, "a") as f: json.dump({"input start": start}, f) # set the hook hook_keyboard(on_keyboard_event) hook_mouse(on_mouse_event) start_game(game) update_json(session_file, {"game start": time.time(), "game": game}) start_recording() time.sleep(1) update_json(session_file, {"recording start": get_obs_log_time()}) # set exit handler to log session data print("registering exit handler") atexit.register(exit_handler) # listen for input wait_messages()
def all_likes(self, user_id): file = utils.update_json("users.json") if user_id in file.data: user = file.data[user_id] fav_count = user["favorites_count:"] self.filename = user["query"]+".json" else: user = self.api.get_user(id=user_id) fav_count = user.favourites_count pages = min(int(fav_count/20), p.MAX_PAGES_PER_USER) for page in (range(1, pages)): self.likes(user_id, page=page)
def save_results(self, query, page, results): updater = utils.update_json("users.json") for result in results: if result.id_str in updater.data: continue if self.profile_validity(query, result): dic = { result.id_str: { "screen_name": result.screen_name, "name": result.name, "bio": result.description, "MBTI type": "", "query": query, "page": page, "favorites_count:": result.favourites_count, "statuses_count": result.statuses_count, "location": result.location, "queried_at": datetime.today() } } updater.data.update(dic) self.saved += 1 updater.write()
def save_data(): data = request.get_json() update_json(f'{base_dir}/tmp/recent.json', data) return {"status": "ok"}, 200
def update_user_info(): """Function dump to file json_data of the active user""" return utils.update_json(options['json_data'], options['path'])
default_paths = utils.reverse_nested_list(default_paths) available_paths = {str(i): '\\'.join(default_path) for i, default_path in enumerate(default_paths)} print_paths(available_paths, user_path) choice = input("Wanna Set a new Path [Y/N]?") if choice.lower() == 'y': choice = input( 'Wanna set a path from a default paths/already set path [Y/N]?').lower() if choice == 'y': print_paths(available_paths, user_path) ip = input('Choose the path id [n to skip]: ').lower() if ip == 'n': print('SKIPPED') else: new_path = available_paths.get(ip) if not new_path is None: user_config[ext] = new_path utils.update_json(user_config_fp, user_config) print(f"Path Updated for the type {ext}") print(f"\tUpdated Path '{new_path}'") elif choice == 'n': new_path = input('Enter a Relative Path(s): ').strip() if new_path != '': user_config[ext] = new_path utils.update_json(user_config_fp, user_config) print(f"Path Updated for the type {ext}") print(f"\tUpdated Path '{new_path}'") else: print('Operation Failed! Rerun the Script again')
def config(browsertype, variables, username, password, domain, env, file=None): """ Creates a webdriver browser instance """ temp_dir = tempfile.TemporaryDirectory(None, None, utils.get_system_download_folder()) temp_download_folder = temp_dir.name if 'chrome' in browsertype: options = webdriver.ChromeOptions() options.add_argument("--window-size=1920,1200") options.add_argument("start-maximized") options.add_experimental_option( "prefs", {"download.default_directory": temp_download_folder}) browser_instance = webdriver.Chrome(options=options) elif 'firefox' in browsertype: options = webdriver.FirefoxOptions() browser_instance = webdriver.Firefox(firefox_options=options) browser_instance.maximize_window() elif 'ie' in browsertype: browser_instance = webdriver.Ie() browser_instance.maximize_window() elif 'edge' in browsertype: # Edge is very slow and all steps will throw a timeout error. browser_instance = webdriver.Edge() browser_instance.maximize_window() else: browser_name = variables['browser']['name'] browser_version = variables['browser']['version'] platform = "{} {}".format(variables['os']['name'], variables['os']['version']) desired_cap = { 'browserName': browser_name, 'version': browser_version, 'platform': platform, 'tags': ["login", "IO"], 'build': "1.2.3.4" } browser_instance = webdriver.Remote( command_executor="http://{}:{}@ondemand.saucelabs.com:80/wd/hub". format(variables['saucelabs']['username'], variables['saucelabs']['password']), desired_capabilities=desired_cap) cfg = BaseConfig() domains = {} if not env else DomainResolver(variables).get_domains(env) cfg.driver = browser_instance cfg.username = username cfg.password = password if os.environ.get("PYTEST_XDIST_WORKER") is not None: io_field = os.environ.get("IO_FIELD").split("/") cfg.username = io_field[0] cfg.password = io_field[1] cfg.worker = os.environ.get("PYTEST_XDIST_WORKER") if ('temp_data' in variables) is False: if len(io_field) == 3: utils.update_json( variables, ["common_data", "clients", "default", "lastname"], variables["common_data"]["clients"]["default"]["lastname"] + io_field[2]) elif re.match("automationuser(?P<user_number>\d)\w{3}\d*", cfg.username): automation_client_to_use = re.match( "automationuser(?P<user_number>\d)\w{3}\d*", cfg.username).group('user_number') utils.update_json( variables, ["common_data", "clients", "default", "lastname"], variables["common_data"]["clients"]["default"]["lastname"] + automation_client_to_use) else: raise Exception("Please provide a default client to use.") if env: cfg.domain = domains["io"] elif domain: cfg.domain = domain cfg.env = env # Obtain token through internal credentials internal_api_data = variables["environments"][env]["data"]["api_data"] cfg.internal_token_client_id = internal_api_data["client_id"] cfg.internal_token_client_secret = internal_api_data["client_secret"] cfg.internal_token_scopes = internal_api_data["scopes"] # Obtain token through app credentials (Tenant Client Credentials) api_data = variables["environments"][env]["data"]["app"] cfg.token_client_id = api_data["tenant_client_credential_client_id"] cfg.token_client_secret = api_data[ "tenant_client_credential_client_secret"] cfg.token_scopes = api_data["tenant_client_credential_scopes"] cfg.domains = domains cfg.variables = variables cfg.variables.update({"temp_data": {}}) cfg.temp_download_folder = temp_download_folder pytest.ui_config = cfg yield cfg if 'saucelabs' in browsertype: sauce_client = SauceClient(variables['saucelabs']['username'], variables['saucelabs']['password']) sauce_client.jobs.update_job(browser_instance.session_id, name='IO Login Tests(s)', passed=True)
def join_copies(): file = utils.update_json("users_likes.json") for i in range(p.KEYWORDS): filename = "users_likes" + str(i) + ".json" duplicate = utils.update_json(filename)
def main(): file = utils.update_json("users.json") for i,id in enumerate(tqdm(file.data.keys())): s = user_likes(key_number=i%4) s.all_likes(id)
import json import multiprocessing from tqdm import tqdm from multiprocessing import Pool import auth import search_users import utils #twitter.utils as utils import userLikes #twitter.user_likes as user_likes import parameters as p file = utils.update_json("users.json") def all_users(t): print(t) index, keyword = t count = 0 user_type = lambda id: file.data[id]["query"] == keyword l = list(filter(user_type, file.data.keys()))[:p.MAX_USERS_PER_TYPE] for i, id in enumerate(tqdm(l)): app_num = (index % p.NUMBER_OF_PROCESSES ) * p.NUMBER_OF_PROCESSES + i % p.NUMBER_OF_APPS_PER_PROCESS s = userLikes.user_likes(key_number=app_num, multiprocess=keyword) s.all_likes(id) count += 1 if count > p.MAX_USERS_PER_TYPE: break