コード例 #1
0
def notify_pebble(pk_user, pk_planner):
    user = User.objects.get(pk=pk_user)
    token = user.profile.timeline_token
    planner = Planner.objects.get(pk=pk_planner)
    
    # send pin
    timeline = Timeline()

    my_pin = dict(
        id='hikeit-' + str(planner.pk),
        time=planner.hiking_time.isoformat(),
        layout=dict(
            type="genericPin",
            title="HikeIt: Upcoming Hike",
            body="Get ready for your hike of " + planner.trail.name + "! Prepare well, and have an excellent trip!",
            tinyIcon="system://images/NOTIFICATION_REMINDER",
        )
    )

    timeline.send_user_pin(
        user_token=token,
        pin=my_pin,
    )
コード例 #2
0
import urllib3.contrib.pyopenssl

urllib3.contrib.pyopenssl.inject_into_urllib3()

# Sandbox key: SBna3itxdgseq99nbw87kur33gi1q4yi
#
#
my_api_key = "SBna3itxdgseq99nbw87kur33gi1q4yi"

user_key = "SBACTtnBhLD2Pig05GxWaT2FqvpwC0i2"

# Python debugger
#import pdb; pdb.set_trace()

timeline = Timeline(my_api_key, "https://timeline-api.getpebble.com")

layout = {
    'type': 'genericPin',
    'title': 'Example Pin',
    'tinyIcon': 'system://images/SCHEDULED_EVENT'
}

notify = {'layout': layout}

## no notifications?  NB update needs a time
#my_pin = Pin(id='123', time = '2015-07-11T23:24:00.000Z', layout = layout, updateNotification = notify)
# works
#my_pin = Pin(id='123', time = '2015-07-11T23:25:00.000Z', layout = layout, createNotification = notify)
#my_pin = Pin(id='123', time = datetime.utcnow().isoformat()+'Z', layout = layout, createNotification = notify)
コード例 #3
0
ファイル: timeline.py プロジェクト: obitoo/PebbleTidesUK
 def __init__ (self, my_api_key):
    self.timeline = Timeline(my_api_key, "https://timeline-api.getpebble.com")
コード例 #4
0
 def __init__(self, my_api_key):
     self.timeline = Timeline(my_api_key,
                              "https://timeline-api.getpebble.com")
コード例 #5
0
ファイル: timeline.py プロジェクト: obitoo/PebbleTidesUK
class myTimeline(object):

   def __init__ (self, my_api_key):
      self.timeline = Timeline(my_api_key, "https://timeline-api.getpebble.com")
   
   
   # TODO - actions
   def send_user_pin (self, user_key, hi_lo_string, date_time, height, portname):
       # add the T eg '2015-07-15 21:17:53.217456Z' to '2015-07-15T21:17:53.217456Z'
       date_time=date_time.replace (" ","T",1)

       layout={
           "type": "weatherPin"
          ,"title": hi_lo_string
          ,"subtitle": height
          ,"tinyIcon": "system://images/TIDE_IS_HIGH"
          ,"largeIcon": "system://images/TIDE_IS_HIGH"
          ,"locationName": portname
          ,"lastUpdated": datetime.utcnow().isoformat()+'Z'
         }
#       actions =  '[ { "title": "Open Cuntface!", "type": "openWatchApp" }]'

       pin_id = self.next_pin_id()
       my_pin = Pin(id=pin_id, time = date_time, layout = layout)#, actions = actions)

       result=self.timeline.send_user_pin(user_key, my_pin)

       return result



   # TODO - actions
   def send_shared_pin (self, port_id,  hi_lo_string, date_time, height, portname, utc_offset):



       if (hi_lo_string == "hi"):
          high_low = "High Tide"
       if (hi_lo_string == "lo"):
          high_low = "Low Tide"

       # topic: hi_0110_-60
       topic = hi_lo_string + "_" + port_id + "_" + str(utc_offset)

       # construct id as: topic/ day of month/ hh / mm
       pin_id = topic + ":"+ date_time.strftime("%d_%m_%y__%H_%M")
       print "pin_id=",pin_id

       # format date as a string, add Z
       # add the T eg '2015-07-15 21:17:53.217456Z' to '2015-07-15T21:17:53.217456Z'
       date_time=str(date_time).replace (" ","T",1) + 'Z'

       layout={
           "type": "weatherPin"
          ,"title": high_low
          ,"subtitle": height
          ,"tinyIcon" : "system://images/RESULT_FAILED"#TIDE_IS_HIGH"
          ,"largeIcon": "system://images/RESULT_FAILED"#TIDE_IS_HIGH"
          ,"locationName": portname
          ,"lastUpdated": datetime.utcnow().isoformat()+'Z'  # aha - isformat is the T
         }
       actions =  '[ { "title": "Open Watchface!", "type": "openWatchApp" }]'


       my_pin = Pin(id=pin_id, time = date_time, layout = layout, actions = actions)


       # make request
       result=self.timeline.send_shared_pin([topic], my_pin)
       print "Sent to topic: ",topic

       return result


   # TODO - lame, do in sql
   def next_pin_id (self):
      filename="/var/www/tides/pin_id.txt"
      with open(filename, "r+") as f:
         data = f.read()
         data = int(data) + 1
         f.seek(0)
         f.write(str(data))
      return str (data -1)
コード例 #6
0
ファイル: test_timeline.py プロジェクト: obitoo/PebbleTidesUK
import urllib3.contrib.pyopenssl
urllib3.contrib.pyopenssl.inject_into_urllib3()

# Sandbox key: SBna3itxdgseq99nbw87kur33gi1q4yi
#
#  
my_api_key="SBna3itxdgseq99nbw87kur33gi1q4yi"

user_key="SBACTtnBhLD2Pig05GxWaT2FqvpwC0i2"



# Python debugger
#import pdb; pdb.set_trace()

timeline = Timeline(my_api_key, "https://timeline-api.getpebble.com")

layout={'type' : 'genericPin', 
        'title': 'Example Pin',
        'tinyIcon': 'system://images/SCHEDULED_EVENT'}

notify={ 'layout': layout}

## no notifications?  NB update needs a time
#my_pin = Pin(id='123', time = '2015-07-11T23:24:00.000Z', layout = layout, updateNotification = notify)
# works
#my_pin = Pin(id='123', time = '2015-07-11T23:25:00.000Z', layout = layout, createNotification = notify)
#my_pin = Pin(id='123', time = datetime.utcnow().isoformat()+'Z', layout = layout, createNotification = notify)

# Tides
layout={
コード例 #7
0
class myTimeline(object):
    def __init__(self, my_api_key):
        self.timeline = Timeline(my_api_key,
                                 "https://timeline-api.getpebble.com")

    # TODO - actions
    def send_user_pin(self, user_key, hi_lo_string, date_time, height,
                      portname):
        # add the T eg '2015-07-15 21:17:53.217456Z' to '2015-07-15T21:17:53.217456Z'
        date_time = date_time.replace(" ", "T", 1)

        layout = {
            "type": "weatherPin",
            "title": hi_lo_string,
            "subtitle": height,
            "tinyIcon": "system://images/TIDE_IS_HIGH",
            "largeIcon": "system://images/TIDE_IS_HIGH",
            "locationName": portname,
            "lastUpdated": datetime.utcnow().isoformat() + 'Z'
        }
        #       actions =  '[ { "title": "Open Cuntface!", "type": "openWatchApp" }]'

        pin_id = self.next_pin_id()
        my_pin = Pin(id=pin_id, time=date_time,
                     layout=layout)  #, actions = actions)

        result = self.timeline.send_user_pin(user_key, my_pin)

        return result

    # TODO - actions
    def send_shared_pin(self, port_id, hi_lo_string, date_time, height,
                        portname, utc_offset):

        if (hi_lo_string == "hi"):
            high_low = "High Tide"
        if (hi_lo_string == "lo"):
            high_low = "Low Tide"

        # topic: hi_0110_-60
        topic = hi_lo_string + "_" + port_id + "_" + str(utc_offset)

        # construct id as: topic/ day of month/ hh / mm
        pin_id = topic + ":" + date_time.strftime("%d_%m_%y__%H_%M")
        print "pin_id=", pin_id

        # format date as a string, add Z
        # add the T eg '2015-07-15 21:17:53.217456Z' to '2015-07-15T21:17:53.217456Z'
        date_time = str(date_time).replace(" ", "T", 1) + 'Z'

        layout = {
            "type": "weatherPin",
            "title": high_low,
            "subtitle": height,
            "tinyIcon": "system://images/RESULT_FAILED"  #TIDE_IS_HIGH"
            ,
            "largeIcon": "system://images/RESULT_FAILED"  #TIDE_IS_HIGH"
            ,
            "locationName": portname,
            "lastUpdated":
            datetime.utcnow().isoformat() + 'Z'  # aha - isformat is the T
        }
        actions = '[ { "title": "Open Watchface!", "type": "openWatchApp" }]'

        my_pin = Pin(id=pin_id, time=date_time, layout=layout, actions=actions)

        # make request
        result = self.timeline.send_shared_pin([topic], my_pin)
        print "Sent to topic: ", topic

        return result

    # TODO - lame, do in sql
    def next_pin_id(self):
        filename = "/var/www/tides/pin_id.txt"
        with open(filename, "r+") as f:
            data = f.read()
            data = int(data) + 1
            f.seek(0)
            f.write(str(data))
        return str(data - 1)
コード例 #8
0
ファイル: test_timeline.py プロジェクト: youtux/pypebbleapi
def test_can_set_api_root():
    t = Timeline(api_root=FAKE_API_ROOT)

    assert t._api_root == FAKE_API_ROOT
コード例 #9
0
ファイル: test_timeline.py プロジェクト: youtux/pypebbleapi
def test_can_set_api_key():
    t = Timeline(api_key='TEST_KEY')

    assert t._api_key == 'TEST_KEY'
コード例 #10
0
ファイル: test_timeline.py プロジェクト: youtux/pypebbleapi
def test_sets_default_api_root():
    t = Timeline()

    assert t._api_root == PEBBLE_API_ROOT
コード例 #11
0
ファイル: test_timeline.py プロジェクト: youtux/pypebbleapi
def test_can_create_with_no_opts():
    t = Timeline()

    assert t
コード例 #12
0
ファイル: test_timeline.py プロジェクト: youtux/pypebbleapi
def timeline():
    return Timeline(api_root=FAKE_API_ROOT, api_key=FAKE_API_KEY)