diff --git a/flashcards/apps/api/v1/urls.py b/flashcards/apps/api/v1/urls.py index 8f654b2..f19e92f 100644 --- a/flashcards/apps/api/v1/urls.py +++ b/flashcards/apps/api/v1/urls.py @@ -1,4 +1,9 @@ """ API v1 URLs. """ +from django.urls import path + +from . import views app_name = 'v1' -urlpatterns = [] +urlpatterns = [ + path('cards//', views.cards, name='cards'), +] diff --git a/flashcards/apps/api/v1/views.py b/flashcards/apps/api/v1/views.py index 60f00ef..17de3da 100644 --- a/flashcards/apps/api/v1/views.py +++ b/flashcards/apps/api/v1/views.py @@ -1 +1,12 @@ -# Create your views here. +from django.views.decorators.http import require_http_methods +from rest_framework.decorators import api_view, authentication_classes, permission_classes +from rest_framework.response import Response + +from flashcards.apps.cards.anki import anki_from_block_id + + +@api_view(['GET']) # TODO get is completely wrong here but convenient for testing +@require_http_methods(['GET']) +def cards(request, course_id, block_id): + cards = anki_from_block_id(course_id, block_id) + return Response("cards") diff --git a/flashcards/apps/cards/anki.py b/flashcards/apps/cards/anki.py index e88316e..6bc28b6 100644 --- a/flashcards/apps/cards/anki.py +++ b/flashcards/apps/cards/anki.py @@ -41,15 +41,8 @@ def create_anki_cards(openai_data): genanki.Package(my_deck).write_to_file('demo_output.apkg') -def main(): - """ - Master function that gets a response from openai and passes the result to Anki - """ - result = cards_from_block_id('course-v1:edX+DemoX+Demo_Course', - 'block-v1:edX+DemoX+Demo_Course+type@vertical+block@867dddb6f55d410caaa9c1eb9c6743ec') - # TODO: Insert some kind of data validation here to make sure openai sent back something nice - result = result.replace('\t', '') +def anki_from_block_id(course_id, block_id): + csv_maybe = cards_from_block_id(course_id, block_id) + result = csv_maybe.replace('\t', '') create_anki_cards(result) - -main()