kshitij10496 / hercules

The mighty hero helping you build projects on top of IIT Kharagpur's academic data
https://hercules-10496.herokuapp.com/api/v1/static/index.html
MIT License
34 stars 18 forks source link

Prettify JSON encoding after scapping data #5

Closed kshitij10496 closed 5 years ago

kshitij10496 commented 5 years ago

Currently, I'm encoding the data scrapped from the timetable directly into a JSON. This is an ad-hoc way just to get things done. Ideally, we would want to store the data into a beautiful format, similar to what jq does.

Add indentation and formatting while encoding the scrapped data. This would involve modifying the CourseEncoder class.

Refer: /data/scrapper/course_rooms.py

icyflame commented 5 years ago

Fixed in #12. The line that you have pointed to in the code doesn't worry about indentation, it's a dict object. We need to specify the indentation we need to the json.dump function which is actually converting the dictionary to a string. 🙂

kshitij10496 commented 5 years ago

I see. Isn't there a way to associate the data formatting in the Encoder class itself? 🤔

Oh man! I just don't like Python standard library's way of dealing with JSON anymore after learning Go. It all looks just so contrained. 😉

kshitij10496 commented 5 years ago

@themousepotato @Ayushk4 What do you guys think about this?

themousepotato commented 5 years ago

I agree with @icyflame . I can't find any way to make indentation in the Encoder itself.

icyflame commented 5 years ago

@kshitij10496 We could do it in the encoder class by adding a method called CourseEncoder.encodeToJson(courses). Sounds like a thing that the encoder class should do (and shouldn't be done outside the encoder class).

kshitij10496 commented 5 years ago

I think this could complicate things even further. Let's use indent keyword argument in the call to json.dumps function as you suggested above. A minor suggestion would be the addition of sort_keys to maintain a uniformity in the resulting output. 😄