Пример #1
0
    def do_get(self, arg):
        # print  arg
        print(" ------ httpc [" + str(self.id) + "] sent a get request ------")
        # print arg
        args = arg.split(' ')
        is_v = False
        o_path = ''
        headers = {}
        url = eval(args[-1])

        if '-v' in args:
            is_v = True

        if '-o' in args:
            o_index = args.index('-o')
            o_path = args[o_index + 1]

        if '-h' in args:
            h_index = 0
            for i in args:
                if i == '-h':
                    header = args[h_index + 1].split(':')
                    headers[header[0]] = header[1]
                h_index += 1

        httplib.get(url, headers, is_v, o_path)
        print(" ------ httpc [" + str(self.id) + "] end the get request ------")
Пример #2
0
	def execute(self, args):

		nickname = args[0]

		response = httplib.get('http://codeforces.com/api/user.info', params={'handles':nickname})

		userinfo = json.loads(response)

		#voot

		if(userinfo["status"] == 'FAILED'):
			print('Fail: {}'.format(userinfo['comment']))
			return

		rating = userinfo["result"][0]['rating']
		
		print('Current rating is: {}'.format(rating))

		x = input("Wait for changes in rating?(y/n)")

		if(x == 'n'):
			return

		while True:
			r = httplib.get('http://codeforces.com/api/user.info', params={'handles':nickname})

			d = r.text[r.find('"rating"'):r.find('"maxRank"')-1]
			d = int(d[d.find(':')+1:])

			if rating != d:
				print('Rank changed to {}'.format(d))
				os.system('play --no-show-progress --null --channels 1 synth %s sine %f' % ( 1, 300))
				break

			time.sleep(5)
Пример #3
0
    def do_get(self, arg):
        arguments = arg.split(' ')
        url = eval(arguments[-1])

        # -v Prints the detail of the response such as protocol, status,and headers.
        is_v = False
        if '-v' in arguments:
            is_v = True

        # bonus -o.

        o_filepath = ''
        if '-o' in arguments:
            o_index = arguments.index('-o')
            o_filepath = arguments[o_index + 1]

        # -h key:value Associates headers to HTTP Request with the format'key:value'.
        headers = {}
        if '-h' in arguments:
            h_index = 0
            for i in arguments:
                if i == '-h':
                    header = arguments[h_index + 1].split(':')
                    headers[header[0]] = header[1]
                h_index += 1

        httplib.get(url, headers, is_v, o_filepath)
Пример #4
0
    def execute(self, args):
        response = httplib.get('http://codeforces.com/api/contest.list', params={'gym' : 'false'})

        contests = json.loads(response)['result']
        for contest in contests:
            if contest['phase'] == 'BEFORE':
                print(contest['name'])
                print(datetime.datetime.fromtimestamp(int(contest['startTimeSeconds'])).strftime('%d-%m-%Y %H:%M:%S'))
Пример #5
0
def parse_get(args):
    """Parses the arguments from the command line in order to make a GET request"""
    url = args.url
    verbose = args.verbose
    udp = args.udp
    if args.headers:
        headers = dict(kv.split(":") for kv in args.headers)
    else:
        headers = None
    res = httplib.get(url, headers, verbose, udp)
Пример #6
0
    def execute(self, args):
        response = httplib.get('http://codeforces.com/api/contest.list',
                               params={'gym': 'false'})

        contests = json.loads(response)['result']
        for contest in contests:
            if contest['phase'] == 'BEFORE':
                print(contest['name'])
                print(
                    datetime.datetime.fromtimestamp(
                        int(contest['startTimeSeconds'])).strftime(
                            '%d-%m-%Y %H:%M:%S'))
Пример #7
0
    def execute(self, args):
        nickname = args[0]

        r = httplib.get("http://codeforces.com/api/user.info", params={'handles':nickname})

        r = json.loads(r)

        if(r["status"] == "FAILED"):
            print("Failed: {}".format(r["comment"]))
            return

        info = r['result'][0]

        # print(info)

        for arg in args[1:]:
            print(info[arg])
Пример #8
0
    def execute(self, args):
        nickname = args[0]
        rid = args[1]

        response = httplib.get('http://codeforces.com/api/contest.standings',
                               params={
                                   'contestId': rid,
                                   'handles': nickname
                               })

        response = json.loads(response)

        if (response['status'] == 'FAILED'):
            print('Fail: {}'.format(response['comment']))
            return

        result = response["result"]
        problems = result['problems']
        rows = result['rows']

        for i in range(len(problems)):
            print(rid,
                  problems[i]["index"],
                  ' ',
                  problems[i]['name'],
                  '\t[',
                  rows[0]["problemResults"][i]['points'],
                  "\\",
                  problems[i]["points"],
                  ']',
                  sep='')

        print('Hacks: +{}/-{}'.format(rows[0]['successfulHackCount'],
                                      rows[0]['unsuccessfulHackCount']))

        print('-' * 10)

        print('Points summary - {}, rank - {}'.format(rows[0]['points'],
                                                      rows[0]['rank']))
Пример #9
0
    def execute(self, args):

        vlvl = 0 #verbosity level
        if args[0] == '-v':
            vlvl = 1
            tasks = []
            handle = args[1]
        else:
            handle = args[0]

        r = httplib.get('http://codeforces.com/api/user.status', params={'handle' : handle})

        info = json.loads(r)

        if(info['status'] != 'OK'):
            print('Fail :c\n{}'.format(info['comment']))
            return

        info = info['result']
        
        count = 0

        for tr in info:
            if(tr['verdict'] == 'OK'):
                count += 1
                if(vlvl == 1):
                    tasks.append([tr['problem']['contestId'], tr['problem']['index']])

        if(vlvl == 1):
            tasks = sorted(tasks)
            for i in range(len(tasks)):
                if(i != 0 and tasks[i][0] != tasks[i-1][0]):
                    print()
                print(tasks[i][0], tasks[i][1], sep='')
            print('-'*10)

        print('Tasks solved: {}'.format(count))
Пример #10
0
    def execute(self, args):
        nickname    = args[0]
        rid         = args[1]

        response = httplib.get('http://codeforces.com/api/contest.standings', params={'contestId':rid, 'handles':nickname})

        response = json.loads(response)

        if(response['status'] == 'FAILED'):
            print('Fail: {}'.format(response['comment']))
            return

        result      = response["result"]
        problems    = result['problems']
        rows        = result['rows']

        for i in range(len(problems)):
            print(rid, problems[i]["index"],' ', problems[i]['name'], '\t[', rows[0]["problemResults"][i]['points'], "\\", problems[i]["points"], ']', sep='')

        print('Hacks: +{}/-{}'.format(rows[0]['successfulHackCount'], rows[0]['unsuccessfulHackCount']))

        print('-'*10)

        print('Points summary - {}, rank - {}'.format(rows[0]['points'], rows[0]['rank']))