Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

Commit 5e42b83

Browse files
the Question model adding instances automated removed repetivite tasks
1 parent abbfdc6 commit 5e42b83

File tree

6 files changed

+150
-6
lines changed

6 files changed

+150
-6
lines changed
24 Bytes
Binary file not shown.

questions.json

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
[
2+
{
3+
"subject": "Sports",
4+
"question": "Which country won the FIFA World Cup in 2018?",
5+
"choices": [
6+
"Brazil",
7+
"Germany",
8+
"France",
9+
"Spain"
10+
],
11+
"correct_answer": "France"
12+
},
13+
{
14+
"subject": "Sports",
15+
"question": "Which sport is Usain Bolt famous for?",
16+
"choices": [
17+
"Basketball",
18+
"Tennis",
19+
"Swimming",
20+
"Sprinting"
21+
],
22+
"correct_answer": "Sprinting"
23+
},
24+
{
25+
"subject": "Sports",
26+
"question": "Which athlete has the most Olympic gold medals?",
27+
"choices": [
28+
"Michael Phelps",
29+
"Usain Bolt",
30+
"Serena Williams",
31+
"Roger Federer"
32+
],
33+
"correct_answer": "Michael Phelps"
34+
},
35+
{
36+
"subject": "Sports",
37+
"question": "Which team has won the most Super Bowl titles?",
38+
"choices": [
39+
"Pittsburgh Steelers",
40+
"New England Patriots",
41+
"Dallas Cowboys",
42+
"San Francisco 49ers"
43+
],
44+
"correct_answer": "Pittsburgh Steelers"
45+
},
46+
{
47+
"subject": "Sports",
48+
"question": "Who is considered the greatest basketball player of all time?",
49+
"choices": [
50+
"Michael Jordan",
51+
"LeBron James",
52+
"Kobe Bryant",
53+
"Magic Johnson"
54+
],
55+
"correct_answer": "Michael Jordan"
56+
},
57+
{
58+
"subject": "Sports",
59+
"question": "Which country has won the most Olympic gold medals in athletics?",
60+
"choices": [
61+
"United States",
62+
"Jamaica",
63+
"China",
64+
"Great Britain"
65+
],
66+
"correct_answer": "United States"
67+
},
68+
{
69+
"subject": "Sports",
70+
"question": "Which tennis player has the most Grand Slam singles titles?",
71+
"choices": [
72+
"Rafael Nadal",
73+
"Roger Federer",
74+
"Novak Djokovic",
75+
"Serena Williams"
76+
],
77+
"correct_answer": "Roger Federer"
78+
},
79+
{
80+
"subject": "Sports",
81+
"question": "Which team has won the most NBA championships?",
82+
"choices": [
83+
"Los Angeles Lakers",
84+
"Boston Celtics",
85+
"Chicago Bulls",
86+
"Golden State Warriors"
87+
],
88+
"correct_answer": "Boston Celtics"
89+
},
90+
{
91+
"subject": "Sports",
92+
"question": "Which country won the UEFA Euro 2020 tournament?",
93+
"choices": [
94+
"England",
95+
"Italy",
96+
"Germany",
97+
"France"
98+
],
99+
"correct_answer": "Italy"
100+
},
101+
{
102+
"subject": "Sports",
103+
"question": "Which golfer has the most major championships?",
104+
"choices": [
105+
"Tiger Woods",
106+
"Jack Nicklaus",
107+
"Arnold Palmer",
108+
"Phil Mickelson"
109+
],
110+
"correct_answer": "Jack Nicklaus"
111+
}
112+
]
70 Bytes
Binary file not shown.
651 Bytes
Binary file not shown.

rewards/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@
1818
path('quiz', views.QuizInQuestions.as_view({'post':'post'})),
1919
path('quizApi', views.QuizApi.as_view({'post':'post'})),
2020
path('addQuizApi', views.AddQuizInApi.as_view()),
21-
path('quizTurns', views.QuizInTurns.as_view())
21+
path('quizTurns', views.QuizInTurns.as_view()),
22+
path("automatequiz", views.load_questions_from_json_view, name="nothing")
2223
]

rewards/views.py

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from django.http import JsonResponse
1+
import json
2+
from django.http import HttpResponse, JsonResponse
23
from rest_framework.views import APIView, status
34
from rest_framework.response import Response
45
from rest_framework.authentication import TokenAuthentication
@@ -136,7 +137,7 @@ def get(self, request, *args, **kwargs):
136137
last_spin_time = userWheelObject.last_played_at
137138
current_time = django_timezone.now()
138139
time_since_last_spin = current_time - last_spin_time
139-
if time_since_last_spin >= timedelta(hours=24):
140+
if time_since_last_spin >= timedelta(hours=6):
140141
userWheelObject.spin_available = 1
141142
userWheelObject.save()
142143
except SpinWheel.DoesNotExist:
@@ -180,7 +181,7 @@ def get(self, request, *args, **kwargs):
180181
last_played_time = userTTCObject.last_played_at
181182
current_time = django_timezone.now()
182183
time_since_last_played = current_time - last_played_time
183-
if time_since_last_played >= timedelta(hours=24):
184+
if time_since_last_played >= timedelta(hours=6):
184185
userTTCObject.turn_available = 1
185186
userTTCObject.save()
186187
return Response({"message": str(userTTCObject.turn_available)}, status=status.HTTP_200_OK)
@@ -257,7 +258,7 @@ def get(self, request, *args, **kwargs):
257258
last_played_time = userMonsterHunterObject.last_played_at
258259
current_time = django_timezone.now()
259260
time_since_last_played = current_time - last_played_time
260-
if time_since_last_played >= timedelta(hours=24):
261+
if time_since_last_played >= timedelta(hours=6):
261262
userMonsterHunterObject.turn_available = 1
262263
userMonsterHunterObject.save()
263264
return Response({"message": str(userMonsterHunterObject.turn_available)}, status=status.HTTP_200_OK)
@@ -392,9 +393,39 @@ def get(self, request, *args, **kwargs):
392393
last_played_time = userQuizInObj.last_played_at
393394
current_time = django_timezone.now()
394395
time_since_last_played = current_time - last_played_time
395-
if time_since_last_played >= timedelta(hours=24):
396+
if time_since_last_played >= timedelta(hours=6):
396397
userQuizInObj.turn_available = 1
397398
userQuizInObj.save()
398399
return Response({"message": str(userQuizInObj.turn_available)}, status=status.HTTP_200_OK)
399400
except Exception as e:
400401
return Response({"message": "Some Error Occured"}, status=status.HTTP_400_BAD_REQUEST)
402+
403+
404+
405+
#Function realted to automating the quiz section
406+
def load_questions_from_json_view(request):
407+
408+
json_file = 'questions.json' # Specify the path to your JSON file
409+
410+
with open(json_file, 'r') as file:
411+
data = json.load(file)
412+
413+
for item in data:
414+
subject_name = item['subject']
415+
subject, _ = Subject.objects.get_or_create(subject=subject_name)
416+
417+
question = Questions.objects.create(
418+
subject=subject,
419+
question=item['question'],
420+
choice1=item['choices'][0],
421+
choice2=item['choices'][1],
422+
choice3=item['choices'][2],
423+
choice4=item['choices'][3],
424+
answer=item['correct_answer']
425+
)
426+
print("Done")
427+
428+
return HttpResponse("All Questions Added")
429+
430+
431+

0 commit comments

Comments
 (0)