def loadFrogs(self): # from loom import Spool try: hashedFrogs = jfileutil.load("hashedFrogs") except: hashedFrogs = dict() logger.error("Couldn't load frogs?", exc_info=True) # new_frog_urls = get_new_frog_urls(old_frog_urls=hashedFrogs.values()) # with Spool(4) as hashSpool: # def job(url): # try: # phash = url_to_hash(url) # if phash not in hashedFrogs.keys(): # hashedFrogs[phash] = url # except Exception: # traceback.print_exc(limit=0) # return # for url in new_frog_urls: # hashSpool.enqueue(target=job, args=(url,)) # jfileutil.save(hashedFrogs, "hashedFrogs") self.frog_urls = list(hashedFrogs.values())
async def addfrog(cog, ctx, url): await ctx.message.add_reaction("🔄") from snip import jfileutil hashedFrogs = jfileutil.load("hashedFrogs", default=dict()) phash = url_to_hash(url) if phash not in hashedFrogs.keys(): hashedFrogs[phash] = url jfileutil.save(hashedFrogs, "hashedFrogs") await ctx.message.remove_reaction("🔄", ctx.me) await ctx.message.add_reaction("👍")
def start(self): logger.info('Creating update loops') tumblr_polls = jfileutil.load("polls") for t in tumblr_polls: logger.info('Creating update loop for ' + t['blogname']) self.client.loop.create_task( self.background_check_feed( self.client, t['blogname'], self.client.get_channel(t['bigchannel']), self.client.get_channel(t['minichannel']), t['mindelay']))
def login(self): self.session = requests.Session() self.cookies = jfileutil.load("cookies", default=dict()) if self.cookiesAreBad(): print("Please log in.") self.cookies = self.bakeCookies() assert not self.cookiesAreBad() jfileutil.save(self.cookies, "cookies") print("Login successful. ")
async def removefrog(cog, ctx, url): await ctx.message.add_reaction("🔄") from snip import jfileutil hashedFrogs = jfileutil.load("hashedFrogs", default=dict()) for key in hashedFrogs.keys(): if hashedFrogs.get(key) == url: hashedFrogs.pop(key) jfileutil.save(hashedFrogs, "hashedFrogs") await ctx.message.remove_reaction("🔄", ctx.me) await ctx.message.add_reaction("👍") return await ctx.message.remove_reaction("🔄", ctx.me) await ctx.message.add_reaction("❌")
def getSetting(guild_id, key): try: settings = jfileutil.load(settings_filename(guild_id)) except FileNotFoundError: logger.info("Missing settings file for server", guild_id) settings = settings_template jfileutil.save(settings, settings_filename(guild_id)) try: return settings.get(key) except KeyError: if settings_template.get(key): settings[key] = settings_template.get(key) jfileutil.save(settings, settings_filename(guild_id)) else: logger.info("No such settings key '{}'".format(key)) raise
def reload(self): """Load json from file """ self.dictionary = ju.load(self.identifier)
print("#", end="") print("#") return messages if __name__ == "__main__": import argparse args = argparse.ArgumentParser() args.add_argument("--all", action="store_true") args.add_argument("--group_ids", nargs="+", default=[]) args = args.parse_args() try: access_token = jfileutil.load("token") groupme = GroupMe(access_token) except: sessiondata = selenium_login.login( "https://groupme.com/signin", lambda browser: browser.current_url == "https://web.groupme.com/chats") access_token = sessiondata.get("cookies").get("token") jfileutil.save(access_token, "token") groupme = GroupMe(access_token) group_ids_to_save = args.group_ids if args.all: all_groups = groupme.getGenericApi('groups') group_ids_to_save += [g['group_id'] for g in all_groups] for group_id in group_ids_to_save: