Well, I came back to writing a bot for vk on python. It shows first signs of life and first obstacles.
One of these are smiles that may arrive in a private message or chat. I have a function that disassembles every incoming message into string using my own functions and json library.
#getting a message
def getmessage(out, count):
payload['out']=str(out)
payload['count']=str(count)
return json.loads(requests.get(api+'messages.get', payload).text) ['response']['items'][0]
#disassembling a message
def messageanalysis(message):
m=message
mes={
'date':m['date'],
'id':m['id'],
'user_id':m['user_id'],
'body':m['body']}
return mes
So, then I .split() the string mes['body'] and compare every word from it to a set of templates and based on the result decide what to answer.
So just now I've received a smile in private messages and the program crashed, not knowing what to do with a .png file. It's interesting that unlike a regular attachment that has its own parameters in the object "message", received by vk server, the smile is directly integrated into the body of the message. What should I do to at least prevent the program from crashing because of smiles, or, which is better, make it recognize that a smile was sent?
====== Error:
Traceback (most recent call last):
File "C:\BOT\Body.py", line 24, in <module>
print('User_id: '+str(m['user_id'])+'\nMessage: '+str(m['body'])+'\n')
File "C:\Users\Арсений\AppData\Local\Programs\Python\Python35-32 \lib\idlelib\PyShell.py", line 1344, in write
return self.shell.write(s, self.tags)
UnicodeEncodeError: 'UCS-2' codec can't encode characters in position 28-28: Non-BMP character not supported in Tk