@@ -628,6 +628,44 @@ def update_question_examples(j1):
628628 except Exception as e :
629629 print (f" ❌ Error updating variables: { e } \n " )
630630
631+ def delete_question_examples (j1 ):
632+ """Demonstrate deleting existing questions."""
633+
634+ print ("=== Delete Question Examples ===\n " )
635+
636+ # Get question ID from user input
637+ print ("1. Enter the question ID to delete:" )
638+ print (" (You can find question IDs by running the list_questions_example first)" )
639+ print ()
640+
641+ # For demonstration purposes, use a placeholder ID
642+ # In a real application, you would use: question_id = input("Enter question ID: ")
643+ question_id = "your-question-id-here" # Replace with actual question ID
644+
645+ if question_id == "your-question-id-here" :
646+ print (" ⚠️ Please replace 'your-question-id-here' with an actual question ID" )
647+ print (" Example: question_id = 'fcc0507d-0473-43a2-b083-9d5571b92ae7'" )
648+ print ()
649+ return
650+
651+ print (f" Question ID to delete: { question_id } " )
652+ print ()
653+
654+ # Delete the question
655+ print ("2. Deleting the question:" )
656+ try :
657+ deleted_question = j1 .delete_question (question_id = question_id )
658+
659+ print (f" ✅ Successfully deleted question!" )
660+ print (f" Deleted question title: { deleted_question ['title' ]} " )
661+ print (f" Deleted question ID: { deleted_question ['id' ]} " )
662+ print (f" Number of queries in deleted question: { len (deleted_question ['queries' ])} " )
663+ print ()
664+
665+ except Exception as e :
666+ print (f" ❌ Error deleting question: { e } " )
667+ print ()
668+
631669def question_use_cases (j1 ):
632670 """Demonstrate real-world use cases for questions."""
633671
@@ -719,6 +757,40 @@ def question_use_cases(j1):
719757 }
720758 )
721759 """ )
760+
761+ # Use Case 5: Question Deletion and Cleanup
762+ print ("\n Use Case 5: Question Deletion and Cleanup" )
763+ print ("-" * 50 )
764+ print ("Delete questions that are no longer needed:" )
765+ print ("""
766+ # Delete a single question
767+ deleted_question = j1.delete_question(
768+ question_id="question-id-to-delete"
769+ )
770+ print(f"Deleted: {deleted_question['title']}")
771+
772+ # Batch delete deprecated questions
773+ deprecated_questions = j1.list_questions(tags=["deprecated"])
774+ for question in deprecated_questions:
775+ try:
776+ deleted = j1.delete_question(question_id=question['id'])
777+ print(f"Deleted deprecated question: {deleted['title']}")
778+ except Exception as e:
779+ print(f"Failed to delete {question['title']}: {e}")
780+
781+ # Safe deletion with backup
782+ question_to_delete = j1.get_question_details(question_id="question-id")
783+ backup_question = j1.create_question(
784+ title=f"{question_to_delete['title']} - BACKUP",
785+ queries=question_to_delete['queries'],
786+ description=f"Backup before deletion: {question_to_delete.get('description', '')}",
787+ tags=question_to_delete.get('tags', []) + ["backup"]
788+ )
789+
790+ # Now delete the original
791+ j1.delete_question(question_id="question-id")
792+ print("Original question deleted, backup preserved")
793+ """ )
722794
723795def main ():
724796 """Run all question management examples."""
@@ -750,6 +822,9 @@ def main():
750822 update_question_examples (j1 )
751823 time .sleep (1 )
752824
825+ delete_question_examples (j1 )
826+ time .sleep (1 )
827+
753828 question_use_cases (j1 )
754829
755830 print ("\n " + "=" * 50 )
0 commit comments