def main(): """Given a dashboard title, search all dashboards to retrieve its id and use it to render the dashboard's pdf. Examples of how to use this: $ python download_dashboard_pdf.py "A Test Dashboard" $ python download_dashboard_pdf.py "A Test Dashboard" '{"filter1": "value1, value2", "filter2": "value3"}' $ python download_dashboard_pdf.py "A Test Dashboard" {} "single_column" """ dashboard_title = sys.argv[1] if len(sys.argv) > 1 else "" filters = json.loads(sys.argv[2]) if len(sys.argv) > 2 else None pdf_style = sys.argv[3] if len(sys.argv) > 3 else "tiled" pdf_width = int(sys.argv[4]) if len(sys.argv) > 4 else 545 pdf_height = int(sys.argv[5]) if len(sys.argv) > 5 else 842 if not dashboard_title: raise exceptions.ArgumentError( textwrap.dedent( """ Please provide: <dashboard_title> [<dashboard_filters>] [<dashboard_style>] [<pdf_width>] [<pdf_height>] dashboard_style defaults to "tiled" pdf_width defaults to 545 pdf_height defaults to 842""" ) ) dashboard = cast(models.Dashboard, get_dashboard(dashboard_title)) download_dashboard(dashboard, pdf_style, pdf_width, pdf_height, filters)
def main() -> None: """Given a look id, obtain the query behind it and run it with the desired filter values. https://docs.looker.com/reference/api-and-integration/api-reference/v3.1/query#implementation_notes_9 # noqa: B950 shows an example of how filters are defined in the posted body. To set the same filter in this example, the script needs to be run as follows: $ python run_look_with_filters.py 5 category.name socks """ look_id = sys.argv[1] if len(sys.argv) > 1 else "" filter_args = iter(sys.argv[2:]) filters: Dict[str, str] = {} if not (look_id and len(sys.argv[2:]) > 0 and len(sys.argv[2:]) % 2 == 0): raise exceptions.ArgumentError( "Please provide: <lookId> <filter_1> <filter_value_1> " "<filter_2> <filter_value_2> ..." ) for filter_name in filter_args: filters[filter_name] = next(filter_args) query = get_look_query(int(look_id)) results = run_query_with_filter(query, filters) print(f"Query results with filters={filters}:\n{results}", end="\n\n")
def main(): """Given a connection, obtain its supported tests and run them. Example: $ python test_connection.py thelook """ connection_name = sys.argv[1] if len(sys.argv) > 1 else "" if not connection_name: raise exceptions.ArgumentError("Please provide a connection name") elif connection_name in ["looker", "looker__internal__analytics"]: raise exceptions.ArgumentError( f"Connection '{connection_name}' is internal and cannot be tested." ) connection = get_connections(connection_name) results = test_connection(connection) output_results(cast(str, connection.name), results)
def main(): """Given a dashboard title, get the ids of all dashboards with matching titles and move them to trash. $ python soft_delete_dashboard.py "An Unused Dashboard" """ dashboard_title = sys.argv[1] if len(sys.argv) > 1 else "" if not dashboard_title: raise exceptions.ArgumentError("Please provide: <dashboardTitle>") dashboards = get_dashboards(dashboard_title) delete_dashboards(dashboards)
def get_channel_data(api_key: str, user_name: str = None, channel_id: str = None) -> Dict: """ Get the ID for the uploads playlist for a given channel. Either the legacy user name or channel id must be supplied. If both are supplied, the channel_id takes precedence. Args: api_key (str): YouTube API key user_name (str, optional): channel user name channel_id (str, optional): channel id Returns: dict: Chanel metadata Raises: ArgumentError: Required arguments not provided HTTPError: YouTube API get request returned an http error """ ret = dict() base_url = 'https://www.googleapis.com/youtube/v3/channels' #init params params = dict() params['key'] = api_key params['part'] = 'snippet,contentDetails' if channel_id is not None: params['id'] = channel_id elif user_name is not None: params['forUsername'] = user_name else: raise exceptions.ArgumentError('user_name or channel_id required!') #make get request and return data response = requests.get(base_url, params) _check_response_status(response.status_code) dat = response.json()['items'][0] ret['uploads_playlistId'] = dat['contentDetails']['relatedPlaylists'][ 'uploads'] for d in CHANEL_INFO_KEYS: if d in dat['snippet'].keys(): ret[d] = dat['snippet'][d] else: ret[d] = 'NA' return ret
def main(): """Given a look title, find the corresponding look id and use it to render its image. $ python download_look.py "A good look" 1024 768 png """ look_title = sys.argv[1] if len(sys.argv) > 1 else "" image_width = int(sys.argv[2]) if len(sys.argv) > 2 else 545 image_height = int(sys.argv[3]) if len(sys.argv) > 3 else 842 image_format = sys.argv[4] if len(sys.argv) > 4 else "png" if not look_title: raise exceptions.ArgumentError( textwrap.dedent(""" Please provide: <lookTitle> [<img_width>] [<img_height>] [<img_format>] img_width defaults to 545 img_height defaults to 842 img_format defaults to 'png'""")) look = get_look(look_title) download_look(look, image_format, image_width, image_height)
def handle(): """ parses the system argluments parses the given system arguments and proceeds with the program depending on what was given OBS! --log can always be passed but --view and --schedule can not be passed at the same time :return: None """ parser = argparse.ArgumentParser( description="Logs and views a systems cpu temperature.") parser.add_argument("--log", action="store_true") parser.add_argument("--schedule", action="store_true") parser.add_argument("--job_type", help="valid values 'cron', 'interval'", type=str) parser.add_argument("--year", "--years", type=int) parser.add_argument("--month", "--months", type=int) parser.add_argument("--week", "--weeks", type=int) parser.add_argument("--day", "--days", type=int) parser.add_argument("--hour", "--hours", type=int) parser.add_argument("--minute", "--minutes", type=int) parser.add_argument("--second", "--seconds", type=int) parser.add_argument( "--misfire", type=int, help="If system is unavaileble to execute at desired run time " "how long in seconds is it allow to execute past set time.") parser.add_argument("--view", action="store_true") parser.add_argument("--host", type=str, help="The hostname of the client to draw data about.") parser.add_argument("--measurement", type=str, help="temperature or cpu_usage") parser.add_argument("--this_session", action="store_true") parser.add_argument("--start_time", type=str, help="Date to start draw data from.") parser.add_argument("--end_time", type=str, help="Date to end draw data from.") parser.add_argument("--core", action="store_true") args = parser.parse_args() if args.log or args.schedule or args.view: if args.log: store_temp(need_sleep=True) if args.schedule: if args.view: raise exceptions.ArgumentError( "Can not handle both --view and --schedule at the same time." ) schedule(args) elif args.view: if args.schedule: raise exceptions.ArgumentError( "Can not handle both --view and --schedule at the same time." ) view(args) else: raise exceptions.NothingToDo( "Need to add '--log', '--view' or '--schedule' to args")