Browse Source

modified: btc-ticker
modified: mmgen/node_tools/Util.py

philemon 8 years ago
parent
commit
bdd008f013
2 changed files with 11 additions and 4 deletions
  1. 6 3
      btc-ticker
  2. 5 1
      mmgen/node_tools/Util.py

+ 6 - 3
btc-ticker

@@ -67,7 +67,7 @@ def update_fx(a,b,debug=False):
 	if debug:
 	if debug:
 		with open('/tmp/ticker.out') as f: text = f.read()
 		with open('/tmp/ticker.out') as f: text = f.read()
 	else:
 	else:
-		text = get_url('{}/q?s={}{}'.format(fx_host,a,b),gzip_ok=True,proxy=proxy)
+		text = get_url('{}/q?s={}{}'.format(fx_host,a,b),gzip_ok=True,proxy=proxy,debug=debug_curl)
 	if not text: return False
 	if not text: return False
 	import re
 	import re
 	ret = re.split('yfs_l10_{}{}=.+?>'.format(a,b),text,maxsplit=1)[1].split('<',1)[0][:10]
 	ret = re.split('yfs_l10_{}{}=.+?>'.format(a,b),text,maxsplit=1)[1].split('<',1)[0][:10]
@@ -140,6 +140,7 @@ opts_data = {
 -a, --alarm-clock-only   Disable ticker, use as alarm clock only
 -a, --alarm-clock-only   Disable ticker, use as alarm clock only
 -c, --cur-ticker-only    Display only current exchange's ticker price
 -c, --cur-ticker-only    Display only current exchange's ticker price
 -d, --debug              Debug mode.  Use saved HTTP data from files
 -d, --debug              Debug mode.  Use saved HTTP data from files
+-D, --debug-curl         Debug curl
 -l, --log=             l Log all data to file '{lf}' at levels 'l' (comma-separated: {lls})
 -l, --log=             l Log all data to file '{lf}' at levels 'l' (comma-separated: {lls})
 -n, --num-digits=      n Display 'n' number of big digits
 -n, --num-digits=      n Display 'n' number of big digits
 -p, --poll-intervals=i1[,i2] Poll servers every 'i' seconds (default: '{pi}')
 -p, --poll-intervals=i1[,i2] Poll servers every 'i' seconds (default: '{pi}')
@@ -183,6 +184,9 @@ CONFIGURED EXCHANGES:
 
 
 opts,args = Opts.parse_opts(sys.argv,opts_data)[:2]
 opts,args = Opts.parse_opts(sys.argv,opts_data)[:2]
 
 
+debug_curl = 'debug_curl' in opts
+proxy = opts['proxy'] if 'proxy' in opts else None
+
 # Global var: the currently displayed exchange
 # Global var: the currently displayed exchange
 if 'alarm_clock_only' in opts:
 if 'alarm_clock_only' in opts:
 	num_digits = 4
 	num_digits = 4
@@ -199,7 +203,6 @@ else:
 			msg('OK')
 			msg('OK')
 		else:
 		else:
 			die_pause(1,'Unable to get {}/{} exchange rate'.format(a.upper(),b.upper()))
 			die_pause(1,'Unable to get {}/{} exchange rate'.format(a.upper(),b.upper()))
-	if 'proxy' in opts: proxy = opts['proxy']
 
 
 	if 'xchgs' in opts:
 	if 'xchgs' in opts:
 		usr_xchgs = [int(i)-1 for i in opts['xchgs'].split(',')]
 		usr_xchgs = [int(i)-1 for i in opts['xchgs'].split(',')]
@@ -561,7 +564,7 @@ def get_market_data(g,d,connfail_msg='full'):
 
 
 	while True:
 	while True:
 		try:
 		try:
-			text = get_url(d.url,proxy=proxy)
+			text = get_url(d.url,proxy=proxy,debug=debug_curl)
 			log(2,g,d.desc,text)
 			log(2,g,d.desc,text)
 			return eval(text)
 			return eval(text)
 		except KeyboardInterrupt:
 		except KeyboardInterrupt:

+ 5 - 1
mmgen/node_tools/Util.py

@@ -40,7 +40,11 @@ def do_system(cmd,testing=False,shell=False):
 	else:
 	else:
 		return subprocess.call((cmd if shell else cmd.split()),shell,stderr=subprocess.PIPE)
 		return subprocess.call((cmd if shell else cmd.split()),shell,stderr=subprocess.PIPE)
 
 
-def get_url(url,gzip_ok=False,proxy=None,timeout=60,verbose=False):
+def get_url(url,gzip_ok=False,proxy=None,timeout=60,verbose=False,debug=False):
+	if debug:
+		print 'get_url():'
+		print '  url', url
+		print '  gzip_ok:',gzip_ok, 'proxy:',proxy, 'timeout:',timeout, 'verbose:',verbose
 	import pycurl,cStringIO
 	import pycurl,cStringIO
 	c = pycurl.Curl()
 	c = pycurl.Curl()
 	c_out = cStringIO.StringIO()
 	c_out = cStringIO.StringIO()