As Google Summer of Code 2016 has officially begun, I am all excited to be working with FOSSASIA yet again. This time, I have been assigned the project Loklak where I shall be spending the summer working on implementing indexing (harvester/scrapers) for different services like,,, Instagram etc.

Loklak is a server application which is able to collect messages from various sources, including Twitter. This server contains a search index and a peer-to-peer index sharing interface. If one likes to be anonymous when searching things, want to archive Tweets or messages about specific topics and if you are looking for a tool to create statistics about Tweet topics, then Loklak is the best option to consider.


Time across seven seas…

It has been rightly said:

Time is of your own making
Its clock ticks in your head.
The moment you stop thought
Time too stops dead.


Hence to keep up with evolving times, Loklak has now introduced a new service for “time”.

The recently developed API provides the current time and day at the location queried by the user. The /api/locationwisetime.json API scrapes the results from using our favourite JSoup as it provides a very convenient API for extracting and manipulating data, scrape and parse HTML from a given URL.

In case of multiple locations with the same name, countries are then also provided along-with corresponding day and time wrapped up as a JSONObject. A sample query could then be something like:

Screenshot from 2016-08-17 14:28:28

When implemented as a console service, this API can be used along-with our our dear SUSI by utilising the API Endpoints like: * FROM locationwisetime WHERE query=’berlin’;

Screenshot from 2016-08-17 14:50:58 for reference:

 *  Location Wise Time
 * scraper
 *  Copyright 27.07.2016 by Jigyasa Grover, @jig08
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  Lesser General Public License for more details.
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program in the file lgpl21.txt
 *  If not, see <>.



import javax.servlet.http.HttpServletResponse;

import org.json.JSONArray;
import org.json.JSONObject;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.loklak.server.APIException;
import org.loklak.server.APIHandler;
import org.loklak.server.AbstractAPIHandler;
import org.loklak.server.Authorization;
import org.loklak.server.BaseUserRole;
import org.loklak.server.Query;
import org.loklak.susi.SusiThought;

public class LocationWiseTimeService extends AbstractAPIHandler implements APIHandler {

    private static final long serialVersionUID = -1495493690406247295L;

    public String getAPIPath() {
        return "/api/locationwisetime.json";

    public BaseUserRole getMinimalBaseUserRole() {
        return BaseUserRole.ANONYMOUS;


    public JSONObject getDefaultPermissions(BaseUserRole baseUserRole) {
        return null;

    public JSONObject serviceImpl(Query call, HttpServletResponse response, Authorization rights,
            JSONObjectWithDefault permissions) throws APIException {
        String query = call.get("query", "");
        return locationWiseTime(query);

    public static SusiThought locationWiseTime(String query) {
        Document html = null;

        JSONArray arr = new JSONArray();

        try {
            html = Jsoup.connect("" + query).get();
        } catch (IOException e) {

        Elements locations ="td");
        int i = 0;
        for (Element e : locations) {
            if (i % 2 == 0) {
                JSONObject obj = new JSONObject();
                String l = e.getElementsByTag("a").text();
                obj.put("location", l);
                String t = e.nextElementSibling().text();
                obj.put("time", t);
        SusiThought json = new SusiThought();
        return json;


Hope this helps, and worth the “time” 😜 Feel free to ask questions regarding the above code snippet, shall be happy to assist. Feedback and Suggestions welcome 🙂

PS: As pointed out by Shane Buck in one of his comments is not lucidly accessible for the sight impaired, hence adding a link to which is WCAG 2.0 compatible. Thanks Shane !