Can some one help to translate Python code to Perl?

W

wnjayantha

import urllib
import urllib2
from xml.dom import minidom

user="YourUserName"
password="YourPassword"

site='https://test.api.betfairgames.com/rest/v1/bet/order'
site=site+"?username="+user

xml_request1="""<postBetOrder
xmlns="https://api.betfairgames.com/rest/v1"
round="1" marketId="3829306" currency="GBP">
<betPlace>
<bidType>BACK</bidType>
<price>2.6</price>
<size>4</size>
<selectionId>658439</selectionId>
</betPlace>
</postBetOrder>"""

values = {'xmlRequest':xml_request}
data=urllib.urlencode(values)

req=urllib2.Request(site)
req.add_header('Content-Type', 'application/x-www-form-urlencoded')
req.add_header('gamexAPIAgent','(e-mail address removed).4.0')
req.add_header('gamexAPIAgentInstance','0d69ee8290ee2f9b336c1f060e3497a5')
req.add_header('gamexAPIPassword',password)
req.add_header('Keep-Alive','300')
req.add_header('Proxy-Connection','keep-alive')
req.add_header('Content-Type','application/x-www-form-urlencoded')
req.add_header('Content-Length',str(len(data)))
req.add_data(data)

xmlresult = urllib2.urlopen(req)
xmlparser = minidom.parse(xmlresult)

print xmlparser.toxml()
 
J

J. Gleixner

import urllib
import urllib2
from xml.dom import minidom
use LWP;
use XML::Simple;
use strict;
use warnings;
user="YourUserName" my $user = 'YourUserName';
password="YourPassword" my $password = 'YourPassword';

site='https://test.api.betfairgames.com/rest/v1/bet/order'
site=site+"?username="+user
my $site =
'https://test.api.betfairgames.com/rest/v1/bet/order?username=' . $user;
xml_request1="""<postBetOrder [...]
</postBetOrder>"""
my $xml_request1 = q{<postBetOrder
....
</postBetOrder>};

For the rest, read the documentation on LWP and XML::Simple:

perldoc LWP
perldoc lwpcook
perldoc XML::Simple

It's almost a cut & paste, while adding a few '$'s here and there.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top