Created
May 15, 2014 16:48
-
-
Save hibiyasleep/4f0a77c6b21fe8af8b75 to your computer and use it in GitHub Desktop.
Sunrin vs VideoHS Monitor
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
# FILE : naver.py | |
# -*- coding: utf-8 -*- | |
# | |
import urllib2, re, sys | |
from time import time, sleep | |
from StringIO import StringIO | |
from gzip import GzipFile | |
VERSION = '0' | |
header = { | |
"Referer": "m.naver.com", | |
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1944.0 Safari/537.36", | |
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8", | |
"Accept-Encoding": "gzip,deflate,sdch", | |
"Accept-Language": "ko-KR,ko;q=0.8,en-US;q=0.6,en;q=0.4", | |
"Accept-Charset": "utf-8;q=0.7,*;q=0.3" | |
} | |
requestA = urllib2.Request("http://m.search.naver.com/search.naver?sm=mtb_hty.top&where=m&query=선린인터넷고등학교+선생님+고맙습니다", headers=header) | |
requestB = urllib2.Request("http://m.search.naver.com/search.naver?sm=mtb_hty.top&where=m&query=서울영상고등학교+선생님+고맙습니다", headers=header) | |
current = {'a': 0, 'b': 0, 't': time()} | |
def g(request): | |
f = urllib2.urlopen(request) | |
d = f.read() | |
f.close() | |
b = StringIO(d) | |
r = GzipFile(fileobj=b).read() | |
return int(re.search('(\d+)</strong>등', r).group(1)) | |
# screen update | |
try: | |
while 1: | |
before = current | |
current = {'a': g(requestA), 'b': g(requestB), 't': time()} | |
sys.stdout.write("선린 %-6.2freq/s | %-7d vs %7d | %6.2freq/s 영상 \r" % ( | |
(current['a'] - before['a']) / (current['t'] - before['t']), | |
current['a'], | |
current['b'], | |
(current['b'] - before['b']) / (current['t'] - before['t']) | |
)) | |
sys.stdout.flush() | |
sleep(0.2) | |
except KeyboardInterrupt: | |
print "[ " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment