Skip to content

Commit

Permalink
Merge pull request #6 from edx/ashultz0/endpoint
Browse files Browse the repository at this point in the history
feat: endpoint
  • Loading branch information
ashultz0 authored Oct 25, 2023
2 parents 18e6a43 + 2b436d2 commit 4a09142
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
7 changes: 6 additions & 1 deletion flashcards/apps/api/v1/urls.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
""" API v1 URLs. """
from django.urls import path

from . import views

app_name = 'v1'
urlpatterns = []
urlpatterns = [
path('cards/<str:course_id>/<str:block_id>', views.cards, name='cards'),
]
13 changes: 12 additions & 1 deletion flashcards/apps/api/v1/views.py
Original file line number Diff line number Diff line change
@@ -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")
13 changes: 3 additions & 10 deletions flashcards/apps/cards/anki.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 4a09142

Please sign in to comment.