Creating a command line tool to initiate loklak app development
There are various apps presently hosted on apps.loklak.org, which shows several interesting and awesome stuff that can be done using the loklak API. Now the question is how to create a loklak app? Well previously there were two ways to create a loklak app, you could either create an app from scratch creating all the necessary files including index.html (app entry point), app.json (required for maintaining app metadata and store listing), getStarted.md, appUse.md and other necessary files, or you could use the boilerplate app which provides you with a ready to go app template which you have to edit to create your app. Recently there has been a new addition to the repository, a command line tool called loklakinit, built with python which will automate the process of initiating a loklak app on the go. The tool creates the entire loklak app directory structure including app.json with all the necessary details (as provided by the user) and defaults, index.html, a css and js subdirectory with a style.css and script.js in the respective folders, getStarted.md file, appUse.md file and others.md file with proper references in app.json. All that the developer needs to do is, execute the following from the root of the apps.loklak.org repository. bin/loklakinit.sh This will start the process and initiate the app. Creating loklakinit tool Now let us delve into the code. So what actually the script does? How it works? Well the tool acts very much like the popular npm init command. At first the script creates a dictionary which stores the defaults for app.json. Next the script takes a number of inputs from the user and predicts some default values, if the user refuses to provide any input for a particular parameter then the default value for that parameter is used. app_json = collections.OrderedDict() app_json["@context"] = "http://schema.org" app_json["@type"] = "SoftwareApplication" app_json["permissions"] = "/api/search.json" app_json["name"] = "myloklakapp" app_json["headline"] = "My first loklak app" app_json["alternativeHeadline"] = app_json["headline"] app_json["applicationCategory"] = "Misc" app_json["applicationSubCategory"] = "" app_json["operatingSystem"] = "http://loklak.org" app_json["promoImage"] = "promo.png" app_json["appImages"] = "" app_json["oneLineDescription"] = "" app_json["getStarted"] = "getStarted.md" app_json["appUse"] = "appUse.md" app_json["others"] = "others.md" author = collections.OrderedDict() author["@type"] = "Person" author["name"] = "" author["email"] = "" author["url"] = "" author["sameAs"] = "" app_json["author"] = author The first part of the script inserts some default values into the app_json dictionary. Now what is an OrderedDict? Well, it is nothing but a python dictionary in which the order in which the keys are inserted is maintained. A ordinary python dictionary does not maintain the order of the keys. while True : app_name = raw_input("name (" + app_json["name"] + ") : ") if app_name : app_json["name"] = app_name app_context = raw_input("@context (" + app_json["@context"] + ") : ") if app_context : app_json["@context"] = app_context app_type = raw_input("@type (" + app_json["@type"] + ") : ") if app_type : app_json["@type"] = app_type app_permissions = raw_input("permissions (" + app_json["permissions"] + ") : ") if app_permissions : app_json["permissions"] = app_permissions.split(",") app_headline = raw_input("headline (" + app_json["headline"] + ") : ") if app_headline : app_json["headline"] = app_headline…
