Recent Changes - Search:

LiveStreamsPro

PmWiki

pmwiki.org

edit SideBar

PythonCodeblock

Python code block is pure python code enclosed in a CDATA section and that has to follow a certain syntax

As we are able to write python code in <expres> tag and it works well on single functions/statements but when you need to perform multiple steps or concatenate multiple outputs, we end up writing two regex etc.
Now we can write full blown python code with import and everything that we want in expres tag.

The tag must start with

Code:

<expres><![CDATA[#$pyFunction
and end with
Code:
]]></expres>

It must contain a function named as GetLSProData with params for page data , cookie jar , regex call and any parameter you want to send it. Parameters can be in the form of param='myStringLiteral', param='[makelist.param#]' or param='$doregex[myregex]'.

Here is an example, completely fictitious, but shows that how you can write your functions and process the request. this will make longer regex shorter, and for complex website interaction, this will allow us to handle them better.

XML validation rules are not enforced as you are using CDATA which means & shouldn't be replaced with &amp;

Example1:

<item>
    <title>Test Function call</title>
    <link>$doregex[get-url]</link>
    <regex>
        <name>get-url</name>
        <expres>
            <![CDATA[#$pyFunction
               import time

               def getMyCode2(dummyParam):
                  return  str(int(time.time()))

               def getMyCode(dummyParam):
                  return  str(int(time.time()*1000))

               def GetLSProData(page_data,Cookie_Jar,m,param='Param1Value'):
                  return 'http://Somewebsite.com/video/'+getMyCode(param) + '/'    
                  +getMyCode2(param)
               ]]>
        </expres>
        <page></page>
        <cookieJar></cookieJar>
    </regex>
</item>

Example2:

<item>
    <title> lb1.itcons.net.ua</title>
    <link>$doregex[get-url]</link>
    <regex>
        <name>get-url</name>
        <expres>
            <![CDATA[#$pyFunction
           import urllib2
           location = urllib2.urlopen('http://lb1.itcons.net.ua:1935/inters/redirect
           .hls?smil:inter.smil')
           print 'Location', location.geturl()
           ]]>
        </expres>
        <page></page>
        <connection>Keep-Alive</connection>
    </regex>
</item>

Edit - History - Print - Recent Changes - Search
Page last modified on May 02, 2016, at 04:42 AM