i managed to find a way to scrap discord messages from a specific channel, turn them into a json format and print the result.
import requests
import json
def retrieve_messages(channelid):
headers = {
'authorization':'MjExMTQ1ODEzNTk2ODMxNzU2.YjtnkQ.-jOz1PucvMjdQ8r2yXdKMpSLK2M'
}
response = requests.get(
f'https://discord.com/api/v9/channels/{channelid}/messages', headers=headers)
data = json.loads(response.text)
for description in data:
print(description)
retrieve_messages('956262565237903401')
Which returns just fine what it's supposed to.
E.G: Cleared in 27:38 of 38:00 (27.3% remaining) for 148 Points\n\n Kindama - Healer (Holy Priest)
The thing that i'd like to do and cannot find how to whatsoever, is, how can i count the occurences in all those lines of a particular keyword such as "Kindama"
I've tried syntax with .index which return false even if the string is present in json,
If anyone with python/json knowledge could give me hints about where to go from there i'd be thankful,
EDIT, Tryouts:
adding to the function:
index=data.index("Kindama")
print(index)
Tells me that 'Kindama' is not in list
adding to the function:
for line in data:
for key in occurences.keys():
occurences[key] += line.count(key)
print(occurences)
Tells me that "AttributeError: 'dict' object has no attribute 'count'"
So what i'm guessing at that point is that the scrapping didnt transform the data in a proper string or that i'm accessing it properly