-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackend.py
More file actions
89 lines (76 loc) · 2.42 KB
/
backend.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
"""
import random
import list_gen
import os
default_filenames = [
"Projektauswahl.txt",
"Programmiersprachen.txt",
"Herausforderungen.txt",
"Aufgaben.txt",
"Bewertungen.txt"
]
cd = os.curdir
folder_content = os.listdir()
for f in default_filenames:
if f in folder_content:
pass
else:
with open(f, "w") as file_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]
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 save_rating(project, language, constraint, rating):
with open(rating_filename, "a") as file_obj:
file_obj.write("{};{};{};{}\n".format(project, language, constraint, rating))
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
def load_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)