Django & JunaTracker

As hinted in the previous JunaTracker post, I have started creating a GUI for the project. Again took some time to learn new stuff (Django, bootstrap) but it’s going pretty well. I have a running application in the dev environment and at the moment I’m figuring out what other useful information I can extract from the API on top of the running times.

The next steps will be to expand the application to cover all the stations and also learn nginx or other web server configuration as the django server is only for dev. Not that I’m sure I will publish this but it never harms to learn how to setup a webserver in production. Perhaps try pentesting and other security related topics 🙂

The setup

Originally the program was running in a way that it requested a json from the API, saved it on the fs and then parsed and printed it on the screen. It has now been modified and the fs part has been scrapped. The queried json is now parsed on the fly and loaded into a MySQL database. Django comes with SqlLite but I figured it’s better to use MySQL for the job.

As I’m still a novice, I’m not even going to try to cover what Django is or is not other than: It’s a web applications framework and fairly easy to understand. And it enables separated development of models, views and templates. So at this point I’m mainly focusing on the models as I’m figuring out how the data should actually be modelled. I have of course views and templates to show the data and I even applied bootstrap on top of the site but the content is more important than the look and feel at this point.

There are a plenty of great tutorials on how to get MySQL to work with the Django. You basically change the’s database part and setup the MySQL. At later point I will config the db settings in a separate file and just reference that.

    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'TRAINDB',
        'USER': <username>,
        'PASSWORD': <password>,
        'HOST': '',
        'PORT': '',
        'OPTIONS': {'init_command': "SET sql_mode='STRICT_TRANS_TABLES'"},

I think I have struggled more on finding python-MySQL connector for the Raspberry. Oh yes, it’s already running on my Raspi 🙂 I’ll cover that later. The actual loading of the parsed JSON is easy as you can see. The data is inserted as string at the moment but the types will be corrected at later point. I just wanted to get things going in.


The look and feel

As stated, I haven’t spent too much time on the html/css part and that will be another interesting area to dig into. But as you can see, I have managed to make it bearable at least junatrackerThe train number is a link to the details and perhaps an OpenStreetMap with the location. To be seen though.

All in all, at the moment I’m more focused on the back-end than front-end. Should I publish the application then the front-end requires some serious work and testing but that’s really not my ultimate goal. Although the idea is tempting and would push me to “learn more” so to speak.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s