forked from pythonfoo/Impossible-Programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
backend.py
52 lines (43 loc) · 1.43 KB
/
backend.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import random
import list_gen
project_filename = "Projektauswahl.txt"
language_filename = "Programmiersprachen.txt"
constraint_filename = "constraints.txt"
job_filename = "Aufgaben.txt"
def get_project():
project_list = list_gen.lines_from_file(project_filename)
project = random.choice(project_list)
return project
def get_language():
language_list = list_gen.lines_from_file(language_filename)
language = random.choice(language_list)
return language
def get_constraint():
constraint_list = list_gen.lines_from_file(constraint_filename)
constraint = random.choice(constraint_list)
return constraint
def new_job():
project = get_project()
language = get_language()
constraint = get_constraint()
job = get_job(project, language, constraint)
return job
def get_job(project, language, constraint):
project = project.strip("\n")
language = language.strip("\n")
constraint = constraint.strip("\n")
result = "Schreibe {0} in {1} {2}.".format(project, language, constraint)
return result
def save_job(job_str):
job_str += "\n\n"
with open(job_filename, "a") as file_obj:
file_obj.write(job_str)
def load_job():
job_list = list_gen.lines_from_file(job_filename)
new_job_list = []
for job in job_list:
if job != "\n":
new_job_list.append(job)
job_list = new_job_list
random_job = random.choice(job_list)
return random_job