Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def subscribe_watchlist(cb, parser, args):
try:
cb.select(Feed, args.feed_id)
except ObjectNotFoundError:
eprint("Nonexistent or private feed: {}".format(args.feed_id))
sys.exit(1)
classifier = {
"key": "feed_id",
"value": args.feed_id,
}
watchlist_dict = {
"name": args.watchlist_name,
"description": args.description,
"tags_enabled": args.tags,
"alerts_enabled": args.alerts,
"create_timestamp": args.timestamp,
"last_update_timestamp": args.last_update,
"report_ids": [],
"classifier": classifier,
def get_report(watchlist, report_id=None, report_name=None):
if report_id:
reports = [report for report in watchlist.reports if report.id == report_id]
elif report_name:
reports = [report for report in watchlist.reports if report.title == report_name]
else:
raise ValueError("expected either report_id or report_name")
if not reports:
eprint("No matching reports found.")
sys.exit(1)
if len(reports) > 1:
eprint("More than one matching report found.")
sys.exit(1)
return reports[0]
def replace_report(cb, parser, args):
feed = get_feed(cb, feed_id=args.id, feed_name=args.feedname)
imported = json.loads(sys.stdin.read())
reports = feed.reports
existing_report = next(
(report for report in reports if imported["id"] == report.id), None
)
if existing_report:
existing_report.update(**imported)
else:
eprint("No existing report to replace")
sys.exit(1)
def get_report(feed, report_id=None, report_name=None):
if report_id:
reports = [report for report in feed.reports if report.id == report_id]
if not reports:
eprint("No reports with ID '{}'".format(report_id))
sys.exit(1)
elif len(reports) > 1:
eprint("More than one report with ID '{}'".format(report_id))
sys.exit(1)
elif report_name:
reports = [report for report in feed.reports if report.title == report_name]
if not reports:
eprint("No reports named '{}'".format(report_name))
sys.exit(1)
elif len(reports) > 1:
eprint("More than one report named '{}'".format(report_name))
sys.exit(1)
else:
raise ValueError("expected either report_id or report_name")
return reports[0]
def get_report(watchlist, report_id=None, report_name=None):
if report_id:
reports = [report for report in watchlist.reports if report.id == report_id]
elif report_name:
reports = [report for report in watchlist.reports if report.title == report_name]
else:
raise ValueError("expected either report_id or report_name")
if not reports:
eprint("No matching reports found.")
sys.exit(1)
if len(reports) > 1:
eprint("More than one matching report found.")
sys.exit(1)
return reports[0]
def import_report(cb, parser, args):
feed = get_feed(cb, feed_id=args.id, feed_name=args.feedname)
imp_dict = json.loads(sys.stdin.read())
reports = feed.reports
existing_report = next(
(report for report in reports if imp_dict["id"] == report.id), None
)
if existing_report:
eprint("Report already exists; use replace-report.")
sys.exit(1)
else:
imp_report = cb.create(Report, imp_dict)
feed.append_reports([imp_report])