Skip to content
Snippets Groups Projects
Commit d3743419 authored by Bensong Liu's avatar Bensong Liu
Browse files

make the noob code better

parent d916148e
No related branches found
No related tags found
No related merge requests found
...@@ -12,12 +12,10 @@ def loadJson(fileName): ...@@ -12,12 +12,10 @@ def loadJson(fileName):
return json.loads(file.read()) return json.loads(file.read())
data = loadJson("data.json") data = loadJson("data.json")
motto_data = data["famous"] # a 代表prefix_data,b代表postfix_data famous_data = list(data['famous']) # a 代表prefix_data,b代表postfix_data
prefix_data = data["before"] # 在motto_data前面弄点nonsense_data prefix_data = list(data['before']) # 在famous_data前面弄点nonsense_data
postfix_data = data['after'] # 在motto_data后面弄点nonsense_data postfix_data = list(data['after' ]) # 在famous_data后面弄点nonsense_data
nonsense_data = data['bosh'] # 代表文章主要nonsense_data来源 nonsense_data = list(data['bosh' ]) # 代表文章主要nonsense_data来源
xx = "学生会退会"
repeat_factor = 2 repeat_factor = 2
...@@ -30,14 +28,14 @@ def randomized_yield(iterable): ...@@ -30,14 +28,14 @@ def randomized_yield(iterable):
yield ele yield ele
nonsense_generator = randomized_yield(nonsense_data) nonsense_generator = randomized_yield(nonsense_data)
motto_generator = randomized_yield(motto_data) famous_generator = randomized_yield(famous_data)
def new_motto(): def new_famous():
global motto_generator global famous_generator
xx = next(motto_generator) famous = next(famous_generator)
xx = xx.replace("a", random.choice(prefix_data) ) famous = famous.replace("a", random.choice(prefix_data) )
xx = xx.replace("b", random.choice(postfix_data) ) famous = famous.replace("b", random.choice(postfix_data) )
return xx return famous
def new_paragraph(): def new_paragraph():
xx = ". " xx = ". "
...@@ -46,16 +44,15 @@ def new_paragraph(): ...@@ -46,16 +44,15 @@ def new_paragraph():
return xx return xx
if __name__ == "__main__": if __name__ == "__main__":
xx = input("请输入文章主题:") topic = input("请输入文章主题:")
for x in xx: result = str()
tmp = str() while ( len(result) < 6000 ) :
while ( len(tmp) < 6000 ) : randsrc = random.randint(0,100)
randsrc = random.randint(0,100) if randsrc < 5:
if randsrc < 5: result += new_paragraph()
tmp += new_paragraph() elif randsrc < 20 :
elif randsrc < 20 : result += new_famous()
tmp += new_motto() else:
else: result += next(nonsense_generator)
tmp += next(nonsense_generator) result = result.replace("x",topic)
tmp = tmp.replace("x",xx) print(result)
print(tmp)
...@@ -164,4 +164,4 @@ ...@@ -164,4 +164,4 @@
"曾经提到过", "曾经提到过",
"说过一句富有哲理的话" "说过一句富有哲理的话"
] ]
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment