def getBehavior(): global __current_behavior__ response = httpclient.get(api.__get_behavior__(node.node_info['behaviorId']), auth.checkResponse) if response.status == 200: #print response.body __current_behavior__ = json.loads(response.body) return __current_behavior__
def getBehavior(): global __current_behavior__ response = httpclient.get( api.__get_behavior__(node.node_info['behaviorId']), auth.checkResponse) if response.status == 200: #print response.body __current_behavior__ = json.loads(response.body) return __current_behavior__
def get_all_activity_ids(self): """Gets all activity IDs for the current user""" profile_url = "http://runkeeper.com/user/%s" % self.user_name user_profile = httpclient.get(profile_url) soup = BeautifulSoup(user_profile) activities = soup.findAll(id=re.compile('^trip')) activity_ids = [] for activity in activities: activity_ids.append(activity['id'][5:]) return activity_ids
def doActions(): try: log.current_state = "Getting light and water info from server" response = httpclient.get(api.__get_lightwater__(node.node_info['id']), auth.checkResponse) scn.update(server_resp="{} {}".format(response.status, response.reason)) log.current_state = "Deserializing light and water info from server" _node = json.loads(response.body) log.current_state = "Setting light pin" sys_gpio.setRelay(sys_gpio.__light_pin__, _node['lightOn']) log.current_state = "Setting water pin" sys_gpio.setRelay(sys_gpio.__water_pin__, _node['waterOn']) except TimeoutError: error_msg = "HTTP Timeout - main.py @ doActions()" #print error_msg, "\n" scn.update(last_error="Get Water and Light - at " + datetime.now().isoformat()) log.log_error(error_msg) return return
def updateNode(nextRun): if datetime.now() >= nextRun: #print 'Start updating the node...' log.current_state = "Getting node info from server" scn.update(node_updating="Updating node info [Calling Server]") response = httpclient.get(api.__get_node__(node.node_info['id']), auth.checkResponse) scn.update(server_resp="{} {}".format(response.status, response.reason)) log.current_state = "Deserializing node info" body = json.loads(response.body) log.current_state = "Updating node info" scn.update(node_updating="Updating node info [Saving Info]") node.update(body) scn.update(node_updating="Last update at " + datetime.now().isoformat()) nextRun = datetime.now() + timedelta(seconds=60) #print 'Node update finised\n' return nextRun
def find_lan_device(keyword,scope='guid',findall=False): my_ip = socket.gethostbyname(socket.gethostname()) my_ip_abc = re.sub(r'\d+$','',my_ip) rtns = {} for d in xrange(1,256): dest_addr = "%s%d" % (my_ip_abc,d) list_url = "http://%s:%d/list" % (dest_addr,HIS_HOSTHUB_ROOT_PORT) resp = httpclient.get(list_url,timeout=1) if resp != '': resp = json.loads(resp) data = resp.get('data') if data is not None and type(data) == type({}): if scope == 'guid': if keyword in data.keys(): guid = keyword rtn = lan_device() rtn.address = dest_addr rtn.port = data[guid]['port'] if findall: rtns[guid] = rtn else: return rtn else: pass else: for guid in data.keys(): obj = data[guid] if obj.get(scope,'') == keyword: rtn = lan_device() rtn.address = dest_addr rtn.port = data[guid]['port'] if findall: rtns[guid] = rtn else: return rtn else: pass else: pass
def _get_activity_type(self): activity_url = "http://runkeeper.com/ui/activityHeader/%s" % self.activity_id activity_header = httpclient.get(activity_url) if activity_header.find('Running'): activity_type = 'Running' elif activity_header.find('Cycling'): activity_type = 'Cycling' elif activity_header.find('Mountain Biking'): activity_type = 'Mountain Biking' elif activity_header.find('Walking'): activity_type = 'Walking' elif activity_header.find('Hiking'): activity_type = 'Hiking' elif activity_header.find('Downhill Skiing'): activity_type = 'Downhill Skiiing' elif activity_header.find('Cross-Country Skiing'): activity_type = 'Cross-Country Skiiing' elif activity_header.find('Snowboarding'): activity_type = 'Snoboarding' elif activity_header.find('Skating'): activity_type = 'Skating' elif activity_header.find('Swimming'): activity_type = 'Swimming' elif activity_header.find('Wheelchair'): activity_type = 'Wheelchair' elif activity_header.find('Rowing'): activity_type = 'Rowing' elif activity_header.find('Elliptical'): activity_type = 'Elliptical' elif activity_header.find('Other'): activity_type = 'Other' else: activity_type = 'Unknown' return activity_type
def run(handler_class=handle,run_port=None,is_hosthub=False): #app = QCoreApplication(sys.argv) parser = argparse.ArgumentParser(prog='HTTP_SERVER') parser.add_argument('-g', '--guid',default='',type=str) parser.add_argument('-t', '--tag',default=handler_class.tag,type=str) parser.add_argument('-s', '--storage',default='',type=str) parser.add_argument('-l', '--log',default='',type=str) result = parser.parse_args() guid = result.guid if guid == '': print_error("-guid must be specified") exit(1) run_port = None if is_hosthub == False: #connect to hub resp = '' while resp == '': resp = httpclient.get('http://127.0.0.1:%d/add?guid=%s' % (HIS_HOSTHUB_ROOT_PORT,guid)) time.sleep(5) hub_result = json.loads(resp) run_port = hub_result.get('data',0) if run_port == 0: print_error("Failed to register to hub") exit(1) else: result.storage = hub_result.get('storage','') result.log = hub_result.get('log_file','') os.environ['HIS_LOG_FILE'] = result.log os.environ['HIS_STORAGE'] = result.storage print_info("Connected to hub") else: run_port = HIS_HOSTHUB_ROOT_PORT if result.storage == '': print_error("Failed to locate storage path, run with -s or check the hub") exit(1) if result.log == '': result.log = result.storage + '/var/log/' if is_hosthub: try: os.makedirs(result.log) os.makedirs(result.storage) except: pass os.environ['HIS_LOG_FILE'] = result.log + '/' + guid + '.log' handler_class.storage_path = result.storage handler_class.log_path = result.log os.environ['HIS_APP_GUID'] = guid print_info("Start Server at port %d with tag '%s'" % (run_port,result.tag)) server_address = ('', run_port) handler_class.tag = result.tag httpd = BaseHTTPServer.HTTPServer(server_address, handler_class) httpd.serve_forever()
q_dist[_k] = q.get(_k)[0] q_dist['appId'] = appid q_dist['idfa'] = payload['idfa'] q_dist['ipv4'] = payload['ipv4'] qs_dist = urlencode(q_dist) u_dist = (u.scheme, u.netloc, u.path, '', qs_dist, '') url = urlunparse(u_dist) print('request to: %s' % url) from httpclient import get, post resp = get('http://127.0.0.1:4567/') logging.debug(resp.code) logging.debug(resp.message) logging.debug(resp.body) resp = post('http://127.0.0.1:4567/post', data={'a': 1, 'b': 2}) logging.debug(resp.code) logging.debug(resp.message) logging.debug(resp.body) resp = post('http://127.0.0.1:4567/post', data=open('/tmp/a', 'rb')) logging.debug(resp.code) logging.debug(resp.message) logging.debug(resp.body)
def _get_activity_data(self): activity_url = "http://runkeeper.com/ajax/activityInfo?tripId=%s" % self.activity_id activity_info = httpclient.get(activity_url) activity_info = json.loads(activity_info); return activity_info['points']
import xrdpclient import httpclient url="http://localhost:9090/xrdp" #url="http://xrdpdemo.appspot.com/xrdp" acct="charlie" link={"rel": "http://oexchange.org/spec/0.8/rel/user-target", "type": "application/xrd+xml", "href": "http://oexchange.org/demo/linkeater/oexchange.xrd"} newlink=link.copy(); newlink["rel"] = "newrel" # get print "--GET: fetching xrd" print httpclient.get(url, params={"acct":"charlie"}) # POST/create print "--POST: adding a new link" #print xrdpclient.add(url, acct, link) print xrdpclient.add(url, acct, newlink) ## PUT/update #print "--PUT: updating the link" #print xrdpclient.update(url, acct, link, newlink) # ## DELETE/remove #print "--DELETE: removing the link" #print xrdpclient.delete(url, acct, newlink)