Beispiel #1
0
 def test_http_err_check(self):
     r = HttpHelper.get('http://127.0.0.1:8008/tests/index.html',
                        err_check=lambda x: True)
     assert r == None
     r = HttpHelper.get('http://127.0.0.1:8008/tests/index.html',
                        err_check=lambda x: False)
     assert r.text == 'Hello\n'
Beispiel #2
0
 def get_price():
     r = HttpHelper.get(API, err_check=err_check, params=params)
     if r:
         result = r.json()
         return result[c2]
     else:
         return -1
Beispiel #3
0
def get_report_hashrate(config):
    url = config['API_BASE'] + config['ACCOUNT']
    r = HttpHelper.get(url, err_check = err_check)
    if r:
        result = r.json()
        return result['data']
    return -1
Beispiel #4
0
 def get_price():
     r = HttpHelper.get(url, err_check = err_check)
     if r:
         result = r.json()
         return result['last']
     else:
         return -1
Beispiel #5
0
 def get_price():
     r = HttpHelper.get(API, err_check = err_check, params = params)
     if r:
         result = r.json()['result']
         price_total = len(result)
         if price_total > 1:
             return (result[price_total - 1]['cnyPrice'] + result[price_total - 2]['cnyPrice'])/2
         else:
             return result[0]['cnyPrice']
     else:
         return -1
Beispiel #6
0
 def push(self, msg):
     params = {
         'sendkey': self.config['KEY'],
         'text': self.config['TITLE'],
         'desp': str(msg)
     }
     r = HttpHelper.get(self.config['API_BASE'],
                        err_check=self.err_check,
                        params=params)
     if r == None:
         return False
     return True
Beispiel #7
0
 def test_http_404(self):
     r = HttpHelper.get('http://127.0.0.1:8008/invalid')
     assert r == None
Beispiel #8
0
 def test_http_200(self):
     r = HttpHelper.get('http://127.0.0.1:8008/tests/index.html')
     assert r.text == 'Hello\n'
Beispiel #9
0
def hourly_notify(config):
    url = config['API_BASE'] + config['ACCOUNT']
    r = HttpHelper.get(url, err_check=err_check)
    if r:
        res = r.json()
        return Message(build_msg(res['data']))