Google Calendar (Sample widget)

  • This widget displays the Google Calendar on your TV screen.
  • The web page that you will need to use as a reference is the one below:

The widget’s Script code

Script CodeExpand source

    type("""#identifierId""" , """{{email|default:'a@b.c'}}""")
    click("""#identifierNext""")
    type("""input[name="password"]""" , """{{password|default:'password'}}""")
    click("""#passwordNext""")
    pause(5)
    runScript("""
        var period = "{{period|default:'week'}}";

        switch (period) {

            case "day":
                window.location.href = "https://calendar.google.com/calendar/r/day?pli=1";
                break;

            case "week":
                window.location.href = "https://calendar.google.com/calendar/r/week?pli=1";
                break;

            case "month":
                window.location.href = "https://calendar.google.com/calendar/r/month?pli=1";
                break;

            case "year":
                window.location.href = "https://calendar.google.com/calendar/r/year?pli=1";
                break;

            case "schedule":
                window.location.href = "https://calendar.google.com/calendar/r/agenda?pli=1";
                break;

            case "customday":
                window.location.href = "https://calendar.google.com/calendar/r/customday?pli=1";
                break;
        }
    """)
    waitForPageLoad()
    repeat(0){
    pause({{refresh|default:180}})
    refreshAndWait()
    click("""#tab-controller-container-week""")  
    runScript("""
        if(document.querySelector('div[role="main"]')){
          var elem = j('div[role="main"]');
          j('body').append(elem);
          j('body>:visible').not(':last').remove();
        }
    """)
    }

The widget’s JSON Schema

We need the declare a schema for the required configuration fields:

  1. email: the email of the user
  2. password: the password of the user
  3. refresh: the refresh rate of the graph
  4. period: the time period that you want to show the graph

JSON SchemaExpand source

{
  "fields": [
    "email",
    "password",
    "refresh",
    "period"
  ],
  "schema": {
    "password": {
      "validators": [
        "required"
      ],
      "type": "Password",
      "title": "Password"
    },
    "email": {
      "validators": [
        "required",
        "email"
      ],
      "type": "Text",
      "title": "Email Address"
    },
    "refresh": {
      "validators": [
        "required"
      ],
      "type": "Number",
      "title": "Refresh Interval (sec)"
    },
    "period": {
      "type": "Select",
      "options": [
        {
          "val": "day",
          "label": "Day"
        },
        {
          "val": "week",
          "label": "Week"
        },
        {
          "val": "month",
          "label": "Month"
        },
        {
          "val": "year",
          "label": "Year"
        },
        {
          "val": "schedule",
          "label": "Schedule"
        },
        {
          "val": "customday",
          "label": "4 days"
        }
      ],
      "def": "day",
      "title": "Select Period"
    }
  }
}