Skip to content

Commit 8d46720

Browse files
committed
parser args added
1 parent c250e84 commit 8d46720

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

website/management/commands/fetch_questions.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import uuid
88

99
class Command(BaseCommand):
10+
def add_arguments(self, parser):
11+
parser.add_argument('foss', nargs='+',type=str, help='Indicates the foss list.')
1012

1113
@tx.atomic
1214
def handle(self, *args, **options):
@@ -15,13 +17,15 @@ def handle(self, *args, **options):
1517
with open(settings.MEDIA_ROOT + meta_file_name, "w+", newline='') as metafile:
1618
metawriter = csv.writer(metafile, dialect='excel', delimiter='|')
1719
metawriter.writerow(["FOSS","Tutorial","Video Minute Range","Video Second Range","Question Title","Question Body","Question_Date","Question Posted By","Answer No.","Answer Body","Answer Date", "Answer Posted By"])
18-
questions = Question.objects.filter(category="Advance-C", status=1)
19-
for q in questions:
20-
metawriter.writerow([q.category,q.tutorial,q.minute_range,q.second_range,q.title,strip_tags(q.body).strip(" "),q.date_created,q.user()])
21-
answers = Answer.objects.filter(question=q)
22-
for i, a in enumerate(answers):
23-
metawriter.writerow(["","","","","","","","",i+1, strip_tags(a.body).strip(" "),a.date_created, a.user()])
24-
metawriter.writerow([])
20+
foss = options['foss']
21+
for f in foss:
22+
questions = Question.objects.filter(category=f, status=1)
23+
for q in questions:
24+
metawriter.writerow([q.category,q.tutorial,q.minute_range,q.second_range,q.title,strip_tags(q.body).strip(" "),q.date_created,q.user()])
25+
answers = Answer.objects.filter(question=q)
26+
for i, a in enumerate(answers):
27+
metawriter.writerow(["","","","","","","","",i+1, strip_tags(a.body).strip(" "),a.date_created, a.user()])
28+
metawriter.writerow([])
2529
print("Metadata File Generated. Please find the file at location given below.")
2630
print(metafile.name)
2731

0 commit comments

Comments
 (0)