Python Forum
convert sh script to python script
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
convert sh script to python script
#1
hi, i have a sh script code and need to convert it into python script.
i m struggling finding the correspondant command.


so here is my sh script

    RESPONSE=`curl -s -X GET http://192.168.8.1/api/webserver/SesTokInfo`
    COOKIE=`echo "$RESPONSE"| grep SessionID=| cut -b 10-147`
    TOKEN=`echo "$RESPONSE"| grep TokInfo| cut -b 10-41`
   

    DATA="<request><PageIndex>1</PageIndex><ReadCount>3</ReadCount> 
    <BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending> 
    <UnreadPreferred>1</UnreadPreferred></request>"

    curl -b $COOKIE -c $COOKIE -H "X-Requested-With: XMLHttpRequest" --data 
    "$DATA" http://192.168.8.1/api/sms/sms-list --header 
    "__RequestVerificationToken: $TOKEN" --header "Content-Type:text/xml"
so i m returning the first 3 most recent results of my html page with the different specific tag


i want to write a script in python which can do the same

thanks

I tried Requests from python library to access the session ID and the Token, so that i can access the next page but i m facing troubles while trying to pass this parameters to requests.get


#!/usr/bin/env python
from urllib.request import urlopen
import urllib.request
import urllib.parse
import requests
from bs4 import BeautifulSoup

#response = Connection('http://192.168.8.1/api/webserver/SesTokInfo')

session = requests.Session()

response1= 'http://192.168.8.1/api/webserver/SesTokInfo'
page1= requests.get(response1)
result1 = BeautifulSoup(page1.text, 'html.parser')

for p in result1.find_all('sesinfo'):
    cookie=p.text
for q in result1.find_all('tokinfo'):
    token=q.text


headers = {
    'X-Requested-With': 'XMLHttpRequest',
    '__RequestVerificationToken':token,
    'Content-Type': 'text/xml'
}

data="<request><PageIndex>1</PageIndex><ReadCount>3</ReadCount><BoxType>1</BoxType><SortType>0</SortType><Ascending>0</Ascending><UnreadPreferred>1</UnreadPreferred></request>"

#response = requests.get('http://192.168.8.1/api/sms/sms-list', headers=headers, cookies=cookie, data=data)
result = BeautifulSoup(response.text, 'html.parser')

for r in result:
    print(r)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Running script from remote to server invisiblemind 4 757 Mar-28-2025, 07:57 AM
Last Post: buran
  Insert command line in script lif 4 1,032 Mar-24-2025, 10:30 PM
Last Post: lif
  modifying a script mackconsult 1 598 Mar-17-2025, 04:13 PM
Last Post: snippsat
  help with a script that adds docstrings and type hints to other scripts rickbunk 2 1,273 Feb-24-2025, 05:12 AM
Last Post: from1991
  Detect if another copy of a script is running from within the script gw1500se 4 1,150 Jan-31-2025, 11:30 PM
Last Post: Skaperen
  pass arguments from bat file to pyhon script from application absolut 2 1,164 Jan-13-2025, 11:05 AM
Last Post: DeaD_EyE
  Best way to feed python script of a file absolut 6 1,185 Jan-11-2025, 07:03 AM
Last Post: Gribouillis
  How to make it so whatever I input into a script gets outputted on a different file spermatozwario 4 1,200 Nov-24-2024, 12:58 PM
Last Post: deanhystad
  [SOLVED] [Linux] Run Python script through cron? Winfried 2 1,253 Oct-19-2024, 06:29 PM
Last Post: Winfried
  Help for Tiktok Script Jasson187512 0 770 Oct-09-2024, 08:42 AM
Last Post: Jasson187512

Forum Jump:

User Panel Messages

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