Last active
March 16, 2016 06:43
-
-
Save toshinarin/a89b27bedb847995be9a to your computer and use it in GitHub Desktop.
BitBar plugin for check unread count of ChatWork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
# <bitbar.title>ChatWork unread count check</bitbar.title> | |
# <bitbar.version>v1.0</bitbar.version> | |
# <bitbar.author>toshinarin</bitbar.author> | |
# <bitbar.author.github>toshinarin</bitbar.author.github> | |
# <bitbar.desc>This plugin displays my unread count of ChatWork.</bitbar.desc> | |
# <bitbar.image>https://www.chatwork.com/imagenew/all/common/logo/img_logo_chatwork.svg?1458088542</bitbar.image> | |
# <bitbar.dependencies>python</bitbar.dependencies> | |
# Based on Travis Check by Chris Tomkins-Tinch and CircleCI Check by Florent Segouin | |
# github.com/tomkinsc | |
# github.com/matryer/bitbar-plugins/tree/master/Dev/CircleCI | |
import requests | |
# You need to set your API_TOKEN with an API Token from ChatWork. | |
API_TOKEN = '' | |
API_ENDPOINT = 'https://api.chatwork.com/v1' | |
def request(path): | |
url = API_ENDPOINT + path | |
headers = {'X-ChatWorkToken': API_TOKEN} | |
r = requests.get(url, headers=headers) | |
return r.json() | |
def get_resource(resource_name): | |
return request(resource_name) | |
def get_my_status(): | |
# unread_num, mytask_room_num, unread_room_num, mytask_num, mention_room_num, mention_num | |
return get_resource('/my/status') | |
def print_unread_count(): | |
status = get_my_status() | |
print("mention: {mention_num}, unread: {unread_num}, unread room: {unread_room_num}".format(**status)) | |
if __name__ == '__main__': | |
if len(API_TOKEN) == 0: | |
raise ValueError("token can not be empty") | |
print_unread_count() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment