Python Forum
Convert script from Perl to Python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert script from Perl to Python3
#1
Hello! First off I'm not a strong Python developer. I'm a Network Engineer and I use Python to create automation scripts for accessing routers and switches. I've never tried to convert a script of any type. A coworker asked me to help him convert a Perl script to Python. In my research and findings, I'm having some issues trying to find what I need in Python or even making it work.

The Perl script accesses Cisco's Call Manager (phone system) webpage (https, authenication, ignore SSL), it pulls data off the pages, may be more than one with up to 2000 line items on each page. It then parses it (XML) into two columns, userID and extensions, and dumps it into a .CSV file. It then reads that .CSV file, accesses Microsoft Active Directory, looks up the userID and puts the extension of that userID into the persons Active Directory profile under the ipPhone attribute.

The modules the Perl script uses are below vs what I've been trying to use in Python3...

Net::LDAP; = python3-ldap3
LWP::UserAgent; = urllib3
LWP::Protocol::https; = requests
XML::Simple; = lxml

Any help would be appreciated. I'd like to know if I'm using the right equivalents of Python3 and any great examples on how to use these modules.

So far, just even getting Python3 to "get" the URL, pass authentication credentials on the website and to ignore SSL cert has been really hard and frustrating. I'm not getting anywhere with that.
Reply
#2
Hello!

You will need requests, BeautifulSoup ( lxml as a parser or only lxml ), csv module ( it's built-in ). If the webpage is JS generated you will need selenium to handle it. For all of this there is tutorials in this forum ( not sure about lxml alone ): https://python-forum.io/Forum-Tutorials .

Don't know what protocol is using Microsoft Active Directory or how could access it. Can't tell anything about that.

Don't hesitate to ask further if you face some obstacles.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
Awesome! Thanks for the help. I will definitely give it a go. Appreciate it.
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020