-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctionalties.py
More file actions
77 lines (64 loc) · 2.3 KB
/
functionalties.py
File metadata and controls
77 lines (64 loc) · 2.3 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
#!/usr/bin/python3
""""Module that contain all functionalies of the all"""
import random
def generate_courses(courses_list):
"""generate random course"""
if not courses_list:
return []
random_courses = []
count = 0
while len(random_courses) < 10:
course = random.choice(courses_list)
if course not in random_courses:
random_courses.append(course)
count += 1
return random_courses
#Not working, you can debug. I put not.
def search_courses(courses_list, search_str):
"""Search for courses related to the search string and return a list of searches."""
matched_courses = []
for course in courses_list:
course_title = course.title.lower() # Accessing the 'title' attribute of the course
if search_str.lower() in course_title:
matched_courses.append(course)
# Convert to JSON format.
courses_data = [
{'id': course.id, 'title': course.title, 'url': course.url, 'instructor': course.instructor}
for course in matched_courses
]
return courses_data
#Working search function
def search_courses_not(courses_list, search_str):
"""search for course related to search string and
return list of searches
"""
matched_courses = []
for course in courses_list:
course_title = course[1].lower()
if search_str.lower() in course_title:
matched_courses.append(course)
#Convert to json.
courses_data = [
{'id': course.id, 'title': course.title, 'url': course.url, 'instructor': course.instructor}
for course in matched_courses
]
return courses_data
def save_course(course):
"""add a course to list of save courses"""
save_courses = []
save_courses.append(course)
return save_courses
def filter_search(courses_list, course_category=None, src=None, plan=None):
"""filter the course search
return list of courses under args
"""
courses = []
if course_category is not None:
for course in course_category:
if course['source'] == src and course['plan'] == plan:
courses.append(course)
else:
for course in courses_list:
if course['source'] == src and course['plan'] == plan:
courses.append(course)
return course