def execute_sync(direction, option): """ run the sync according to user select. direction: up or down option: conf or plugin sync_settings: dictionary for sync_settings.json, contain gist id and auth. """ config = Config('sync_settings') sync_settings = config.readData() gist = sync_settings.get('gist', None) auth = sync_settings.get('auth', None) if direction == 'up': if not auth: click.echo( td(text= "<a> Set up Auth Token to Upload settings. </a>\nRefer to: [https://github.com/settings/tokens]" )) return data = extract_settings(option) write_gist(data, auth, gist, option) return elif direction == 'down': if not gist: click.echo( td(text= "<a> Set up gist ID to download settings. </a>\nRefer to: [https://gist.github.com/]" )) return data = extract_gist(gist, option) write_settings(data, option) return
def update_Sync_settings(gist=None, auth=None): config = Config('sync_settings') data = config.readData() if gist is not None: data.update(gist=gist.strip()) click.echo(td(text=f"Saved Gist ID: [<{gist}>].")) if auth is not None: data.update(auth=auth.strip()) click.echo(td(text=f"Saved auth: [<{auth}>].")) config.saveData(data)
import click import requests from cli.utils import ColorText,TableDisplay,Config import json APIs = Config('api') _data = APIs.readData() COL_API_KEY=_data.get("COL_API_KEY",None) MED_API_KEY=_data.get("MED_API_KEY",None) URBAN_API_KEY=_data.get("URBAN_API_KEY",None) def lookupMW(word,limit): url1=f"https://www.dictionaryapi.com/api/v3/references/collegiate/json/{word}?key={COL_API_KEY}" url2=f"https://www.dictionaryapi.com/api/v3/references/medical/json/{word}?key={MED_API_KEY}" try: if COL_API_KEY is None or (MED_API_KEY is None): raise ValueError ("Missing API key for M-W dictionary. Run def --config to setup.") r1 = requests.request("GET", url1, ).json() r2 = requests.request("GET", url2, ).json() def process(r): result = [] for k,d in enumerate(r[0:limit]): if not isinstance(d,dict): continue _def = [("<gDef {}.g> [{}]".format(k+1,d.get('fl','None')))] for i,l in enumerate(d.get('shortdef',[])): _def.append(f" [{i+1}]. {l}") result.append(_def) return result res1 = process(r1) res2 = process(r2)