2017-05-26 11:06:20 +02:00
|
|
|
# pylint: disable=C0111,R0903
|
|
|
|
|
2017-05-26 11:11:58 +02:00
|
|
|
"""Displays the unread GitHub notifications for a GitHub user
|
2017-05-26 11:06:20 +02:00
|
|
|
|
|
|
|
Requires the following executable:
|
|
|
|
* curl
|
|
|
|
|
|
|
|
Parameters:
|
|
|
|
* github.token: GitHub user access token
|
|
|
|
* github.interval: Interval in minutes
|
|
|
|
"""
|
|
|
|
|
|
|
|
import bumblebee.input
|
|
|
|
import bumblebee.output
|
|
|
|
import bumblebee.engine
|
|
|
|
import re
|
|
|
|
import time
|
2017-05-26 13:32:47 +02:00
|
|
|
import json
|
|
|
|
|
|
|
|
try:
|
|
|
|
import requests
|
|
|
|
from requests.exceptions import RequestException
|
|
|
|
except ImportError:
|
|
|
|
pass
|
2017-05-26 11:06:20 +02:00
|
|
|
|
|
|
|
class Module(bumblebee.engine.Module):
|
|
|
|
def __init__(self, engine, config):
|
|
|
|
super(Module, self).__init__(engine, config,
|
|
|
|
bumblebee.output.Widget(full_text=self.github)
|
|
|
|
)
|
|
|
|
self._count = 0
|
|
|
|
self._interval = int(self.parameter("interval", "5"))
|
|
|
|
self._nextcheck = 0
|
|
|
|
|
|
|
|
def github(self, widget):
|
2017-05-26 13:32:47 +02:00
|
|
|
return str(self._count)
|
2017-05-26 11:06:20 +02:00
|
|
|
|
|
|
|
def update(self, widgets):
|
|
|
|
if self._nextcheck < int(time.time()):
|
|
|
|
self._nextcheck = int(time.time()) + self._interval * 60
|
|
|
|
token = self.parameter("token", "")
|
|
|
|
|
|
|
|
if not token:
|
|
|
|
self._count = 0
|
|
|
|
return
|
|
|
|
|
2017-05-26 13:32:47 +02:00
|
|
|
notifications = requests.get("https://api.github.com/notifications?access_token={}".format(token)).text
|
|
|
|
unread = 0
|
|
|
|
for notification in json.loads(notifications):
|
|
|
|
if "unread" in notification and notification["unread"] == True:
|
|
|
|
unread += 1
|
|
|
|
self._count = unread
|
2017-05-26 11:06:20 +02:00
|
|
|
|
|
|
|
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4
|