コード例 #1
0
 def create_question(self):
     title = raw_input("Set title: ")
     if title == None:
         print("No question made")
         return None
     elif title in self.titles:
         print("A question with the same title already exists")
         return None
     question_string = raw_input("Type question: ")
     question = Questionnaire(title, question_string)
     add_answer_bool = True
     while add_answer_bool:
         print("Type an answer or type quit")
         answer = raw_input("Answer: ")
         if answer == "quit" or answer == "q":
             if question.count_answers():
                 self.add_question(question)
                 print("Question " + title + " successfully created")
             else:
                 print("Error: Question " + title +
                       " has no answers and was deleted")
             add_answer_bool = False
         elif answer:
             points = raw_input("Points: ")
             try:
                 p = int(points)
                 question.add_answer(answer, p)
             except:
                 print("Error: Point value must be numeric")
コード例 #2
0
    def send_question(self, title):
        question = self.get_question(title)
        if question:
            self.pub(question.serialize(), "question")

    def ask_for_results(self):
        self.pub("results", "results")


publish_key = 'pub-c-c96b6401-1254-4fe2-9d2a-0c193f5818ad'
subscribe_key = 'sub-c-24bd254c-df80-11e6-8652-02ee2ddab7fe'
name = "alex"
admin = Admin(publish_key, subscribe_key, name, "awesome")
q1 = Questionnaire("Q1", "What is 1+1?")
q1.add_answer("2", 1)
q1.add_answer("1", 0)
q1.add_answer("3", 0)
q1.add_answer("4", 0)
admin.add_question(q1)
# admin.pub(q1.serialize(), "question")
print("Type help for commands. Press CTRL+C to exit.")
while True:
    try:
        input = raw_input()
        if input:
            admin.commands(input)
    except KeyboardInterrupt:
        print("Exiting")
        admin.end_question()
        admin.unsub()