Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackend.py
More file actions
Latest commit
89 lines (76 loc) · 2.42 KB
/
Copy pathbackend.py
File metadata and controls
89 lines (76 loc) · 2.42 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python3
"""
@author: dodo
"""
importrandom
importlist_gen
importos
default_filenames= [
"Projektauswahl.txt",
"Programmiersprachen.txt",
"Herausforderungen.txt",
"Aufgaben.txt",
"Bewertungen.txt"
]
cd=os.curdir
folder_content=os.listdir()
forfindefault_filenames:
iffinfolder_content:
pass
else:
withopen(f, "w") asfile_obj:
file_obj.write("")
project_filename=default_filenames[0]
language_filename=default_filenames[1]
constraint_filename=default_filenames[2]
job_filename=default_filenames[3]
rating_filename=default_filenames[4]
defget_project():
project_list=list_gen.lines_from_file(project_filename)
project=random.choice(project_list)
returnproject
defget_language():
language_list=list_gen.lines_from_file(language_filename)
language=random.choice(language_list)
returnlanguage
defget_constraint():
constraint_list=list_gen.lines_from_file(constraint_filename)
constraint=random.choice(constraint_list)
returnconstraint
defnew_job():
project=get_project()
language=get_language()
constraint=get_constraint()
job=get_job(project, language, constraint)
returnjob
defget_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)
returnresult
defsave_job(job_str):
job_str+="\n\n"
withopen(job_filename, "a") asfile_obj:
file_obj.write(job_str)
defsave_rating(project, language, constraint, rating):
withopen(rating_filename, "a") asfile_obj:
file_obj.write("{};{};{};{}\n".format(project, language, constraint, rating))
defload_job():
job_list=list_gen.lines_from_file(job_filename)
new_job_list= []
forjobinjob_list:
ifjob!="\n":
new_job_list.append(job)
job_list=new_job_list
random_job=random.choice(job_list)
returnrandom_job
defload_rating():
job_list=list_gen.lines_from_file(rating_filename)
current_job=random.choice(job_list)
current_job=current_job.split(";")
current_project=current_job[0]
current_language=current_job[1]
current_constraint=current_job[2]
current_rating=current_job[3]
return (current_project, current_language, current_constraint, current_rating)