python: Reformat with Black, except quotes.

Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
Anders Kaseorg
2021-02-11 23:19:30 -08:00
committed by Tim Abbott
parent 5028c081cb
commit 11741543da
817 changed files with 44952 additions and 24860 deletions

View File

@@ -14,6 +14,7 @@ def load_config() -> Dict[str, Any]:
return config
def generate_topics(num_topics: int) -> List[str]:
config = load_config()["gen_fodder"]
@@ -37,6 +38,7 @@ def generate_topics(num_topics: int) -> List[str]:
return topics
def load_generators(config: Dict[str, Any]) -> Dict[str, Any]:
results = {}
@@ -60,6 +62,7 @@ def load_generators(config: Dict[str, Any]) -> Dict[str, Any]:
return results
def parse_file(config: Dict[str, Any], gens: Dict[str, Any], corpus_file: str) -> List[str]:
# First, load the entire file into a dictionary,
@@ -74,6 +77,7 @@ def parse_file(config: Dict[str, Any], gens: Dict[str, Any], corpus_file: str) -
return paragraphs
def get_flair_gen(length: int) -> List[str]:
# Grab the percentages from the config file
@@ -88,6 +92,7 @@ def get_flair_gen(length: int) -> List[str]:
random.shuffle(result)
return result
def add_flair(paragraphs: List[str], gens: Dict[str, Any]) -> List[str]:
# roll the dice and see what kind of flair we should add, if any
@@ -134,6 +139,7 @@ def add_flair(paragraphs: List[str], gens: Dict[str, Any]) -> List[str]:
return results
def add_md(mode: str, text: str) -> str:
# mode means: bold, italic, etc.
@@ -149,6 +155,7 @@ def add_md(mode: str, text: str) -> str:
return " ".join(vals).strip()
def add_emoji(text: str, emoji: str) -> str:
vals = text.split()
@@ -157,6 +164,7 @@ def add_emoji(text: str, emoji: str) -> str:
vals[start] = vals[start] + " " + emoji + " "
return " ".join(vals)
def add_link(text: str, link: str) -> str:
vals = text.split()
@@ -166,12 +174,13 @@ def add_link(text: str, link: str) -> str:
return " ".join(vals)
def remove_line_breaks(fh: Any) -> List[str]:
# We're going to remove line breaks from paragraphs
results = [] # save the dialogs as tuples with (author, dialog)
results = [] # save the dialogs as tuples with (author, dialog)
para = [] # we'll store the lines here to form a paragraph
para = [] # we'll store the lines here to form a paragraph
for line in fh:
text = line.strip()
@@ -187,19 +196,24 @@ def remove_line_breaks(fh: Any) -> List[str]:
return results
def write_file(paragraphs: List[str], filename: str) -> None:
with open(filename, "wb") as outfile:
outfile.write(orjson.dumps(paragraphs))
def create_test_data() -> None:
gens = load_generators(config) # returns a dictionary of generators
gens = load_generators(config) # returns a dictionary of generators
paragraphs = parse_file(config, gens, config["corpus"]["filename"])
write_file(paragraphs, os.path.join(get_or_create_dev_uuid_var_path('test-backend'),
"test_messages.json"))
write_file(
paragraphs,
os.path.join(get_or_create_dev_uuid_var_path('test-backend'), "test_messages.json"),
)
config = load_config()