Last active
December 19, 2015 02:48
-
-
Save esehara/5885110 to your computer and use it in GitHub Desktop.
HatenaBookmark Polling
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
# -*- coding: utf-8 -*- | |
import os | |
import sys | |
import urllib | |
import time | |
import datetime | |
def loop(): | |
url = sys.argv[1].replace('http://', 'http://b.hatena.ne.jp/entry/') | |
print "Polling -> ", url | |
while 1: | |
html = urllib.urlopen(url).read().decode('utf-8') | |
if html.find(u'このページはまだブックマークされていません。') == -1: | |
title = "対象のページはブックマークされました。" | |
os.system('notify-send -u critical "%s"' % title) | |
sys.exit(0) | |
title = "まだブックマークされていないようです。" | |
popup = "[%s]<br />" % (datetime.datetime.now().isoformat()) | |
popup += "5分後にもう一度再試行します。" | |
os.system('notify-send -u low "%s" "%s"' % (title, popup)) | |
time.sleep(300) | |
def command(): | |
if len(sys.argv) == 1: | |
print "usage: poll.py (url)" | |
sys.exit(1) | |
loop() | |
if __name__ == '__main__': | |
command() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment