def saveToken(self, text): token = text.replace('#', '') token = token + '×tamp=' + str(int(time.time())) f = open(TOKEN_FILE, 'w') f.write(token) f.close() WoxAPI.show_msg('凭证已保存', 'saved')
def wrap(*args, **kwargs): try: return func(*args, **kwargs) except: error = traceback.format_exc() WoxAPI.show_msg("error", error) Log.error(error)
def wrap(*args, **kwargs): try: return func(*args, **kwargs) except: error = traceback.format_exc() WoxAPI.show_msg("error", error) Log.error(error) os.system(r'explorer "{}"'.format(os.getcwd()))
def setk(self, key, value): with open(self.aliasfile, 'r+') as f: alias = load(f) alias[key] = value f.seek(0) f.truncate() dump(alias, f, indent=4) WoxAPI.show_msg('set alias', '{}={}'.format(key, value))
def delk(self, key): with open(self.aliasfile, 'r+') as f: alias = load(f) alias.pop(key) f.seek(0) f.truncate() dump(alias, f, indent=4) WoxAPI.show_msg('remove alias', '{}'.format(key))
def copy_password(self, password): """ Copies the given password to the clipboard. WARNING:Uses yet-to-be-known Win32 API and ctypes black magic to work. """ clipboard.put(password) WoxAPI.show_msg(password, 'Password has been copied to clipboard.', self.icon)
def saveSteamAppsDirectory(self, path): plugin_conf = self.plugin_conf plugin_conf['steamapps_dir'] = re.sub(r'[/\\]+', '/', path.rstrip('/\\')) + '/' self.steam_apps_dir = plugin_conf['steamapps_dir'] with codecs.open('./config.json', 'w', 'utf-8') as f: json.dump(plugin_conf, f, indent=4) WoxAPI.show_msg("Steam apps directory path has been saved", plugin_conf['steamapps_dir'])
def open_webpage(self, url, notification=True): """Trivial implementation of bookmarks in Wox Demonstrates how optional parameters in Json RPC are handled. """ if notification: WoxAPI.show_msg('Heads up', 'We opened in new window') webbrowser.open_new(url) else: webbrowser.open(url)
def __init__(self): Wox.__init__(self) watcher = clipmonitor.ClipboardWatcher(self.check_clipboard, self.append_datalist, 5.) watcher.start() while True: try: time.sleep(10) except Exception as e: watcher.stop() WoxAPI.show_msg('Error ' + str(e)) break
def mark_as_done(self, url): try: api = todoist.TodoistAPI(token=self.get_todoist_api_key()) items = api.state['items'] filtered = [i for i in items if i['id'] == int(url)] item_to_complete = filtered[0] item_to_complete.complete() api.commit() api.sync() WoxAPI.show_msg("Marked as done", "GZ!") except Exception as e: WoxAPI.show_msg("Something went wrong :( :(", f"{str(e)}")
def add_new_domain(self,domain): if not domain: WoxAPI.show_msg("Warning","You can't add empty domain") return r = re.compile(r"domains = {([\s\S]*)};") with open(self.get_pac_path(),"r+") as pac: pactxt = pac.read() existing_domains = r.search(pactxt).group(1) domains = json.loads("{" + existing_domains + "}") domains[domain] = 1 newpactxt = r.sub(r"domains = " + json.dumps(domains,indent = 4) +";",pactxt) pac.seek(0) pac.write(newpactxt) pac.truncate() WoxAPI.show_msg("Success","{} is now in PAC file".format(domain))
def update_github(): """从github上clone或pull最新的文件""" try: if not os.path.exists(cmdblog_path): os.chdir(dir) # os.mkdir(cmdblog_path) # git clone 可以生成该文件夹 os.system("git clone https://github.com/basicsp/cmdblog.git") WoxAPI.show_msg('update_github', 'git clone is over.') else: os.chdir(cmdblog_path) os.system("git pull") WoxAPI.show_msg('update_github', 'git pull is over.') except Exception as e: return str(e) else: return True
def add_new_domain(self, domain): if not domain: WoxAPI.show_msg("Warning", "You can't add empty domain") return r = re.compile(r"domains = {([\s\S]*)};") with open(self.get_pac_path(), "r+") as pac: pactxt = pac.read() existing_domains = r.search(pactxt).group(1) domains = json.loads("{" + existing_domains + "}") domains[domain] = 1 newpactxt = r.sub( r"domains = " + json.dumps(domains, indent=4) + ";", pactxt) pac.seek(0) pac.write(newpactxt) pac.truncate() WoxAPI.show_msg("Success", "{} is now in PAC file".format(domain))
def learn(self, wordId): if False == self.hasToken(): self.authorize() return token = self.getToken() if not token: WoxAPI.show_msg('token失效', 'token expiresed') return payload = {'id': wordId} r = requests.post(LEARNING_API + token, data=payload) if r.json()['status_code'] == 0: WoxAPI.show_msg('已添加', 'already added') else: WoxAPI.show_msg('请检查token', 'pls check token file')
def reloadLibrary(self, steam_apps_dir): self.game_list = Steamlauncher.save_steam_library(steam_apps_dir) WoxAPI.show_msg("Steam library has been updated", steam_apps_dir)
def Alert(cls, title, content): # can not call frequently, will crash from wox import WoxAPI WoxAPI.show_msg(title, content, r"./Images/pic.png")
def copy_to_clip(self, text): """method""" clipboard.copy(text) WoxAPI.show_msg(text, text + "copy is over.")
def copy(self, data): clipboard.put(data) WoxAPI.show_msg("Value has been copied to clipboard.", '', self.icon)
def openFile(self, filePath): if not os.path.exists(filePath): WoxAPI.show_msg(title="The file is no longer exist", sub_title=filePath) return os.startfile(filePath)
def clean_cache(self, contest): shutil.rmtree(self.img_path) WoxAPI.show_msg("Success", " clean up cache file done", self.plugin_ico)
def pinned(self): Setting.getInstance().setPinned() WoxAPI.show_msg("Searching only pinned file is set to " + str(Setting.getInstance().getPinned()), sub_title="") return