Go Back   CodingForums.com > :: Server side development > Other server side languages/ issues > Python

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-05-2010, 01:34 AM   PM User | #1
ck3mp
New to the CF scene

 
Join Date: Jun 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
ck3mp is an unknown quantity at this point
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
ck3mp is offline   Reply With Quote
Old 06-07-2010, 11:11 AM   PM User | #2
Samhain13
Regular Coder

 
Samhain13's Avatar
 
Join Date: Aug 2008
Location: Pilipinas
Posts: 165
Thanks: 4
Thanked 18 Times in 18 Posts
Samhain13 is on a distinguished road
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.
__________________
I am a Man of Truth. I am a Free Human Person. I am a Peacemaker.
** Independent Multimedia Artist in Pasig **

Last edited by Samhain13; 06-07-2010 at 12:05 PM.. Reason: Modified sample code.
Samhain13 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:25 AM.


Advertisement
Log in to turn off these ads.