ck3mp
06-05-2010, 01:34 AM
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:
#!/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...
be1.getCurrentRecording(1)
returns the recording in this format:
<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
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:
#!/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...
be1.getCurrentRecording(1)
returns the recording in this format:
<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