Skip to content

headings/paragraphs don't seem to work #97

@rubdos

Description

@rubdos

Hiya!

I'm pushing pins of this form to Rockpool Dbus:

{
  "id": "vub-resto-2021-06-02",
  "time": "2021-06-02T12:00:00+02:00",
  "duration": 60,
  "layout": {
    "type": "genericPin",
    "title": "Resto menu",
    "lastUpdated": "2021-06-01T18:49:13+02:00",
    "tinyIcon": "system://images/DINNER_RESERVATION",
    "headings": [
      "Soup",
      "Menu 1",
      "Menu 2",
      "Wok"
    ],
    "paragraphs": [
      "Broccoli Soup",
      "Vol-Au-Vent Or Vegan Vol-Au-Vent With Cucumber Salad",
      "Lamb Epigram With Ratatouille And Potato Gratin",
      "Pork Stir-Fry With Sweet And Sour Sauce"
    ]
  }
}

I'm using a Ruby script for that:

Ruby script for VUB restaurant
#!/usr/bin/env ruby

require 'bundler/setup'

require "rubygems"
require "net/http"
require "pp"
require "time"
require "cgi"
require "dbus"

require "json"

VUB_RESTO_URL = URI("https://call-cc.be/files/vub-resto/etterbeek.en.json")

TUSSENFIX = "\n"

EMOJI = {
  "Soup" => "🥣",
  "Soep" => "🥣",
  "Menu 1" => "🍲",
  "Menu 2" => "🍳",
  "Veggie" => "🥗",
  "Fish" => "🐟",
  "Vis" => "🐟",
  "Pasta" => "🍝",
  "Wok" => "🥢",
}
EMOJI.default = "🥙"

def get_JSON()
  res = nil
  uri = URI(VUB_RESTO_URL)

  Net::HTTP.start(uri.host, uri.port,
                  :use_ssl => uri.scheme == "https") do |http|
    request = Net::HTTP::Get.new uri.request_uri

    res = http.request request
    return res.body
  end
end

def postit(data, location)
  vandaag = Date.today
  dagstr = vandaag.strftime("%F")
  noon = DateTime.new(vandaag.year, vandaag.month, vandaag.day, 12, 0, 0, Time.now.getlocal.zone)
  parsed_data = JSON.parse(data)

  rockwork_svc = DBus.session_bus["org.rockwork"]
  mgr = rockwork_svc["/org/rockwork/Manager"]
  mgr = mgr["org.rockwork.Manager"]

  pebbles = mgr.ListWatches()
  pebbles.map! { |pebble_name|
    pebble = rockwork_svc[pebble_name]
    pebble["org.rockwork.Pebble"]
  }

  parsed_data.each do |node|
    next unless node["date"] == dagstr
    lines = []
    headings = []
    paragraphs = []

    items = node["menus"]
    until items.empty?
      dish = items.shift

      headings.push(dish["name"])
      paragraphs.push(dish["dish"])
      line = "#{EMOJI[dish["name"]]} #{dish["name"]}: #{dish["dish"]}"
      lines.push(line)
    end

    pin = {
      id: "vub-resto-" + dagstr,
      time: noon.iso8601,
      duration: 60, # 1h
      layout: {
        type: "genericPin",
        title: "Resto menu",
        body: lines.join(TUSSENFIX),
        lastUpdated: DateTime.now.iso8601,
        tinyIcon: "system://images/DINNER_RESERVATION",
        headings: headings,
        paragraphs: paragraphs,
      }
    }
    puts pin
    puts JSON.generate(pin)
    pebbles.each do |pebble|
      pebble.insertTimelinePin(JSON.generate(pin))
    end

    return
  end
end

if ENV["VUBFOOD_LOCATION"].nil?
  warn "location not set, assume etterbeek"
  location = :etterbeek
elsif ENV["VUBFOOD_LOCATION"].downcase == "etterbeek"
  location = :etterbeek
elsif ENV["VUBFOOD_LOCATION"].downcase == "jette"
  location = :jette
end

postit(get_JSON(), location)

If you want to test it, you need Ruby and gem install ruby-dbus.


Sadly, the headings and paragraphs that I generate don't show up:

image

Talking on Rebble's Discord, someone tested out the produced JSON (assumingly on Android/iOS), and got it working for them:

image


I've been skimming the source code a bit, tracing the flow of the json from DBus into libpebble, and it seems like it should pass through perfectly. Do you have an idea what's happening here? I see that meetings should also have headings, but I didn't see them show up ever either (not that I ever paid attention...)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions