parsing telegram MessageMediaPoll and print it as readable text
Question:
Good day every one,
I’m trying to parse telegram poll data, I have the following:
{'_': 'MessageMediaPoll', 'poll': {'_': 'Poll', 'id': 578954245254551900254, 'question': 'Have you seen it ?! ', 'answers': [{'_': 'PollAnswer', 'text': 'Lost', 'option': [48]}, {'_': 'PollAnswer', 'text': 'Am lose', 'option': [49]}, {'_': 'PollAnswer', 'text': 'Have lost', 'option': [50]}, {'_': 'PollAnswer', 'text': 'Am losing', 'option': [51]}], 'closed': False, 'public_voters': False, 'multiple_choice': False, 'quiz': True, 'close_period': None, 'close_date': None}, 'results': {'_': 'PollResults', 'min': False, 'results': [{'_': 'PollAnswerVoters', 'option': [48], 'voters': 2066, 'chosen': False, 'correct': True}, {'_': 'PollAnswerVoters', 'option': [49], 'voters': 471, 'chosen': False, 'correct': False}, {'_': 'PollAnswerVoters', 'option': [50], 'voters': 704, 'chosen': False, 'correct': False}, {'_': 'PollAnswerVoters', 'option': [51], 'voters': 279, 'chosen': True, 'correct': False}], 'total_voters': 3520, 'recent_voters': [], 'solution': None, 'solution_entities': []}}
and I want to print it like this:
Q: Have you seen it ?!
A: Lost|Correct
A: Am lose|Incorrect
A: Have lost|Incorrect
A: Am losing|Incorrect
How I can achieve that in Python? and what is the type of the data? json?
Answers:
data = {'_': 'MessageMediaPoll', 'poll': {'_': 'Poll', 'id': 57894245245450254, 'question': 'Have you seen it ?! ', 'answers': [{'_': 'PollAnswer', 'text': 'Lost', 'option': [48]}, {'_': 'PollAnswer', 'text': 'Am lose', 'option': [49]}, {'_': 'PollAnswer', 'text': 'Have lost', 'option': [50]}, {'_': 'PollAnswer', 'text': 'Am losing', 'option': [51]}], 'closed': False, 'public_voters': False, 'multiple_choice': False, 'quiz': True, 'close_period': None, 'close_date': None}, 'results': {'_': 'PollResults', 'min': False, 'results': [{'_': 'PollAnswerVoters', 'option': [48], 'voters': 2066, 'chosen': False, 'correct': True}, {'_': 'PollAnswerVoters', 'option': [49], 'voters': 471, 'chosen': False, 'correct': False}, {'_': 'PollAnswerVoters', 'option': [50], 'voters': 704, 'chosen': False, 'correct': False}, {'_': 'PollAnswerVoters', 'option': [51], 'voters': 279, 'chosen': True, 'correct': False}], 'total_voters': 3520, 'recent_voters': [], 'solution': None, 'solution_entities': []}}
Questionz = data['poll']['question']
Answerz = ""
Truez = ""
fullData = ""
#print(data['poll']['question'])
for answer in data['poll']['answers']:
#print(answer['text'], answer['option'])
Answerz = Answerz + answer['text'] + "n"
#print(answer['text'])
for results in data['results']['results']:
#print(results['correct'])
Truez = Truez + str(results['correct']) + "n"
TruezLines = Truez.split("n")
n = 0
for line in Answerz.splitlines():
print(line, "|||||||||" ,TruezLines[n])
fullData = line, "|||||||||" ,TruezLines[n]
n += 1
Good day every one,
I’m trying to parse telegram poll data, I have the following:
{'_': 'MessageMediaPoll', 'poll': {'_': 'Poll', 'id': 578954245254551900254, 'question': 'Have you seen it ?! ', 'answers': [{'_': 'PollAnswer', 'text': 'Lost', 'option': [48]}, {'_': 'PollAnswer', 'text': 'Am lose', 'option': [49]}, {'_': 'PollAnswer', 'text': 'Have lost', 'option': [50]}, {'_': 'PollAnswer', 'text': 'Am losing', 'option': [51]}], 'closed': False, 'public_voters': False, 'multiple_choice': False, 'quiz': True, 'close_period': None, 'close_date': None}, 'results': {'_': 'PollResults', 'min': False, 'results': [{'_': 'PollAnswerVoters', 'option': [48], 'voters': 2066, 'chosen': False, 'correct': True}, {'_': 'PollAnswerVoters', 'option': [49], 'voters': 471, 'chosen': False, 'correct': False}, {'_': 'PollAnswerVoters', 'option': [50], 'voters': 704, 'chosen': False, 'correct': False}, {'_': 'PollAnswerVoters', 'option': [51], 'voters': 279, 'chosen': True, 'correct': False}], 'total_voters': 3520, 'recent_voters': [], 'solution': None, 'solution_entities': []}}
and I want to print it like this:
Q: Have you seen it ?!
A: Lost|Correct
A: Am lose|Incorrect
A: Have lost|Incorrect
A: Am losing|Incorrect
How I can achieve that in Python? and what is the type of the data? json?
data = {'_': 'MessageMediaPoll', 'poll': {'_': 'Poll', 'id': 57894245245450254, 'question': 'Have you seen it ?! ', 'answers': [{'_': 'PollAnswer', 'text': 'Lost', 'option': [48]}, {'_': 'PollAnswer', 'text': 'Am lose', 'option': [49]}, {'_': 'PollAnswer', 'text': 'Have lost', 'option': [50]}, {'_': 'PollAnswer', 'text': 'Am losing', 'option': [51]}], 'closed': False, 'public_voters': False, 'multiple_choice': False, 'quiz': True, 'close_period': None, 'close_date': None}, 'results': {'_': 'PollResults', 'min': False, 'results': [{'_': 'PollAnswerVoters', 'option': [48], 'voters': 2066, 'chosen': False, 'correct': True}, {'_': 'PollAnswerVoters', 'option': [49], 'voters': 471, 'chosen': False, 'correct': False}, {'_': 'PollAnswerVoters', 'option': [50], 'voters': 704, 'chosen': False, 'correct': False}, {'_': 'PollAnswerVoters', 'option': [51], 'voters': 279, 'chosen': True, 'correct': False}], 'total_voters': 3520, 'recent_voters': [], 'solution': None, 'solution_entities': []}}
Questionz = data['poll']['question']
Answerz = ""
Truez = ""
fullData = ""
#print(data['poll']['question'])
for answer in data['poll']['answers']:
#print(answer['text'], answer['option'])
Answerz = Answerz + answer['text'] + "n"
#print(answer['text'])
for results in data['results']['results']:
#print(results['correct'])
Truez = Truez + str(results['correct']) + "n"
TruezLines = Truez.split("n")
n = 0
for line in Answerz.splitlines():
print(line, "|||||||||" ,TruezLines[n])
fullData = line, "|||||||||" ,TruezLines[n]
n += 1