Esempio n. 1
0
 def get_data(self):
     data = {
         "clientId": None,
         "destination": "GenericDestination",
         "correlationId": None,
         "source":
         "com.backendless.services.persistence.PersistenceService",
         "operation": "first",
         "messageRefType": None,
         "headers": {
             "application-type": "ANDROID",
             "api-version": "1.0"
         },
         "timestamp": 0,
         "body": ["ConfigCharlie"],
         "timeToLive": 0,
         "messageId": None,
     }
     msg = messaging.RemotingMessage(**data)
     req = remoting.Request(target="null", body=[msg])
     ev = remoting.Envelope(pyamf.AMF3)
     ev["null"] = req
     resp = requests.post(self.url,
                          data=remoting.encode(ev).getvalue(),
                          headers={"Content-Type": "application/x-amf"})
     resp_msg = remoting.decode(resp.content)
     config = json.dumps(resp_msg.bodies[0][1].body.body,
                         default=lambda obj: repr(obj))
     return json.loads(config)
Esempio n. 2
0
    def test_destination(self):
        d = defer.Deferred()

        gw = twisted.TwistedGateway(
            {'spam.eggs': lambda x: x}, expose_request=False
        )
        proc = twisted.AMF3RequestProcessor(gw)

        request = remoting.Request(
            'null',
            body=[
                messaging.RemotingMessage(
                    body=[None], destination='spam', operation='eggs'
                )
            ]
        )

        def cb(result):
            try:
                self.assertTrue(result)
            except:
                d.errback()
            else:
                d.callback(None)

        proc(request).addCallback(cb).addErrback(lambda failure: d.errback())

        return d
Esempio n. 3
0
    def test_exposed_preprocessor(self):
        d = defer.Deferred()

        def preprocessor(http_request, service_request):
            return reactor.callLater(0, lambda: True)

        preprocessor = gateway.expose_request(preprocessor)
        gw = twisted.TwistedGateway(
            {'echo': lambda x: x},
            expose_request=False,
            preprocessor=preprocessor
        )
        proc = twisted.AMF3RequestProcessor(gw)

        request = remoting.Request(
            'null',
            body=[
                messaging.RemotingMessage(body=['spam.eggs'], operation='echo')
            ]
        )

        def cb(result):
            try:
                self.assertTrue(result)
            except:
                d.errback()
            else:
                d.callback(None)

        proc(request).addCallback(cb).addErrback(lambda failure: d.errback())

        return d
Esempio n. 4
0
    def test_preprocess(self):
        def echo(x):
            return x

        self.called = False

        def preproc(sr, *args):
            self.called = True

            self.assertEquals(args, ('spam.eggs', ))
            self.assertTrue(isinstance(sr, gateway.ServiceRequest))

        gw = gateway.BaseGateway({'echo': echo}, preprocessor=preproc)
        rp = amf3.RequestProcessor(gw)
        message = messaging.RemotingMessage(body=['spam.eggs'],
                                            operation='echo')
        request = remoting.Request('null', body=[message])

        response = rp(request)
        ack = response.body

        self.assertTrue(isinstance(response, remoting.Response))
        self.assertEquals(response.status, remoting.STATUS_OK)
        self.assertTrue(isinstance(ack, messaging.AcknowledgeMessage))
        self.assertEquals(ack.body, 'spam.eggs')
        self.assertTrue(self.called)
    def test_error_deferred_body(self):
        d = defer.Deferred()

        def echo(x):
            d2 = defer.Deferred()

            def cb(result):
                raise IndexError

            reactor.callLater(0, lambda: d2.callback(None))

            d2.addCallback(cb)
            return d2

        gw = twisted.TwistedGateway({'echo': echo}, expose_request=False)
        proc = twisted.AMF3RequestProcessor(gw)

        request = remoting.Request('null', body=[messaging.RemotingMessage(body=['spam.eggs'], operation='echo')])

        def cb(result):
            try:
                self.assertTrue(isinstance(result, remoting.Response))
                self.assertTrue(result.status, remoting.STATUS_ERROR)
                self.assertTrue(isinstance(result.body, messaging.ErrorMessage))
                self.assertEqual(result.body.faultCode, 'IndexError')
            except:
                d.errback()
            else:
                d.callback(None)

        proc(request).addCallback(cb).addErrback(lambda x: d.errback())

        return d
Esempio n. 6
0
    def test_error_preprocessor(self):
        def preprocessor(service_request, *args):
            raise IndexError

        gw = twisted.TwistedGateway(
            {'echo': lambda x: x},
            expose_request=False,
            preprocessor=preprocessor
        )
        proc = twisted.AMF3RequestProcessor(gw)

        request = remoting.Request(
            'null',
            body=[
                messaging.RemotingMessage(body=['spam.eggs'], operation='echo')
            ]
        )

        d = proc(request)

        self.assertTrue(isinstance(d, defer.Deferred))
        response = d.result
        self.assertTrue(isinstance(response, remoting.Response))
        self.assertTrue(response.status, remoting.STATUS_ERROR)
        self.assertTrue(isinstance(response.body, messaging.ErrorMessage))
        self.assertEqual(response.body.faultCode, 'IndexError')
Esempio n. 7
0
File: amf.py Progetto: wighawag/ubh
def executeService(gw, service, *args):
    rp = amf3.RequestProcessor(gw)
    message = messaging.RemotingMessage(body=args, operation=service)
    request = remoting.Request('null', body=[message])

    response = rp(request)
    return response
Esempio n. 8
0
    def test_deferred_preprocessor(self):
        d = defer.Deferred()

        def preprocessor(u, *args):
            d2 = defer.Deferred()
            reactor.callLater(0, lambda: d2.callback(None))

            return d2

        gw = twisted.TwistedGateway(
            {'echo': lambda x: x},
            expose_request=False, preprocessor=preprocessor
        )
        proc = twisted.AMF3RequestProcessor(gw)

        request = remoting.Request(
            'null',
            body=[
                messaging.RemotingMessage(body=['spam.eggs'], operation='echo')
            ]
        )

        def cb(result):
            self.assertTrue(result)
            d.callback(None)

        proc(request).addCallback(cb).addErrback(lambda failure: d.errback())

        return d
Esempio n. 9
0
    def test_RemotingMessage(self):
        m = messaging.RemotingMessage(source='foo.bar')

        self.assertEqual(pyamf.encode(m).getvalue(),
            '\n\x81\x1bOflex.messaging.messages.RemotingMessage\x15timeToLive'
            '\x13timestamp\x13messageId\x0fheaders\x17destination\x11clientId'
            '\tbody\x13operation\rsource\x01\x01\x01\n\x0b\x01\x01\x01\x01\x01'
            '\x01\x06\x0ffoo.bar\x01')
Esempio n. 10
0
    def test_unknown_service_request(self):
        gw = twisted.TwistedGateway({'echo': lambda x: x}, expose_request=False)
        proc = twisted.AMF3RequestProcessor(gw)

        request = remoting.Request('null', body=[messaging.RemotingMessage(body=['spam.eggs'], operation='ss')])

        d = proc(request)

        self.assertTrue(isinstance(d, defer.Deferred))
        response = d.result
        self.assertTrue(isinstance(response, remoting.Response))
        self.assertTrue(response.status, remoting.STATUS_ERROR)
        self.assertTrue(isinstance(response.body, messaging.ErrorMessage))
Esempio n. 11
0
def construct_request(startDate,endDate,market_code,market_name,item_code,item_name):
    breedInfoPo = BreedInfoPo(None,None,None,None)
    select_breed = BreedInfoPo(item_code,item_name,None,None)
    select = ArrayCollection([select_breed])
    market = PMarketInfo(market_code,market_name)
    msg = messaging.RemotingMessage(messageId=str(uuid.uuid1()).upper(),clientId=str(uuid.uuid1()).upper(),operation='getDyscDpzData',destination='reportStatService',timeToLive=0,timestamp=0)
    msg.body = [DyscdpzPara(startDate,endDate,select,market,breedInfoPo)]
    msg.headers['DSEndpoint'] = None  
    msg.headers['DSId'] = str(uuid.uuid1()).upper()
    req = remoting.Request('null',body = (msg,))
    env = remoting.Envelope(amfVersion=pyamf.AMF3)
    env.bodies = [('/1',req)]
    data = bytes(remoting.encode(env).read())
    return data
Esempio n. 12
0
    def test_preprocessor(self):
        d = defer.Deferred()

        def preprocessor(service_request, *args):
            d.callback(None)

        gw = twisted.TwistedGateway({'echo': lambda x: x}, expose_request=False, preprocessor=preprocessor)
        proc = twisted.AMF3RequestProcessor(gw)

        request = remoting.Request('null', body=[messaging.RemotingMessage(body=['spam.eggs'], operation='echo')])

        proc(request).addErrback(lambda failure: d.errback())

        return d
    def test_too_many_args(self):
        def spam(bar):
            return bar

        gw = gateway.BaseGateway({'spam': spam})
        rp = amf3.RequestProcessor(gw)
        message = messaging.RemotingMessage(body=['eggs', 'baz'], operation='spam')
        request = remoting.Request('null', body=[message])

        response = rp(request)
        ack = response.body

        self.assertTrue(isinstance(response, remoting.Response))
        self.assertEqual(response.status, remoting.STATUS_ERROR)
        self.assertTrue(isinstance(ack, messaging.ErrorMessage))
        self.assertEqual(ack.faultCode, 'TypeError')
    def test_request(self):
        def echo(x):
            return x

        gw = gateway.BaseGateway({'echo': echo})
        rp = amf3.RequestProcessor(gw)
        message = messaging.RemotingMessage(body=['spam.eggs'], operation='echo')
        request = remoting.Request('null', body=[message])

        response = rp(request)
        ack = response.body

        self.assertTrue(isinstance(response, remoting.Response))
        self.assertEqual(response.status, remoting.STATUS_OK)
        self.assertTrue(isinstance(ack, messaging.AcknowledgeMessage))
        self.assertEqual(ack.body, 'spam.eggs')
Esempio n. 15
0
    def test_error(self):
        def echo(x):
            raise TypeError

        gw = gateway.BaseGateway({'echo': echo})
        rp = amf3.RequestProcessor(gw)
        message = messaging.RemotingMessage(body=['spam.eggs'],
                                            operation='echo')
        request = remoting.Request('null', body=[message])

        response = rp(request)
        ack = response.body

        self.assertTrue(isinstance(response, remoting.Response))
        self.assertEquals(response.status, remoting.STATUS_ERROR)
        self.assertTrue(isinstance(ack, messaging.ErrorMessage))
        self.assertEquals(ack.faultCode, 'TypeError')
    def test_fail_preprocess(self):
        def preproc(sr, *args):
            raise IndexError

        def echo(x):
            return x

        gw = gateway.BaseGateway({'echo': echo}, preprocessor=preproc)
        rp = amf3.RequestProcessor(gw)
        message = messaging.RemotingMessage(body=['spam.eggs'], operation='echo')
        request = remoting.Request('null', body=[message])

        response = rp(request)
        ack = response.body

        self.assertTrue(isinstance(response, remoting.Response))
        self.assertEqual(response.status, remoting.STATUS_ERROR)
        self.assertTrue(isinstance(ack, messaging.ErrorMessage))
Esempio n. 17
0
def getAmf(list1, operationStr, destinationStr, jsessionid, opener):
    list = []
    #list1 = [''];
    # 构造flex.messaging.messages.RemotingMessage消息
    #print(str(uuid.uuid1()).upper())
    msg = messaging.RemotingMessage(messageId=str(uuid.uuid1()).upper(),  
                                clientId=None,  
                                operation=operationStr,  
                                destination=destinationStr,  
                                timeToLive=0,  
                                timestamp=0);
    # 第一个是查询参数
    msg.body = list1
    msg.headers['DSEndpoint'] = 'my-amf'  
    msg.headers['DSId'] = str(uuid.uuid4()).upper()
    # 按AMF协议编码数据  
    req = remoting.Request('null', body=(msg,))  
    env = remoting.Envelope(amfVersion=pyamf.AMF3)  
    env.bodies = [('/1', req)]  
    data = bytes(remoting.encode(env).read())
    url="123123123"
    t = time.time();
    headC = "Hm_lvt_447d5331c7cf0d9e38c7ee579499d9fb=" + str(int(t)) + ";Hm_lpvt_447d5331c7cf0d9e38c7ee579499d9fb" + str(int(t)) + ";JSESSIONID=" + jsessionid;
    
    req = ub.Request(url,data, headers={'Content-Type': 'application/x-amf', 'Cookie': headC, 'Accept':'*/*', 'Accept-Encoding': 'gzip, deflate', 'Accept-Language': 'zh-CN',
   'Host': '1111111',
   'Pragma': 'no-cache',
   'Proxy-Connection': 'Keep-Alive',
   'Referer': '1111111111111111111',
   'User-Agent': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 10.0; WOW64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; InfoPath.3; wbx 1.0.0)',
   'x-flash-version': '29,0,0,113'})
    resp = remoting.decode(opener.open(req).read())
    #for i, record in enumerate(resp.bodies[0][1].body.body[0]):
        #print(record)
    #print(resp)
    a = resp.bodies[0][1].body.body['resultList'];
    #print(a)
    #print(a.get(8));
    #for record in a:
        #list.append(a);
        #print(record)
    return a;
Esempio n. 18
0
def getAllStudentMultiExam(student_id):
    msg = messaging.RemotingMessage(
        operation="getAllStudentMultiExam",
        source=None,
        timeTolive=0,
        clientId=None,
        destination="multiExamServiceNew",
        messageId="C",
        timestamp=0,
    )
    msg.body = [0, student_id, None]
    msg.headers["DSRequestTimeout"] = 600
    msg.headers["DSId"] = "C"
    msg.headers["DSEndpoint"] = None
    # 按AMF协议编码
    req = remoting.Request("null", body=(msg, ))
    env = remoting.Envelope(amfVersion=pyamf.AMF3)
    env.bodies = [("/2", req)]
    data = bytes(remoting.encode(env).read())
    return invoke(data)
Esempio n. 19
0
    def test_error_body(self):
        def echo(x):
            raise KeyError

        gw = _twisted.TwistedGateway({'echo': echo}, expose_request=False)
        proc = _twisted.AMF3RequestProcessor(gw)

        request = remoting.Request('null',
                                   body=[
                                       messaging.RemotingMessage(
                                           body=['spam.eggs'],
                                           operation='echo')
                                   ])

        d = proc(request)

        self.assertTrue(isinstance(d, defer.Deferred))
        response = d.result
        self.assertTrue(isinstance(response, remoting.Response))
        self.assertTrue(response.status, remoting.STATUS_ERROR)
        self.assertTrue(isinstance(response.body, messaging.ErrorMessage))
        self.assertEquals(response.body.faultCode, 'KeyError')
Esempio n. 20
0
login_request = requests.post(
    ''.join(['http://', host, '/?method=loginUser']),
    data={
        'email': email,
        'password': password
    },
    #proxies = proxies
)

# save cookies
jar = login_request.cookies

# build message for CF backend
msg = messaging.RemotingMessage(operation='loadRoles',
                                source='model.remote.remoteRoleManager',
                                destination='ColdFusion',
                                messageId=str(uuid.uuid4()).upper(),
                                body=[0, 'cc'])
# make an envelope
req = remoting.Request(target='null', body=[msg])
ev = remoting.Envelope(pyamf.AMF3)
ev['/0'] = req
# encode id
bin_msg = remoting.encode(ev)
# send -> the xml formatted request you can find in AMF folder
resp = requests.post(
    ''.join(['http://', host, '/flex2gateway/']),
    data=bin_msg.getvalue(),
    headers={'Content-Type': 'application/x-amf'},
    cookies=jar,
    #proxies = proxies
Esempio n. 21
0
def this_is_spider(module_path):
    msg = messaging.RemotingMessage(messageId=str(uuid.uuid1()).upper(),
                                    clientId=str(uuid.uuid1()).upper(),
                                    operation='getAllShowHourData',
                                    destination='GISCommonDataUtilForWms',
                                    timeToLive=0,
                                    timestamp=0,
                                    body=[],
                                    source=None)
    # 第一个是查询参数,第二个是页数,第三个是控制每页显示的数量(默认每页只显示15条)
    #msg.body = [HqPara()]
    msg.headers['DSEndpoint'] = None
    msg.headers['DSId'] = str(uuid.uuid1()).upper()
    # 按AMF协议编码数据
    req = remoting.Request('null', body=(msg, ))
    env = remoting.Envelope(amfVersion=pyamf.AMF3)
    env.bodies = [('/1', req)]
    data = bytes(remoting.encode(env).read())
    # 提交请求
    url = 'http://wms.zjemc.org.cn/wms/messagebroker/amfWms'
    req = urllib2.Request(url,
                          data,
                          headers={'Content-Type': 'application/x-amf'})
    # 解析返回数据
    opener = urllib2.build_opener()

    # 解码AMF协议返回的数据
    resp = remoting.decode(opener.open(req).read())
    result = str(resp.bodies)
    number1_a = result.find("u'\u8bf8\u5bb6'")  #诸家
    result_1 = result[number1_a:]
    number1_b = result_1.find('}')
    result_1_f = result_1[:number1_b]
    number1_c = result_1_f.find('[')
    number1_d = result_1_f.find(']')
    result_1_g = result_1_f[number1_c + 1:number1_d]
    result_1_h = result_1_g.split(',')

    number2_a = result.find("u'\u5357\u661f\u6865\u6e2f'")  #南星桥港
    result_2 = result[number2_a:]
    number2_b = result_2.find('}')
    result_2_f = result_2[:number2_b]
    number2_c = result_2_f.find('[')
    number2_d = result_2_f.find(']')
    result_2_g = result_2_f[number2_c + 1:number2_d]
    result_2_h = result_2_g.split(',')

    number3_a = result.find("u'\u5927\u9ebb'")  #大麻
    result_3 = result[number3_a:]
    number3_b = result_3.find('}')
    result_3_f = result_3[:number3_b]
    number3_c = result_3_f.find('[')
    number3_d = result_3_f.find(']')
    result_3_g = result_3_f[number3_c + 1:number3_d]
    result_3_h = result_3_g.split(',')

    number4_a = result.find("u'\u8054\u5408\u6865'")  #联合桥
    result_4 = result[number4_a:]
    number4_b = result_4.find('}')
    result_4_f = result_4[:number4_b]
    number4_c = result_4_f.find('[')
    number4_d = result_4_f.find(']')
    result_4_g = result_4_f[number4_c + 1:number4_d]
    result_4_h = result_4_g.split(',')

    number5_a = result.find("u'\u665a\u6751'")  #晚村
    result_5 = result[number5_a:]
    number5_b = result_5.find('}')
    result_5_f = result_5[:number5_b]
    number5_c = result_5_f.find('[')
    number5_d = result_5_f.find(']')
    result_5_g = result_5_f[number5_c + 1:number5_d]
    result_5_h = result_5_g.split(',')

    number6_a = result.find("u'\u4e4c\u9547'")  #乌镇
    result_6 = result[number6_a:]
    number6_b = result_6.find('}')
    result_6_f = result_6[:number6_b]
    number6_c = result_6_f.find('[')
    number6_d = result_6_f.find(']')
    result_6_g = result_6_f[number6_c + 1:number6_d]
    result_6_h = result_6_g.split(',')

    number7_a = result.find("u'\u4e4c\u9547\u5317'")  #乌镇北
    result_7 = result[number7_a:]
    number7_b = result_7.find('}')
    result_7_f = result_7[:number7_b]
    number7_c = result_7_f.find('[')
    number7_d = result_7_f.find(']')
    result_7_g = result_7_f[number7_c + 1:number7_d]
    result_7_h = result_7_g.split(',')

    number8_a = result.find("u'\u65b0\u584d\u5927\u901a'")  #新塍大通
    result_8 = result[number8_a:]
    number8_b = result_8.find('}')
    result_8_f = result_8[:number8_b]
    number8_c = result_8_f.find('[')
    number8_d = result_8_f.find(']')
    result_8_g = result_8_f[number8_c + 1:number8_d]
    result_8_h = result_8_g.split(',')

    number9_a = result.find("u'\u676d\u7533\u516c\u8def\u6865'")  #杭申公路桥
    result_9 = result[number9_a:]
    number9_b = result_9.find('}')
    result_9_f = result_9[:number9_b]
    number9_c = result_9_f.find('[')
    number9_d = result_9_f.find(']')
    result_9_g = result_9_f[number9_c + 1:number9_d]
    result_9_h = result_9_g.split(',')
    result_total = [{
        'name': '南星桥港',
        'value': result_2_h
    }, {
        'name': '大麻',
        'value': result_3_h
    }, {
        'name': '联合桥',
        'value': result_4_h
    }, {
        'name': '晚村',
        'value': result_5_h
    }, {
        'name': '乌镇',
        'value': result_6_h
    }, {
        'name': '乌镇北',
        'value': result_7_h
    }, {
        'name': '新塍大通',
        'value': result_8_h
    }, {
        'name': '杭申公路桥',
        'value': result_9_h
    }]
    json_url1 = module_path + 'json_szsj1.json'
    text1 = open(json_url1, 'w')
    data_json = json.dumps(result_total, ensure_ascii=False)
    text1.write(data_json)
    text1.close()
Esempio n. 22
0
login_header = resp.headers['Set-Cookie'].split(',')
for data in login_header:
    if "SMSESSION" in data:
        data = data.split(";")
        data = data[0].split("=")
        print(data)

cookies = {'SMSESSION': data[1],
           'TS0115c575': '0159fffb6670d4f050f15ccf6f4008111b5db91efc0c16e81535cf32dae600d36a0068b88c4da597c7379aff788db512164bf1e1c3871b1c72b1858c536ff6a96cf04c0d416d867547dd7641ea1f216bf4a0b42607',
           'TS0157d5db':'0159fffb66d37a90c0a710441436619d4ccc171057c074bbfdfc9f63b4faae68196fb4227f918566d0b72b45795afd2bc057982220'}

msg = messaging.RemotingMessage(operation='getUploadFiles',
                                clientId='6525D474-C40B-310E-5166-1BBAD11DB51D',
                                destination='scheduleUploadDocCommand',
                                messageId=str(uuid.uuid4()).upper(),
                                body=['IRMEHT2'],
                                headers={'DSId': '62A318D7-A719-932E-AAB7-19ED3B5CFA23',
                                        'DSEndpoint': 'my-amf', 'DSRequestTimeout': '150'},
                                timeToLive= 0,
                                timestamp=0)


#         # msg_2 = messaging.RemotingMessage(operation='getReportDetails',
#         #                           clientId='6525D474-C40B-310E-5166-1BBAD11DB51D',
#         #                           destination='scheduleUploadDocCommand',
#         #                           messageId=str(uuid.uuid4()).upper(),
#         #                           body=['IRMEHT2'],
#         #                           headers={'DSId': '62A318D7-A719-932E-AAB7-19ED3B5CFA23',
#         #                                    'DSEndpoint': 'my-amf', 'DSRequestTimeout': '150'},
#         #                           timeToLive=0,
#         #                           timestamp=0)
Esempio n. 23
0
        #                                 clientId='6525D474-C40B-310E-5166-1BBAD11DB51D',
        #                                 destination='scheduleUploadDocCommand',
        #                                 messageId=str(uuid.uuid4()).upper(),
        #                                 body=['IRMEHT2'],
        #                                 headers={'DSId': '62A318D7-A719-932E-AAB7-19ED3B5CFA23',
        #                                         'DSEndpoint': 'my-amf', 'DSRequestTimeout': '150'},
        #                                 timeToLive= 0,
        #                                 timestamp=0)

        # updateReportDistributionStatus
        data_array = flex.ArrayCollection([{'docID': '37969668', 'targetID': '42413994', 'reportId': '64035', 'status': 'COMPLETED', 'filename': "FILE || Generic Report.pdf"}])
        msg = messaging.RemotingMessage(operation='updateReportDistributionStatus',
                                  clientId='C747A8F6-9409-0C8F-2BCB-65AF73A43268',
                                  destination='scheduleUploadDocCommand',
                                  messageId=str(uuid.uuid4()).upper(),
                                  body=[data_array],
                                  headers={'DSId': 'C747A362-5B1C-7F78-1CB4-A6FE0D75F959',
                                           'DSEndpoint': 'my-amf', 'DSRequestTimeout': '150'},
                                  timeToLive=0,
                                  timestamp=0)
        req = remoting.Request(target= None, body=[msg])#, msg_2])
        ev = remoting.Envelope(pyamf.AMF3)
        ev['/0'] = req
        # print("\n\n" + str(req))
        # Encode request
        bin_msg = remoting.encode(ev)

        # print("\n<-------------Encoded Request------------------>\n")
        # print(bin_msg.getvalue())

        # Fuzzing Logic
Esempio n. 24
0
# 打开页面加载flash会先发送一个请求,返回所有批发市场和品种的编号。而这两个编号也是接下面请求的必需的input参数
from urllib import request
import uuid
import pyamf
import json, datetime
from pyamf import remoting
from pyamf.flex import messaging
import csv
# 很显然operation是 getInitData 初始化数据
msg = messaging.RemotingMessage(messageId=str(uuid.uuid1()).upper(),
                                clientId=str(uuid.uuid1()).upper(),
                                operation='getInitData',
                                destination='reportStatService',
                                timeToLive=0,
                                timestamp=0)
msg.body = []
msg.headers['DSEndpoint'] = None
msg.headers['DSId'] = str(uuid.uuid1()).upper()
req = remoting.Request('null', body=(msg, ))
env = remoting.Envelope(amfVersion=pyamf.AMF3)
env.bodies = [('/1', req)]
data = bytes(remoting.encode(env).read())
url = 'http://jgsb.agri.cn/messagebroker/amf'
req = request.Request(url, data, headers={'Content-Type': 'application/x-amf'})
opener = request.build_opener()
response = opener.open(req).read()
amf_parse_info = remoting.decode(response)
breed_info = amf_parse_info.bodies[0][1].body.body[0]
fp = open('breed_code.csv', 'w')
csvFile = csv.writer(fp)
for item in breed_info:
Esempio n. 25
0
def spider1():
    msg = messaging.RemotingMessage(messageId=str(uuid.uuid1()).upper(),
                                    clientId=str(uuid.uuid1()).upper(),
                                    operation='getHourlyDataForAllSites',
                                    destination='GisCommonDataUtil',
                                    timeToLive=0,
                                    timestamp=0,
                                    body=[],
                                    source=None)
    # 第一个是查询参数,第二个是页数,第三个是控制每页显示的数量(默认每页只显示15条)
    #msg.body = [HqPara()]
    msg.headers['DSEndpoint'] = None
    msg.headers['DSId'] = str(uuid.uuid1()).upper()
    # 按AMF协议编码数据
    req = remoting.Request('null', body=(msg, ))
    env = remoting.Envelope(amfVersion=pyamf.AMF3)
    env.bodies = [('/1', req)]
    data = bytes(remoting.encode(env).read())
    # 提交请求

    #url = 'http://wms.zjemc.org.cn/wms/messagebroker/amfWms'
    url = 'http://aqi.zjemc.org.cn/aqi/messagebroker/amf'
    req = urllib2.Request(url,
                          data,
                          headers={'Content-Type': 'application/x-amf'})
    # 解析返回数据
    opener = urllib2.build_opener()

    # 解码AMF协议返回的数据
    resp = remoting.decode(opener.open(req).read())
    result = str(resp.bodies)
    #print result
    number1_a = result.find("u'\u4e4c\u9547'")  #乌镇
    result_1 = result[number1_a:]
    number1_b = result_1.find("},")
    number1_c = result_1.find("u'airIndexLevel': {")
    result_1_f = result_1[number1_b + 2:number1_c - 2]
    result_1_i = result[:number1_a]
    number1_d = result_1_i.rfind("u'avgHour1O3'")
    number1_f = result_1_i.rfind("u'avgHour24SliderPm25'")
    result_1_j = result_1_i[number1_d:number1_f - 1]
    result_1_k = result_1_j + result_1_f
    result_1_h = result_1_k.split(',')

    number2_a = result.find("u'\u632f\u4e1c\u65b0\u516d\u4e2d\u7ad9'")  #振东新六中站
    result_2 = result[number2_a:]
    number2_b = result_2.find("},")
    number2_c = result_2.find("u'airIndexLevel': {")
    result_2_f = result_2[number2_b + 2:number2_c - 2]
    result_2_i = result[:number2_a]
    number2_d = result_2_i.rfind("u'avgHour1O3'")
    number2_f = result_2_i.rfind("u'avgHour24SliderPm25'")
    result_2_j = result_2_i[number2_d:number2_f - 1]
    result_2_k = result_2_j + result_2_f
    result_2_h = result_2_k.split(',')

    number3_a = result.find("u'\u679c\u56ed\u6865\u6c34\u5382'")  #果园桥水厂
    result_3 = result[number3_a:]
    number3_b = result_3.find("},")
    number3_c = result_3.find("u'airIndexLevel': {")
    result_3_f = result_3[number3_b + 2:number3_c - 2]
    result_3_i = result[:number3_a]
    number3_d = result_3_i.rfind("u'avgHour1O3'")
    number3_f = result_3_i.rfind("u'avgHour24SliderPm25'")
    result_3_j = result_3_i[number3_d:number3_f - 1]
    result_3_k = result_3_j + result_3_f
    result_3_h = result_3_k.split(',')

    result_total = [{
        'name': '乌镇',
        'value': result_1_h
    }, {
        'name': '振东新六中站',
        'value': result_2_h
    }, {
        'name': '果园桥水厂',
        'value': result_3_h
    }]
    return result_total
class ZjemcDay:
    """ 浙江省水质日均数据 """
    pyamf.register_class(WmsDayDataVo,
                         alias='com.fpi.prj.zjemc.airenv.wms.entity.vo')
    msg = messaging.RemotingMessage(
        messageId=str(uuid.uuid1()).upper(),
        clientId=str(uuid.uuid1()).upper(),
        operation='getAllShowDayData',  # getAllValleyVo\getAllSiteHistoryVo
        destination='GISCommonDataUtilForWms',
        timeToLive=0,
        timestamp=0,
    )

    def __init__(self) -> None:
        self.headers = {
            # POST /wms/messagebroker/amfWms HTTP/1.1
            'Host': 'wms.zjemc.org.cn',
            'User-Agent':
            'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.75 Safari/537.36',
            'Content-Type': 'application/x-amf',
            'Accept': '*/*',
            'Origin': 'http://wms.zjemc.org.cn',
            'X-Requested-With': 'ShockwaveFlash/32.0.0.445',
            # Referer	http://wms.zjemc.org.cn/wms/wmsflex/index.swf/[[DYNAMIC]]/4
            'Accept-Encoding': 'gzip, deflate',
            'Accept-Language': 'zh-CN,zh;q=0.9'
        }

    def getRequestData(self):
        ZjemcDay.msg.body = []
        ZjemcDay.msg.headers['DSEndpoint'] = None
        ZjemcDay.msg.headers['DSId'] = str(uuid.uuid1()).upper()
        # 按AMF协议编码数据
        req = remoting.Request('null', body=(ZjemcDay.msg, ))
        env = remoting.Envelope(amfVersion=pyamf.AMF3)
        env.bodies = [('/1', req)]
        data = bytes(remoting.encode(env).read())
        return data

    def getResponse(self, data):
        url = 'http://wms.zjemc.org.cn/wms/messagebroker/amf'
        resp = Request(url, data, self.headers)
        # 解析返回数据
        opener = urllib2.build_opener()
        return opener.open(resp).read()
        # return resp

    def getContent(self, response):
        amf_parse_info = remoting.decode(response)
        # print(amf_parse_info)
        info = amf_parse_info.bodies[0][1].body.body['wmsWeekDataVos']
        # print(info)
        factor_key = [
            'pH', 'DO(mg/l)', 'COD_Mn(mg/l)', 'TP(mg/l)', 'NH3-N(mg/l)'
        ]
        level_key = ['pH_级别', 'DO_级别', 'COD_Mn_级别', 'TP_级别', 'NH3-N_级别']
        data_list = []
        for record in info:
            # print(record)
            data = {}
            data['监测站点'] = record['mtName']
            data['监测时间'] = record['monitorTime']
            data['所属区域'] = record['boundaryArea']
            data['功能要求'] = record['levelStandard']
            data['水质类别'] = record['level']
            data['longitude'] = record['longitude']
            data['latitude'] = record['latitude']
            factor_value = eval(str(record['factorValues'])[35:-1])
            level_value = eval(str(record['factorLevel'])[35:-1])

            for key, value in zip(factor_key, factor_value):
                data[key] = value

            for key, value in zip(level_key, level_value):
                data[key] = value

            data_list.append((data))

        return data_list