Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2010
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Regex and show name problem

    Hi,

    I literally started learning python two hours ago in an attempt to produce a script that can monitor my mythtv box recording status. Scripts do exist but they all see live tv as a recording. So I wanted a custom script.

    I have this so far:
    Code:
    #!/usr/bin/python
    
    import httplib
    import time
    import MythTV
    import twitter
    import re
    
    from MythTV import MythDB, MythBE
    
    prefix = 'Recording: '
    
    db1 = MythDB(args=(('DBHostName','localhost'),
                      ('DBName','mythconverg'),
                      ('DBUserName','mythtv'),
                      ('DBPassword','################')))
    
    LastTweet1 = ' '
    LastTweet2 = ' '
    
    be1 = MythBE(db=db1)
    
    api = twitter.Api(username='########', password='#########')
    
    Encoder1 = "Encoder 1 "
    Encoder2 = "Encoder 2 "
    Recording = "is local on chimera and is recording"
    
    while(True):
            Connection = httplib.HTTPConnection("localhost:6544")
            Connection.request("GET", "/")
            Results = Connection.getresponse().read()
    
            if Encoder1+Recording in Results:
                    REC1 = be1.getCurrentRecording(1)
                    result = re.search ( "\'[A-Z a-z 0-9]*\'", str(REC1) )
                    Show = result.group ( 0 )
                    if LastTweet1 != Show:
                            LastTweet1 = Show
                            tempPrefix = prefix
                            tempPrefix += Show
                            api.PostUpdate(tempPrefix)
    
            if Encoder2+Recording in Results:
                    REC2 = be1.getCurrentRecording(2)
                    result = re.search ( "\'[A-Z a-z 0-9]*\'", str(REC2) )
                    Show = result.group ( 0 )
                    if LastTweet2 != Show:
                            LastTweet2 = Show
                            tempPrefix = prefix
                            tempPrefix += Show
                            api.PostUpdate(tempPrefix)
    
            time.sleep(10)
    It works fine minus one small problem...
    Code:
    be1.getCurrentRecording(1)
    returns the recording in this format:
    Code:
    <Program '4Music's Top 20','2010-06-05 01:30:00' at 0x1dd4050>
    The problem I have is if I have a show like the above 4Music's Top 20 then my regex code will produce '4Music'

    I there a better way to get the show name from the given string?

    Please excuse any bad programming! Im a newbie of two hours

    Thanks
    Chris

  • #2
    Regular Coder Samhain13's Avatar
    Join Date
    Aug 2008
    Location
    Pilipinas
    Posts
    169
    Thanks
    4
    Thanked 18 Times in 18 Posts
    Sorry I know nothing about the MythBE module. But from what I've found in the module's Wiki, getCurrentRecording is supposed to return a Program object.

    --- [Edit: just looked at the MythData.Program source...] ---
    You can try looking for "4Music" in the Program object's title, as in:
    Code:
    REC1 = be1.getCurrentRecording(1)
    if "4Music" in REC1.title:
        # do stuff...
    There's no need to use the "re" module. At least, I don't think so.
    Last edited by Samhain13; 06-07-2010 at 01:05 PM. Reason: Modified sample code.
    I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
    ** Independent Multimedia Artist in Pasig **


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •