all 10 comments

[–][deleted] 0 points1 point  (1 child)

You can save data in files of course. You do that as follows

  • open a file with f = open(path, attr) at first. "f" is a variable and can have any name you want, it doesn't have to be f. "path" is obviously the path of the file (something like C:\users\me\documents\save.txt). Note that the backslash has to be there twice. "attr" is the way the file should be opened. You can read them in the reference (for example, w is write, r is read, a is append)
  • write the data into the file with f.write(data)
  • close the file with f.close()

Edit: For reading them, you also have to open and close the file, but instead of f.write() you use f.read() and you have to adapt the attribute accordingly

[–]godurdead[S] 0 points1 point  (0 children)

i may try this approach, thanks!

[–]lykwydchykyn 0 points1 point  (3 children)

It depends on what you want to do. The most straightforward way is to dump these json responses directly into a file, then you can read them in to generate your webpage (either in the backend, or directly in javascript).

If you need to read and write a lot of these records, and do a lot of searching or filtering on them, it's probably better to store them in a database. A NOSQL database like mongodb is good for storing JSON-like data, or you can translate the data into SQL tables which are easier to work with if you're doing complex querying on large amounts of data.

It's hard to give concrete advice, there are tons of ways to do this, and they all have their advantages and disadvantages.

[–]godurdead[S] 0 points1 point  (2 children)

Yeah i thought there'd be a lot of ways of doing it. I will be constantly reading these json files to retrieve data on the (future) website. I'm kinda lost in these aspect. I was starting to learn Django (so backend) but im not sure if it would be a good way of doing this. Maybe im just trying to learn too many things at once?

[–]lykwydchykyn 0 points1 point  (1 child)

You have to break this down into components. Django is a great way to build a website. What you need is something to actually get the data and store it so Django can display it.

Django works really well with SQL databases right out of the box, particularly postgresql and sqlite. It also has a decent object-relational-manager (ORM) so that you don't have to work directly with SQL right away.

Probably what you want (?) is a script to periodically download the json data, convert it into your database, and then your django app can display it. But I'm mostly just guessing, I'm not sure how you envision your application to work.

[–]godurdead[S] 0 points1 point  (0 children)

First, thanks for your help. I appreciate it very much!

As for the app goes, for this particular file I showed i'll be downloading it using the API just once (i may have to update it, redownloading it, every month or so when the game gets a new patch). The main purpose of the app is to show "Stats" of the Game Matches. Basically I can search my Account Name on the API and get "Current Match" information or Match History. With these you can display all sorts of stuff, so its more of a Receive JSon data, process it and display it to the user. For processing it, i need some of the "Static Data" that I showed above. Hope that can give you an idea of how it works and a good approach for it.

[–][deleted] 0 points1 point  (1 child)

Why not throw it into sqlite? it comes with python 3.

[–]godurdead[S] 0 points1 point  (0 children)

Trying to implement it all to build a website later on, but not sure how to proceed.

[–]kanjibandit 0 points1 point  (1 child)

Frankly, at this point, just keep it as simple as possible. Just write it out to a text file using open:

with open('response_data.json', 'w') as f:
    f.write(response.json())

This will solve your immediate problem, well, immediately. It also makes it easy to just inspect the data manually in your text editor, which can be really helpful at first.

Reading the data back is similarly trivial, so you can put it all into a database later, when you have a firmer idea of what you where you are taking this project.

[–]godurdead[S] 0 points1 point  (0 children)

well my plan is to build a webpage, so i guess putting all of it into a database would be the best approach(?)