Python Forum
How to use data from an API, to create an alert?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use data from an API, to create an alert?
#8
(Apr-20-2021, 11:36 PM)snippsat Wrote:
(Apr-20-2021, 11:01 PM)PopFendi Wrote: So, are you saying the correct method would be to search for all of the 'sub' and 'com' values first, before trying to search for a keyword within them?
No was just demo how these libraries can help with a large nested return like this.
Not look at more precise what you want(describe it better),doge as you talk about look just like a plain text and not a key in the nested dictionary.

Sorry, let me clarify.

'Doge' is the string I am trying to search for within the values of 'com' and 'sub'. If the 'Doge' string is found, I want it to return the value of 'no' (ie. the thread number) Perhaps my latest attempt might help to illustrate what I mean.

import requests
import json

response = requests.get('https://a.4cdn.org/biz/catalog.json')
catalog = json.loads(response.text)

for page in catalog:
    thread = page['threads']
    for threads in thread:
        no = threads["no"]
        word = "doge"
        try:
            sub = threads["sub"]
            for value in sub:
                if word in value:
                    print(no)
        except:
            pass

        try:
            com = threads["com"]
            for value in com:
                if word in value:
                    print(no)
        except:
            continue
I've added the try / except because some threads do not contain either a 'com' or a 'sub' key, and I was getting a traceback.

Hope that makes sense,
Thank you!
Reply


Messages In This Thread
RE: How to use data from an API, to create an alert? - by PopFendi - Apr-21-2021, 12:04 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Monitor specific line of code and get alert Olimpiarob 0 1,540 Jul-08-2020, 10:06 AM
Last Post: Olimpiarob
  Python / Selenium Turning Off Alert graham23s 3 8,300 Aug-18-2019, 02:12 PM
Last Post: metulburr
  Issue closing an Modal Alert (popup) leviathan54 8 5,946 Apr-23-2019, 02:00 PM
Last Post: leviathan54

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020