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?
#6
(Apr-20-2021, 10:27 PM)snippsat Wrote: The first post was correct no need to mix in json library.
import requests
 
response = requests.get('https://a.4cdn.org/biz/catalog.json')
catalog = response.json() # Correct
Some tips,also a couple of libraries(jmespath | nested-lookup) that can help search a nested dictionary that json can return.
import requests
from nested_lookup import nested_lookup
import jmespath

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

# Ordinay way
find_sub = catalog[0]['threads'][0]['sub']
print(find_sub)

# Find all <md5> using nested_lookup
find_md5 = nested_lookup('md5', catalog)[:5]
print(find_md5)

# Find thread <no> using jmespath
thread_no = jmespath.search('threads[*].no', catalog[0])
print(thread_no)
Output:
NO BEGGING ['pJvXhdg2z1jzhaXDpXJCSA==', 'FnhPHN6dqDf2BRAe/KlekQ==', 'otmlJIe2Z8Ie1tOznSJeTw==', 'bYhv5BMl3FDUl6Ij35KjFA==', 'aH0WKPS4g13LSXvNvXP8ZQ=='] [4884770, 21374000, 33546252, 33545084, 33529907, 33548153, 33544096, 33534099, 33546968, 33546648, 33547703, 33545399, 33533316, 33544886, 33547053, 33548145, 33547368, 33547858, 33545941, 33546379]

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? Thanks for these libraries, these look very helpful.
Reply


Messages In This Thread
RE: How to use data from an API, to create an alert? - by PopFendi - Apr-20-2021, 11:01 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Monitor specific line of code and get alert Olimpiarob 0 1,493 Jul-08-2020, 10:06 AM
Last Post: Olimpiarob
  Python / Selenium Turning Off Alert graham23s 3 8,179 Aug-18-2019, 02:12 PM
Last Post: metulburr
  Issue closing an Modal Alert (popup) leviathan54 8 5,826 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