make default user-agent include git revision
This commit is contained in:
parent
154f457f3a
commit
b82372a76c
|
@ -3,11 +3,22 @@ import socket
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from util import hook
|
from util import hook, http
|
||||||
|
|
||||||
socket.setdefaulttimeout(10) # global setting
|
socket.setdefaulttimeout(10) # global setting
|
||||||
|
|
||||||
|
|
||||||
|
def get_version():
|
||||||
|
p = subprocess.Popen(['git', 'log', '--oneline'], stdout=subprocess.PIPE)
|
||||||
|
stdout, _ = p.communicate()
|
||||||
|
p.wait()
|
||||||
|
|
||||||
|
revnumber = len(stdout.splitlines())
|
||||||
|
|
||||||
|
ret = stdout.split(None, 1)[0]
|
||||||
|
|
||||||
|
return ret, revnumber
|
||||||
|
|
||||||
#autorejoin channels
|
#autorejoin channels
|
||||||
@hook.event('KICK')
|
@hook.event('KICK')
|
||||||
def rejoin(paraml, conn=None):
|
def rejoin(paraml, conn=None):
|
||||||
|
@ -42,16 +53,13 @@ def onjoin(paraml, conn=None):
|
||||||
conn.join(channel)
|
conn.join(channel)
|
||||||
time.sleep(1) # don't flood JOINs
|
time.sleep(1) # don't flood JOINs
|
||||||
|
|
||||||
|
# set user-agent
|
||||||
|
ident, rev = get_version()
|
||||||
|
http.ua_skybot = 'Skybot/r%d %s http://github.com/rmmh/skybot' % (rev, ident)
|
||||||
|
|
||||||
@hook.regex(r'^\x01VERSION\x01$')
|
@hook.regex(r'^\x01VERSION\x01$')
|
||||||
def version(inp, notice=None):
|
def version(inp, notice=None):
|
||||||
p = subprocess.Popen(['git', 'log', '--oneline'], stdout=subprocess.PIPE)
|
ident, rev = get_version()
|
||||||
stdout, _ = p.communicate()
|
|
||||||
p.wait()
|
|
||||||
|
|
||||||
revnumber = len(stdout.splitlines())
|
|
||||||
|
|
||||||
ret = stdout.split(None, 1)[0]
|
|
||||||
|
|
||||||
notice('\x01VERSION skybot %s r%d - http://github.com/rmmh/'
|
notice('\x01VERSION skybot %s r%d - http://github.com/rmmh/'
|
||||||
'skybot/\x01' % (ret, revnumber))
|
'skybot/\x01' % (ident, rev))
|
||||||
|
http.ua_skybot = 'Skybot/r%d %s http://github.com/rmmh/skybot' % (rev, ident)
|
||||||
|
|
|
@ -12,7 +12,7 @@ from urllib2 import HTTPError, URLError
|
||||||
from lxml import etree, html
|
from lxml import etree, html
|
||||||
|
|
||||||
|
|
||||||
user_agent = 'Skybot/1.0 http://github.com/rmmh/skybot'
|
ua_skybot = 'Skybot/1.0 http://github.com/rmmh/skybot'
|
||||||
|
|
||||||
ua_firefox = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) ' \
|
ua_firefox = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) ' \
|
||||||
'Gecko/20070725 Firefox/2.0.0.6'
|
'Gecko/20070725 Firefox/2.0.0.6'
|
||||||
|
@ -37,12 +37,15 @@ def get_json(*args, **kwargs):
|
||||||
return json.loads(get(*args, **kwargs))
|
return json.loads(get(*args, **kwargs))
|
||||||
|
|
||||||
|
|
||||||
def open(url, query_params=None, user_agent=user_agent, post_data=None,
|
def open(url, query_params=None, user_agent=None, post_data=None,
|
||||||
get_method=None, cookies=False, **kwargs):
|
get_method=None, cookies=False, **kwargs):
|
||||||
|
|
||||||
if query_params is None:
|
if query_params is None:
|
||||||
query_params = {}
|
query_params = {}
|
||||||
|
|
||||||
|
if user_agent is None:
|
||||||
|
user_agent = ua_skybot
|
||||||
|
|
||||||
query_params.update(kwargs)
|
query_params.update(kwargs)
|
||||||
|
|
||||||
url = prepare_url(url, query_params)
|
url = prepare_url(url, query_params)
|
||||||
|
|
Loading…
Reference in New Issue