Last active
January 27, 2017 09:04
-
-
Save naosim/354b1e354cebc682c249 to your computer and use it in GitHub Desktop.
チャットワーク用ヘルパー
This file contains hidden or 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
# -*- coding: utf-8 -*- | |
import urllib | |
import urllib2 | |
from datetime import datetime | |
# ------------------------- | |
# チャットワーク関連 | |
# ------------------------- | |
# チャットワークに送信する | |
def post(message, accesskey, roomId): | |
url = "https://api.chatwork.com/v2/rooms/" + roomId + "/messages" | |
headers = { 'X-ChatWorkToken' : accesskey } | |
data = urllib.urlencode({'body' : message.strip().encode("utf-8")}) | |
#proxy if needed | |
#urllib2.install_opener(urllib2.build_opener(urllib2.ProxyHandler({'https': 'your.proxy.com:8080'}))) | |
req = urllib2.Request(url, data, headers) | |
response = urllib2.urlopen(req) | |
the_page = response.read() | |
# チャットワークにinfoを送信する | |
def postInfo(title, message, accesskey, roomId): | |
post(u"[info][title]%s[/title]%s[/info]" % (title.strip(), message.strip()), accesskey, roomId) | |
# ------------------------- | |
# 曜日関連のヘルパー | |
# ------------------------- | |
class DayOfWeek: | |
def _getDay(self): | |
return datetime.now().strftime("%w") | |
def isSunday(self): | |
return self._getDay() == "0" | |
def isMonday(self): | |
return self._getDay() == "1" | |
def isTuesday(self): | |
return self._getDay() == "2" | |
def isWednesday(self): | |
return self._getDay() == "3" | |
def isThursday(self): | |
return self._getDay() == "4" | |
def isFriday(self): | |
return self._getDay() == "5" | |
def isSaturday(self): | |
return self._getDay() == "6" | |
def toJapanese(self): | |
return [u"日", u"月", u"火", u"水", u"木", u"金", u"土"][int(self._getDay())] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment