So I have been playing around to make a sort of monitor - What monitor is that it prints out whenever a new item, object, number is new, then print it out basically nothing harm.
The json I am printing out (I know this is not a correctly json format now but it does print out the correctly stuff currently)
"threads": {
"1": {
"name": "Hello",
"id": "4174"
},
"2": {
"name": "World",
"id": "6231"
},
"3": {
"name": "Overflow",
"id": "7231"
}
}
Basically I have done a script that right now:
def get_feed():
url = 'https://www.helloworld.com/loadfilter'
resp = s.get(url, timeout=6)
resp.raise_for_status()
return resp.json()['threads']
old_list = []
for index, thread in get_feed().items():
old_list.append(thread['id'])
while True:
try:
new_list = []
for index, thread in get_feed().items():
new_list.append(thread['id'])
for index, item in enumerate(new_list):
if item in old_list:
print(item['name'] # ERROR - string indices must be integers
else:
print('Sleeping 2 sec')
time.sleep(2)
except Exception as e:
print(e)
sys.exit()
So basically if I print out inside the for index, thread in get_feed().items(): a print of thread['name'] that would be not an issue and it would print it out.
However in the for loop of: if item in old_list: - The issue there is it does not print out anything but the id numbers that I have added to the list and I wonder how can I possible make it so it prints out the names through the json that is given above?
Meaning : whenever I print out after the if item old list etc. item['name'] it should give the name?