Bot is not parsing the posts from the wall of the VK group channel Discord In what was my mistake?

Hello!
Write a bot in Python(e).
After editing some functions, the bot started up and responds to the command. But then just doesn't. In the terminal window, swearing strange error. But the bot is active. Tell me, maybe someone knows how to fix?
For earlier thanks for the help. To Google not to send, there is nothing found.
# -*- coding: utf-8 -*-
import urllib.request
import json
import re
import config
import time
import datetime
import codecs
from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool

import shell
import asyncio
# import vk_api

# initialized
vdbot = discord.Client()
chat_ids = []
ids = open('ids', 'r')
ids_arr = ids.read().split(',')
for i in ids_arr:
 if len(i) > 1:
print(i)
chat_ids.append(int(i))
ids.close()
pool = ThreadPool(4)

@vdbot.event
@asyncio.coroutine
def on_ready():
 print('Logged in the shell')
print(vdbot.user.name)
print(vdbot.user.id)
print('------')
@vdbot.event
@asyncio.coroutine
def on_message(message):
 # parsim /start a new ID and sign for the distribution of news
 if message.content.startswith('!start'):
 yield from message.channel.send(config.greeting)
 print(str(message.channel.id) + " !start")

 if not message.channel.id in chat_ids:
 # if the executed command is not in the list - recordable
 # at file and dobbelaer in the array
 with open('ids', 'a') as ids:
 ids.write(str(message.channel.id) + ",")
chat_ids.append(message.channel.id)

print(chat_ids)


# get post with by means of the shift
def get_post(number=1):
 news_off = number

 cooked = []
 a = urllib.request.urlopen('https://api.vk.com/method/wall.get?owner_id=-' + str(config.group_id) + '&filter=owner&count=1&offset=' + str(news_off) + '&v=5.63&access_token=' + str(config.vk_token))
 out = a.read().decode('utf-8')
 json_data = json.loads(out)
 # get the raw text
 text = json_data['response'][1]["text"]
 id_from_id = str(json_data['response'][1]["from_id"]) + "_" + str(json_data['response'][1]["id"])
 # remove html tripe
 text = text.replace('<br>', '\n')
 text = text.replace('&amp', '&')
 text = text.replace('&quot', '"')
 text = text.replace('&apos', "'")
 text = text.replace('&gt', '>')
 text = text.replace('&lt', '<')

 # if found the link to the profile
 profile_to_replace = re.findall(r'\[(.*?)\]', text)
 profile_link = re.findall(r'\[(.*?)\|', text)
 profile_name = re.findall(r'\|(.*?)\]', text)
 profiles = []

 # sameem a link to the profile in the text
try:
 for i in range(len(profile_link)):
 profiles.append(profile_name[i] + " (@" + profile_link[i] + ")")
 counter = 0
 for i in profile_to_replace:
 text = text.replace("[" + i + "]", profiles[counter])
 counter += 1
except:
pass

 text += u"\n\commentarii: http://vk.com/wall" + id_from_id
cooked.append(text)
cooked.append(json_data['response'][1]["date"])

 # on the occasion of the meeting with the media (realized that while photo and thumb to video)
try:
 media = json_data['response'][1]["attachments"]

 media_arr = []
 for i in media:
 if "photo" in i:
media_arr.append(i["photo"]["src_xbig"])
 if "video" in i:
 media_arr.append("http://vk.com/video" + i["video"]["owner_id"] + "_" + i["video"]["vid"])
 if "doc" in i:
media_arr.append(i["doc"]["url"])
cooked.append(media_arr)
except:
pass
 return cooked


# check new posts
@asyncio.coroutine
#def checker(loop):
def checker():
 yield from vdbot.wait_until_ready()
 if len(chat_ids) < 1:
return
 with open('timestamp', 'r') as t:
 timestamp = str(t.read())
 while not vdbot.is_closed():
 print('checking...' + str(datetime.datetime.now()))
 last_posts = 1
 end = False
 # check the new news on timestamp and get a number of new
 while not end:
 post = get_post(last_posts)
 if post[1] > timestamp:
 last_posts += 1
else:
 last = get_post()
 timestamp = last[1]
 with open('timestamp', 'w') as t:
t.write(str(timestamp))
 end = True

 print('found' + str(last_posts - 1) + ' new posts!')
 #def on_message(message):
 # send each the required number of posts
 if last_posts > 1:
 for post_c in range(last_posts - 1):
 post = get_post(last_posts - 1 - post_c)
 text_to_send = post[0]
 photo_to_send = []
 if len(post) > 2:
 for i in post[2]:
photo_to_send.append(i)
 for idc in chat_ids:
try:
 yield from message.channel.send(vdbot.get_channel(str(idc)), text_to_send)
 if photo_to_send:
 for i in photo_to_send:
 yield from message.channel.send(vdbot.get_channel(str(idc)), str(i))
 #await vdbot.send_file(vdbot.get_channel(str(id_)), str(i))

 except Exception:
pass
 # sleep 1 minute
 yield from asyncio.sleep(1 * 60)

#def wait_until_ready():
 #raise Exception()

#vdbot.loop.run_until_complete(asyncio.gather(checker()))
#vdbot.loop.set_exception_handler(checker)
#vdbot.loop = asyncio.get_event_loop()
vdbot.loop.create_task(checker())
vdbot.run(config.token)

5cf2b162b5790773273416.png
March 23rd 20 at 18:41
1 answer
March 23rd 20 at 18:43
Solution
You have a key [1] in the answer from VK
text = json_data['response'][1]['text']
For more detail, please? - waylon.Carroll8 commented on March 23rd 20 at 18:46
@waylon.Carroll8, KeyError at line 62 says that in the json received in the response of the VC is missing key [1] - orin68 commented on March 23rd 20 at 18:49
Read docks vk api, there should be answers from the server, and respectively correct the logic of the script.
To correctly handle the various responses.
As a variant debug prints
print(json_data['response']) - orin68 commented on March 23rd 20 at 18:52
@orin68Well. Now I will try. Thanks for the tip. - waylon.Carroll8 commented on March 23rd 20 at 18:55
@waylon.Carroll8, most likely a typo, the response is responce - william.Effertz commented on March 23rd 20 at 18:58
and no, it's not a typo, not seen) - william.Effertz commented on March 23rd 20 at 19:01
@orin68, thanks again! Now parses.
However, missing this kind:
future: <Task finished coro=<checker() done, defined at d:/VDbot/bot.py:113> exception=ValueError("invalid literal for int() with base 10: "")>
Traceback (most recent call last):
 File "d:/VDbot/bot.py", line 120, in checker
 timestamp = int(t.read())
ValueError: invalid literal for int() with base 10: "

Can you tell me where to dig? - waylon.Carroll8 commented on March 23rd 20 at 19:04
@waylon.Carroll8,
future: exception=ValueError("invalid literal for int() with base 10: "")>
Traceback (most recent call last):
File "d:/VDbot/bot.py", line 120, in checker
timestamp = int(t.read())
ValueError: invalid literal for int() with base 10: "

t.read() returns an empty string - orin68 commented on March 23rd 20 at 19:07
@william.Effertz, corrected - orin68 commented on March 23rd 20 at 19:10
@orin68Litter. I have already corrected. All parses as it should, mistakes are not curses. But the new post not refers in deep. Looking for the cause.
# -*- coding: utf-8 -*-
import urllib.request
import json
import re
import config
import time
import datetime
import codecs
from multiprocessing import Pool
from multiprocessing.dummy import Pool as ThreadPool

import shell
import asyncio
# import vk_api

# initialized
vdbot = discord.Client()
chat_ids = []
ids = open('ids', 'r')
ids_arr = ids.read().split(',')
for i in ids_arr:
 if len(i) > 1:
print(i)
chat_ids.append(int(i))
ids.close()
pool = ThreadPool(4)

@vdbot.event
@asyncio.coroutine
def on_ready():
 print('Logged in the shell')
print(vdbot.user.name)
print(vdbot.user.id)
print('------')
@vdbot.event
@asyncio.coroutine
def on_message(message):
 # parsim /start a new ID and sign for the distribution of news
 if message.content.startswith('!start'):
 yield from message.channel.send(config.greeting)
 print(str(message.channel.id) + " !start")

 if not message.channel.id in chat_ids:
 # if the executed command is not in the list - recordable
 # at file and dobbelaer in the array
 with open('ids', 'a') as ids:
 ids.write(str(message.channel.id) + ",")
chat_ids.append(message.channel.id)

print(chat_ids)

# get post with by means of the shift
def get_post(number=1):
 news_off = number

 cooked = []
 a = urllib.request.urlopen('https://api.vk.com/method/wall.get?owner_id=-' + str(config.group_id) + '&filter=owner&count=1&offset=' + str(news_off) + '&extended=1&v=5.95&access_token=' + str(config.vk_token))
 out = a.read().decode('utf-8')
 json_data = json.loads(out)
 # get the raw text
 #print( json_data['response']['items'][0]["text"])
 text = json_data['response']['items'][0]["text"]
 id_from_id = str(json_data['response']['items'][0]["from_id"]) + "_" + str(json_data['response']['items'][0]["id"])
 # remove html tripe
 text = text.replace('<br>', '\n')
 text = text.replace('&amp', '&')
 text = text.replace('&quot', '"')
 text = text.replace('&apos', "'")
 text = text.replace('&gt', '>')
 text = text.replace('&lt', '<')

 # if found the link to the profile
 profile_to_replace = re.findall(r'\[(.*?)\]', text)
 profile_link = re.findall(r'\[(.*?)\|', text)
 profile_name = re.findall(r'\|(.*?)\]', text)
 profiles = []

 # sameem a link to the profile in the text
try:
 for i in range(len(profile_link)):
 profiles.append(profile_name[i] + " (@" + profile_link[i] + ")")
 counter = 0
 for i in profile_to_replace:
 text = text.replace("[" + i + "]", profiles[counter])
 counter += 1
except:
pass

 text += u"\n\commentarii: http://vk.com/wall" + id_from_id
cooked.append(text)
cooked.append(json_data['response']['items'][0]["date"])

 # on the occasion of the meeting with the media (realized that while photo and thumb to video)
try:
 media = json_data['response']['items'][0]["attachments"][0]

 media_arr = []
 for i in media:
 if "photo" in i:
media_arr.append(i["photo"]["sizes"][0]["url"])
 if "video" in i:
 media_arr.append("http://vk.com/video" + i["video"]["owner_id"] + "_" + i["video"])
 if "doc" in i:
media_arr.append(i["doc"][0]["url"])
cooked.append(media_arr)
except:
pass
 return cooked

# check new posts
@vdbot.event
@asyncio.coroutine
#def checker(loop):
def checker():
 yield from vdbot.wait_until_ready()
 if len(chat_ids) < 1:
return
 with open('timestamp', 'r') as t:
 timestamp = int(t.read())
 while not vdbot.is_closed():
 print('checking...' + str(datetime.datetime.now()))
 last_posts = 1
 end = False
 # check the new news on timestamp and get a number of new
 while not end:
 post = get_post(last_posts)
print(post)
 if post[1] > timestamp:
 last_posts += 1
else:
 last = get_post()
 timestamp = last[1]
 with open('timestamp', 'w') as t:
t.write(str(timestamp))
 end = True

 print('found' + str(last_posts - 1) + ' new posts!')
 #def on_message(message):
 # send each the required number of posts
 if last_posts > 1:
 for post_c in range(last_posts - 1):
 post = get_post(last_posts - 1 - post_c)
 text_to_send = post[0]
 photo_to_send = []
 if len(post) > 2:
 for i in post[2]:
photo_to_send.append(i)
 for id_ in chat_ids:
try:
 yield from message.channel.send(vdbot.get_channel(str(id_)), text_to_send)
 if photo_to_send:
 for i in photo_to_send:
 yield from message.channel.send(vdbot.get_channel(str(id_)), str(i))
 #yield from channel.send(vdbot.get_channel(str(id_)), str(i))

except:
pass
 # sleep 1 minute
 yield from asyncio.sleep(1 * 60)

#def wait_until_ready():
 #raise Exception()
#print(vdbot.message.channel.send)
#vdbot.loop.run_until_complete(asyncio.gather(checker()))
#vdbot.loop.set_exception_handler(checker)
#vdbot.loop = asyncio.get_event_loop()
vdbot.loop.create_task(checker())
vdbot.run(config.token)

The output of the terminal:
5cf366bab5355338026341.png - waylon.Carroll8 commented on March 23rd 20 at 19:13
@waylon.Carroll8,
All parses as it should, mistakes are not curses. But the new post not refers in deep. Looking for the cause.

Can you please mark my answer with a solution and ask a new question.
One mistake - one question. - orin68 commented on March 23rd 20 at 19:16
@orin68, but not the issue. In gratitude, I can do that. Bot does not send parsed post from the wall of the group ... - waylon.Carroll8 commented on March 23rd 20 at 19:19

Find more questions by tags DiscordVKontakteJSONPython