def parse_args(): parser = ArgumentParser(description="Scrape data from SEDE queries") parser.add_argument("-q", "--quiet", action="store_true") parser.add_argument("--naruto", action="store_true") parser.add_argument("--bad-naruto", action="store_true") parser.add_argument("--code-only-answers", action="store_true") parser.add_argument("--forgotten-zombie-killers", action="store_true") parser.add_argument("-u", "--url") args = parser.parse_args() if args.quiet: logging.basicConfig(level=logging.WARN) else: logging.basicConfig(level=logging.INFO) for label in URLS: if getattr(args, label.replace("-", "_"), False): break else: return url = URLS[label] cols, rows = sede.fetch_table(label, url) sorted_cols = sorted(cols.items(), key=lambda x: x[1]["index"]) for row in rows: for col_item in sorted_cols: col = col_item[1] print("{}: {}".format(col["name"], row[col["index"]])) print()
def pick(self): """ Select a random post from a list of post ids extracted from the URL. Iterate over the post ids until self.accept returns truthy. :return: a list of messages to post, or else empty list if none """ table = sede.fetch_table(self.url) if table: post_ids = table.post_ids() random.shuffle(post_ids) for post_id in post_ids: post = self.accept(post_id) if post: return post return ()