Skip to content

Instantly share code, notes, and snippets.

@esehara
Last active December 19, 2015 02:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esehara/5885110 to your computer and use it in GitHub Desktop.
Save esehara/5885110 to your computer and use it in GitHub Desktop.
HatenaBookmark Polling
# -*- 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