Left: | ||
Right: |
OLD | NEW |
---|---|
1 #from ryu.app import nfm_13 | 1 #from ryu.app import nfm_13 |
2 import urllib2 | 2 import urllib2 |
3 from urllib2 import urlopen | 3 from urllib2 import urlopen |
4 import urllib | 4 import urllib |
5 #from urllib2 import urlencode | 5 #from urllib2 import urlencode |
6 #import urllib2.parse | 6 #import urllib2.parse |
7 #import urlencode | 7 #import urlencode |
8 #from urllib2 import parse as urlparse | 8 #from urllib2 import parse as urlparse |
9 from contextlib import closing | 9 from contextlib import closing |
10 import codecs | 10 import codecs |
11 import requests | 11 import requests |
12 | 12 import sys |
13 | 13 |
14 import json , re | 14 import json , re |
15 | 15 |
16 | 16 |
17 class GetRequest(): | 17 class GetRequest(): |
18 | 18 |
19 def __init__(self, arg1, arg2): | 19 def __init__(self, arg1, arg2): |
20 self.swithes_counter = {} | 20 self.swithes_counter = {} |
21 self.flow_counters_bw = {} | 21 self.flow_counters_bw = {} |
22 self.port_counters_tx_bw = {} | 22 self.port_counters_tx_bw = {} |
23 self.port_counters_rx_bw = {} | 23 self.port_counters_rx_bw = {} |
24 #params = urllib.urlencode(dict({'hello': 'there'})) | 24 #params = urllib.urlencode(dict({'hello': 'there'})) |
25 self.params = urllib.urlencode({'table': arg1, 'row': arg2}) | 25 self.params = urllib.urlencode({'table': arg1, 'row': arg2}) |
26 self.get_data_from_Server(self.params) | 26 self.get_data_from_Server(self.params) |
27 | 27 |
28 | 28 |
29 def get_data_from_Server(self, params ): | 29 def get_data_from_Server(self, params ): |
30 self.url = 'http://192.16.125.183/API_REST/request.php/get?' | 30 self.url = 'http://192.16.125.183/API_REST/request.php/get?' |
31 request = urllib2.Request(self.url + params) | 31 request = urllib2.Request(self.url + params) |
32 #print request | |
32 rq = urllib2.urlopen(request).read() | 33 rq = urllib2.urlopen(request).read() |
33 » » print rq | 34 » » #print rq |
34 cache = json.dumps(rq.decode('utf-8')) | 35 cache = json.dumps(rq.decode('utf-8')) |
35 #clen = len(cache) | 36 #clen = len(cache) |
36 while True: | 37 while True: |
37 # Search json string specifically for '"' | 38 # Search json string specifically for '"' |
38 b = re.search(r'[\w|"]\s?(")\s?[\w|"]',cache) | 39 b = re.search(r'[\w|"]\s?(")\s?[\w|"]',cache) |
39 # If we don't find any the we come out of loop | 40 # If we don't find any the we come out of loop |
40 if not b: | 41 if not b: |
41 break | 42 break |
42 # Get the location of \" | 43 # Get the location of \" |
43 s, e = b.span(1) | 44 s, e = b.span(1) |
44 c = cache[s:e] | 45 c = cache[s:e] |
45 # Replace \" with \' | 46 # Replace \" with \' |
46 c = c.replace('"',"'") | 47 c = c.replace('"',"'") |
47 cache = cache[:s] + c + cache[e:] | 48 cache = cache[:s] + c + cache[e:] |
48 new_json = json.loads(cache) | 49 new_json = json.loads(cache) |
49 #req = urllib2.Request(self.url, cache , {'Content-Type ': 'application/json', 'Content-Length': clen} | 50 #req = urllib2.Request(self.url, cache , {'Content-Type ': 'application/json', 'Content-Length': clen} |
50 print new_json | 51 print new_json |
51 | 52 |
52 | 53 |
53 | 54 |
55 #print "\n".join(sys.argv) | |
54 | 56 |
55 | 57 print 'You have given', len(sys.argv), 'arguments:', sys.argv |
56 a = GetRequest('port_counters',10) | 58 a = GetRequest(sys.argv[1], int(sys.argv[2])) |
Michail.Xirouchakis
2017/10/12 12:18:08
Since this file will be a module (imported to CPM)
Vasileios Papageorgiou
2017/11/29 16:24:32
Acknowledged.
| |
OLD | NEW |