Convert Excel to Json

Some time in our projects we need data in json files(mostly web projects). But collecting and managing data in json files is harder(At least this is what I feel) compared to excel. I had recently ran into a similar situation where I need some data. Data is going to be provided by a non-technical person/client. And there going to be several rounds of it.

So I was looking for options what can be done here, where I found several online tools which could be used for same. But I don’t want to use that because of course privacy. I don’t want to upload an excel file to a unknown application which would process it server side give me results.

Another Attempt at Wag3

Until now we had done as of following code. We would create couples of more functions which would help us in managing our application. As discussed earlier we would now we creating different directories and files present inside .git directory along with directory itself. More or less we would something like following directory structure after doing wag init

  • .git is the git directory itself, which contains:
    • .git/objects/ : the object store, which we’ll introduce in the next section.
    • .git/refs/ the reference store, which we’ll discuss . It contains two subdirectories, heads and tags.
    • .git/HEAD, a reference to the current HEAD (more on that later!)
    • .git/config, the repository’s configuration file.
    • .git/description, the repository’s description file.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import sys
import argparse
import os

argparser = argparse.ArgumentParser(description="Another Content Tracker")
argsubparsers = argparser.add_subparsers(title="Commands", dest="command")
argsubparsers.required = True
argsp = argsubparsers.add_parser(
    "init", help="Initialize a new, empty repository.")
argsp.add_argument("path", metavar="directory", nargs="?",
                   default=".", help="Where to create the repository.")


def main(argv=sys.argv[1:]):
    args = argparser.parse_args(argv)
    if args.command == "init":
        cmd_init(args)


def cmd_init(args):
    repo_create(args.path)


class GitRepository(object):
    """A git repository"""
    worktree = None
    gitdir = None

    def __init__(self, path, force=False):
        self.worktree = path
        self.gitdir = os.path.join(path, ".git")


def repo_create(path):
    """Create a new repository at path."""
    repo = GitRepository(path)
    # We check whether there exsits a path of worktree
    if os.path.exists(repo.worktree):
        # if path exsits its a directory or not
        if not os.path.isdir(repo.worktree):
            raise Exception("%s is not a directory!" % path)
        # if path exsits its empty or not
        if os.listdir(repo.worktree):
            raise Exception("%s is not empty!" % path)
    else:
        # Create directory as nothing exist with same path
        os.makedirs(repo.worktree)

Now let’s create function which would gives us path of directory after verifying that the directory exist and if it doesn’t it should gives us an error. We would also require mechanism to check whether we need to create the directory or not if it doesn’t exists.

Another Attempt at Wag 2

Last time we had created cmd_init(args) function. We add more functionality to cmd_init(args).

This was our code till last time.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
import sys
import argparse

argparser = argparse.ArgumentParser(description="Another Content Tracker")
argsubparsers = argparser.add_subparsers(title="Commands", dest="command")
argsubparsers.required = True
argsp = argsubparsers.add_parser("init", help="Initialize a new, empty repository.")
argsp.add_argument("path", metavar="directory", nargs="?", default=".", help="Where to create the repository.")

def main(argv=sys.argv[1:]):
    args = argparser.parse_args(argv)
    if args.command == "init":
        cmd_init(args)
    

def cmd_init(args):
    print("Hello from init")
    

We had added an argument to your sub parser called path. If the value of path is not specified it would be ‘.’ current directory or it would whatever specified. This would help us

Another Attempt to write a git

Second Try

We would be trying to create a mini git clone from this tutorial. I aspect this to go long. In general git is awesome source code manager which is wieldy use.

So first we would be creating a lib file and executing file.

Let’s create a file called wag which would have following code.

1
2
3
4
#!/usr/bin/env python3

import libwag
libwag.main()

Then we would create another file which would be libwag.py with just a main function in it.

An attempt to Write Yourself a Git

So I tried to follow wyag at here but I was not able to. This tutorial is great but I was not able follow it because may be I am not still not much clear with python and how it works. So after much thought I have decided that I would try to create my own blog post series where I would take learnings from wyag and try to do it in my way.