def add_key(gituser, gitpass): """add_key:<githubuser>,<githubpass>. Adds a new key to github. """ run("mkdir -p ~/.ssh") key_file = "id_rsa.git" private_key_file = os.path.join("/tmp/", key_file) public_key_file = "%s.pub" % private_key_file remote_full_key_path = os.path.join("/home", env.user, ".ssh", key_file) ssh.add_ssh_config("github.com", key_file=remote_full_key_path) local("rm -rf %s %s" % (private_key_file, public_key_file)) local("ssh-keygen -t rsa -f %s " % private_key_file) with file(public_key_file, "r") as f: key = f.read() print "====BEGIN PUBLIC KEY=====" print key print "====END PUBLIC KEY=======" data = { 'title' : "key for: %s" % env.host, 'key' : key } client = WebClient("https://api.github.com", verbose=True) client.authenticate(username=gituser, password=gitpass) put(private_key_file, "~/.ssh") run("chmod 600 %s" % remote_full_key_path) client.post("/user/keys", data)
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" dds = DirectionSolver() wcl = WebClient(dds) wcl.run("ws://codenjoy.com:80/codenjoy-contest/ws", 'au')
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" dds = DirectionSolver() wcl = WebClient(dds) wcl.run("ws://tetrisj.jvmhost.net:12270/codenjoy-contest/ws", 'au')
def main(username): assert version_info[0] == 3, "You should run me with Python 3.x" dds = DirectionSolver() wcl = WebClient(dds) wcl.run(_SERVER, username)
def __init__(self): self.app = WinClient self.client = WebClient(8081, pi_address) self.client.set_lock_handler(self.lock_handler) self.client.set_unlock_handler(self.unlock_handler) self.client.start() print('Hello World!')
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" # substitute following link with the one you've copied in your browser after registration url = "https://dojorena.io/codenjoy-contest/board/player/8aq9izxu40h7blnrd3l9?code=6712803793075447834&gameName=bomberman" direction_solver = DirectionSolver() wcl = WebClient(url=get_url_for_ws(url), solver=direction_solver) wcl.run_forever()
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" # paste here board page url from browser after registration # url = f"http://127.0.0.1:8080/codenjoy-contest/board/player/0?code=000000000000" url = f"https://practice.epam-botchallenge.com/codenjoy-contest/board/player/ba0hceicbze6l2mqkmrb?code=5495296893386541378&game=battlecity" direction_solver = DirectionSolver() wcl = WebClient(url=get_url_for_ws(url), solver=direction_solver) wcl.run_forever()
def main(): dds = DirectionSolver() wcl = WebClient(dds) server = 'ws://localhost:8080/codenjoy-contest/ws' user = '******' code = '1351323692637632922' wcl.run(server, user, code)
def test_auth(self): "It support basic http authentication." client = WebClient("http://localhost:3000") client.authenticate(username="******", password="******") response = client.get("test_auth") self.assertEqual(response.data['username'], "Aladdin") self.assertEqual(response.data['password'], "open sesame")
def test_tracker_log_in_url_and_method(self): webclient = WebClient(self.session) mock_acc = Mock(username='******', password='******', userid=12345) webclient.tracker_log_in(mock_acc) formdata = WebClient.login_form_data(mock_acc) self.session.request.assert_called_once_with('POST', 'http://login.rutracker.org/forum/login.php', data=formdata, timeout=TIMEOUTS)
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" # substitute following link with the one # you've copied in your browser after registration url = environ["URL"] direction_solver = DirectionSolver() wcl = WebClient(url=get_url_for_ws(url), solver=direction_solver) wcl.run_forever()
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" # substitute following link with the one you've copied in your browser after registration #url = "http://localhost:8080/codenjoy-contest/board/player/0?code=000000000000" url = "https://epam-botchallenge.com/codenjoy-contest/board/player/v50trdhg80hxed60q7xc?code=331017081544738029" direction_solver = DirectionSolver() wcl = WebClient(url=get_url_for_ws(url), solver=direction_solver) wcl.run_forever()
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" # substitute following link with the one you've copied in your browser after registration url = "http://3.133.109.198:8080//codenjoy-contest/board/player/g2kzb99qhnjs217fkcyy?code=3689161262388400247&gameName=bomberman" direction_solver = DirectionSolver() print(get_url_for_ws(url)) wcl = WebClient(url=get_url_for_ws(url), solver=direction_solver) wcl.run_forever()
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" dds = DirectionSolver() wcl = WebClient(dds) user = '******' code = '0000000000000000000' wcl.run("ws://host:port/codenjoy-contest/ws", user, code)
def __init__(self, host, port=None, path=None): if not port and not path: matches = re.search("http://(\w+)(:\d+)?(.+)", host) host = matches.group(1) port = int(matches.group(2)[1:]) path = matches.group(3) self.host = host self.path = path self.port = port self.webclient = WebClient(host=host, port=port) self.registered_namespaces = {}
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" # you can get this URL after registration on the server with your email url = "http://*****:*****@:%._\+~#=\.]+)\/codenjoy-contest\/board\/player\/([a-z0-9]+)\?code=([0-9]+)") rematch = repattern.match(url) serverandport = rematch.group(1) username = rematch.group(2) usercode = rematch.group(3) dds = MySolver() wcl = WebClient(dds) wcl.run(serverandport, username, usercode)
class WebClientUnitTestRequest(unittest.TestCase): def setUp(self): self.client = WebClient("http://localhost:3000") def test_get_html_status_code(self): "It can issue a GET request and return a status code" response = self.client.get("/") self.assertEquals(200, response.status_code) def test_get_html_content(self): "It can issue a GET request and return the page content" response = self.client.get("/") self.assertEquals("this is text", response.content) def test_get_json(self): "It automatically parses json data." response = self.client.get("data.json") self.assertEquals(response.data['name'], "coca cola") def test_get_data(self): "It passes POST data arguments thru the querystring." data = {"param1": "value1", "param2": "value2"} response = self.client.get("echo_get", data=data) self.assertEqual(response.data, data) def test_post_data_json(self): "It passes json POST data as the request body content." data = {"param1": "value1", "param2": "value2"} response = self.client.post("echo_post_json", data=data, content_type='application/json') self.assertEqual(response.data, data) def test_post_data_multipart(self): "It can POST multipart/form-data" data = {"param1": "value1", "param2": "value2"} response = self.client.post("echo_post_multipart", data=data, content_type='multipart/form-data') self.assertEqual(response.data, data) def test_post_data_multipart_file(self): "It can POST multipart/form-data with attached files" data = {"param1": "value1", "param2": "value2"} files = {"textfile" : "fixtures/test1.txt"} response = self.client.post("echo_post_files", data=data, files=files, content_type='multipart/form-data') data.update({'textfile': 'Awesome\n'}) self.assertEqual(response.data, data)
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" # substitute following link with the one you've copied in your browser after registration url = "http://codenjoy.com:80/codenjoy-contest/board/player/3edq63tw0bq4w4iem7nb?code=12345678901234567890" repattern = re.compile( "^https?://([-a-zA-Z0-9@:%._\+~#=\.]+)/codenjoy-contest/board/player/([a-z0-9]+)\?code=([0-9]+)" ) rematch = repattern.match(url) serverandport = rematch.group(1) username = rematch.group(2) usercode = rematch.group(3) dds = DirectionSolver() wcl = WebClient(dds) wcl.run(serverandport, username, usercode)
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" # you can get this URL after registration on the server with your email url = "http://*****:*****@:%._\+~#=\.]+)/codenjoy-contest/board/player/([a-z0-9]+)\?code=([0-9]+)" ) rematch = repattern.match(url) serverandport = rematch.group(1) username = rematch.group(2) usercode = rematch.group(3) dds = DirectionSolver() wcl = WebClient(dds) wcl.run(serverandport, username, usercode)
def main(): assert version_info[0] == 3, "You should run me with Python 3.x" config_init() if QT_BOARD_SHOW: qt_create_board() # substitute following link with the one you've copied in your browser after registration direction_solver = DirectionSolver() if DEBUG: board_string = "".join("".join(b) for b in BOARDDEBUG) direction_solver.get(board_string) else: url = REMOTE_URL wcl = WebClient(url=get_url_for_ws(url), solver=direction_solver) wcl.run_forever()
class Endpoint(object): def __init__(self, host, port=None, path=None): if not port and not path: matches = re.search("http://(\w+)(:\d+)?(.+)", host) host = matches.group(1) port = int(matches.group(2)[1:]) path = matches.group(3) self.host = host self.path = path self.port = port self.webclient = WebClient(host=host, port=port) self.registered_namespaces = {} def register_namespace(self, prefix, namespace): self.registered_namespaces[prefix] = namespace def get_registered_namespaces_header(self): header_items = [] for prefix, ns in self.registered_namespaces.items(): ns_name = ns.encode() header_items.append('PREFIX %s: <%s>' % (prefix, ns_name)) return '\n'.join(header_items) def get_full_path(self): return "http://%s:%s%s" % (self.host, self.port, self.path) @staticmethod def get_query_path(query, base_path, output): return "%s?query=%s&format=%s" % (base_path, urllib.quote(query), output) def query(self, query, output="ResultSet"): #print ">>%s" % query query = "%s\n%s" % (self.get_registered_namespaces_header(), query) if output == "ResultSet": request_format = "xml" else: request_format = output url = Endpoint.get_query_path(query, self.path, request_format) response = self.webclient.get(url) if output == 'ResultSet': return ResultSet(response.content) elif output == "json": return response.data
def add_key(gituser, gitpass): """add_key:<githubuser>,<githubpass>. Adds a new key to github. """ run("mkdir -p ~/.ssh") key_file = "id_rsa.git" private_key_file = os.path.join("/tmp/", key_file) public_key_file = "%s.pub" % private_key_file remote_full_key_path = os.path.join("/home", env.user, ".ssh", key_file) ssh.add_ssh_config("github.com", key_file=remote_full_key_path) local("rm -rf %s %s" % (private_key_file, public_key_file)) local("ssh-keygen -t rsa -f %s " % private_key_file) with file(public_key_file, "r") as f: key = f.read() print "====BEGIN PUBLIC KEY=====" print key print "====END PUBLIC KEY=======" data = {'title': "key for: %s" % env.host, 'key': key} client = WebClient("https://api.github.com", verbose=True) client.authenticate(username=gituser, password=gitpass) put(private_key_file, "~/.ssh") run("chmod 600 %s" % remote_full_key_path) client.post("/user/keys", data)
class Doorman: """The Windows client side of Doorman.""" def __init__(self): self.app = WinClient self.client = WebClient(8081, pi_address) self.client.set_lock_handler(self.lock_handler) self.client.set_unlock_handler(self.unlock_handler) self.client.start() print('Hello World!') def unlock_handler(self): """Handle request from server to unlock computer.""" print("Unlock requested!") self.app.autounlock() def lock_handler(self): """Handle request to lock computer.""" print("Lock requested!")
def __enrich_data(self, latitude, longitude): webclient = WebClient() address = webclient.get_address_by_latlong(latitude, longitude) return address
print "It would help if you specified what I'm supposed to download :)" print usage(sys.argv[0]) exit() args = sys.argv if args[1] == "fake": print("--> faking download") if not len(args) == 3: print " -> can't fake without a value" exit() components = [Percentage(), Bar(), Remaining()] size = int(args[2]) bar = ProgressBar(components, size) for n in range(100, size + 1, 50): bar.update(n) time.sleep(0.005) bar.render() print "--> done" exit() url = sys.argv[1] client = WebClient(ProgressBarFactory()) try: client.get(url) except KeyboardInterrupt: print "\nUser canceled download"
def __init__(self, timelapseClient): WebClient.__init__(self) self.timelapseClient = timelapseClient self.currentWeatherData = []
def setUp(self): self.client = WebClient("http://localhost:3000")
def test_get_torrent_page_url_and_method(self): webclient = WebClient(self.session) webclient.get_torrent_page(1) self.session.request.assert_called_once_with('GET', 'http://rutracker.org/forum/viewtopic.php?t=1', timeout=TIMEOUTS)
print(usage(sys.argv[0])) exit(0) args = sys.argv if args[1] == "fake": print("--> faking download") if not len(args) == 3: print(" -> can't fake without a value") exit() components = [ [Label("some.file"), Remaining(), Speed(), Bar(), Percentage()], ] for c in components: run_download(c, int(args[2])) exit() url = sys.argv[1] client = WebClient(ProgressBarFactory()) try: client.get(url) except KeyboardInterrupt: print("\nUser canceled download")
def test_get_torrent_page(self): webclient = WebClient(self.session) html = webclient.get_torrent_page(669606) self.assertIn(html, '669606')