#๐Ÿ”’ get information from json list

47 messages ยท Page 1 of 1 (latest)

modern furnaceBOT
#

@trim vine

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

trim vine
#

so i am currently trying to check a json list for available timeslots

#

the timeslots get displayed in a json list as timeslots : [] and im trying to check if this changes

noble lotus
#

So if the array is blank, you want the date or?

trim vine
#

and if a timeslots becomes available it changes from empty and i want to extract that information

noble lotus
#

So then it would get the date if the timeslot is empty?

#

Just to clarify

trim vine
#

get the date if the timeslot isnt empty

noble lotus
#

Alright, let me create that program

trim vine
#

thanks a lot

noble lotus
#

Is the JSON stored in a varable or is a file?

#

So if I need to use load or loads

trim vine
#

variable if possible

#

i get the list from a web requests

noble lotus
#

Whats the request if thats fine with you

trim vine
#

that wont be possible unfortunately as the request is protected by a unique token

noble lotus
#

Whats the URL? You can do all the secrets on your side

#

Or not, nvm

trim vine
#

easy

#

thats the link

#

but you shouldnt be able to access the data

#

but its exactly as in the pastebin link above

noble lotus
#

No, it gives me an error, so your good

#

And now I make the code

tidal ravine
#

I think no need to convert data. It is returning as dict.

noble lotus
#

@trim vine

import requests

# Used pastebin for testing, replace with actual link
data = requests.get("https://paste.pythondiscord.com/raw/VZCQ").json()

open_dates = []

for spot in data:
    if spot['timeslots']:
        open_dates.append(spot['date'])

# Now, we go through every date with the timeslots not empty
print("Open Days:")
print("------------")
for day in open_dates:
    print(f"- {day}")

trim vine
#

made my day

noble lotus
#

Does it work how you want it to?

noble lotus
trim vine
noble lotus
#

I think there is a close thread command

noble lotus
tidal ravine
#

@noble lotus , it looks like you have lots of problems.

noble lotus
#

I have a lot of problems?

noble lotus
tidal ravine
#

I can see your other questions as well.

#

are you building any application ?

noble lotus
#

Then go to that thread :/

#

thats not even on topic of this

modern furnaceBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.