Dec-29-2018, 11:32 PM
(Dec-29-2018, 10:17 PM)Unisoftdev Wrote: If I understand it well, then you ask how to separately parse particular data from JSON objects.
So when you need to extract a particular variable then you can construct it like:
your_variable = data["groups"][0]["columns"]... and so far.
When you parse JSON, you just create a crew/line.
Do you mean a beautiful HTML + CSS table on the client-side languages? Maybe, it's gonna take a time which could be spent in a better way (than a free work) and you would like to hire someone. If you have just another question on how you can work on it by yourself then here with it and you will get an answer.
Best regards
Thanks for input. Didnt know i had to parse out each line. (Still learnig python expressions, and not beeing native english language i miss some of them, but do know parse now :) )
So what i did now is i made a new line for each data set i need:
# First making the headers for the table title = data['headers'] # Then the data date = data['groups'][0]['columns'][0] day = data['groups'][0]['columns'][1] week = data['groups'][0]['columns'][2] season = data['groups'][0]['columns'][3] team = data['groups'][0]['columns'][4] oteam = data['groups'][0]['columns'][5] site = data['groups'][0]['columns'][6] points = data['groups'][0]['columns'][7] opoints = data['groups'][0]['columns'][8] line = data['groups'][0]['columns'][9] total = data['groups'][0]['columns'][10]Google a bit and found prettytable. That looks fine for me in python. Dont know what to pick from a webpage. Totally newbie there, so dont know anything about it.
so:
from prettytable import prettytable # Starts the prettytable with the headings for all columns t = PrettyTable(title) # Adds all the data to the table, 1 row at a time t.add_row([date[0], day[0], week[0], season[0], team[0], oteam[0], site[0], points[0], opoints[0], line[0], total[0]]) t.add_row([date[1], day[1], week[1], season[1], team[1], oteam[1], site[1], points[1], opoints[1], line[1], total[1]]) print[t] +----------+--------+------+--------+-------+---------+------+--------+----------+------+-------+ | date | day | week | season | team | o:team | site | points | o:points | line | total | +----------+--------+------+--------+-------+---------+------+--------+----------+------+-------+ | 20110911 | Sunday | 1 | 2011 | Bears | Falcons | home | 30 | 12 | 2.0 | 40.5 | | 20110918 | Sunday | 2 | 2011 | Bears | Saints | away | 13 | 30 | 6.0 | 47.0 | +----------+--------+------+--------+-------+---------+------+--------+----------+------+-------+So far so good :)
Now i would like to add SUM next to total.
title.append('SUM')Then i would like to sum up the numbers from points and o:points columns. So i below sum gets 42 and 43 accordingly.
Also bonus question.
I never know if my api returns 1 line of data or 200 lines.
So how to write the t.add_row part when lines is dynamic.
Also if there is 200 lines, i only need to print out 10 lines or so. How to add that part.
Thanks
/ Carsten