2014-08-08, 17:58
(2014-08-07, 22:06)Lunatixz Wrote:could this be of any use? maybe to modify for zap2it if anything?(2014-08-07, 20:23)bry- Wrote:(2014-08-07, 19:26)Lunatixz Wrote: I've seen this before, from my knowledge it parses XMLTV data... Which PTVL already does... what would be the benefit of adding this module?
Ah I was thinking that PTVL could eventually handle all xmltv data with a python wrapper. I did some googling and found that there is 1 for zap2it and one for schedules direct.
Add an option to control the amount of data being pulled into the xmltv file and limit complaints of slow loading/scanning times perhaps. (thinking out loud) of course.
Aside from Schdedulesdirect... the projects I've found are not true wrappers and are more or less just xmltv parsers... I've searched for over a year for a true wrapper so I can have PseudoTV Live request xmltv data on the fly directly from (mc2xml, zap2it, etc)... but no luck
Thanks for the suggestions...
edit: or this http://sourceforge.net/projects/pytvgrab/files/
Code:
# This module retrieves SchedulesDirect XML data using a hand-coded SOAP request.
#
# The code is released into the Public Domain. If you break it, you own both halves.
#
# Original Code by Keith Medcalf, [email protected]
import codecs
import encodings
import gzip
import string
import sys
import time
import urllib2
import urlparse
def FetchXML(userName,
passWord,
URL='http://webservices.schedulesdirect.tmsdatadirect.com/schedulesdirect/tvlistings/xtvdService',
Realm='TMSWebServiceRealm',
predays=0,
postdays=14,
fileName='ddata.xml',
fileCoding='latin-1',
gzipped = False):
cur = time.time()
startTime = time.strftime( '%Y-%m-%dT00:00:00Z', time.gmtime( cur + ( predays * 86400.0 ) ) )
endTime = time.strftime( '%Y-%m-%dT00:00:00Z', time.gmtime( cur + ( postdays * 86400.0 ) ) )
strSoap = '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">\n' \
' <SOAP-ENV:Body>\n' \
' <m:download xmlns:m="urn:TMSWebServices" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">\n' \
' <startTime xsi:type="xsd:dateTime">' + startTime + '</startTime>\n' \
' <endTime xsi:type="xsd:dateTime">' + endTime + '</endTime>\n' \
' </m:download>\n' \
' </SOAP-ENV:Body>\n' \
'</SOAP-ENV:Envelope>'
print '#', time.strftime('%Y/%m/%d %H:%M:%S'), "Retrieving DataDirect TV Schedules"
print '#', time.strftime('%Y/%m/%d %H:%M:%S'), "Requesting", startTime, "to", endTime
authinfo = urllib2.HTTPDigestAuthHandler()
authinfo.add_password(Realm, urlparse.urlparse(URL)[1], userName, passWord)
request = urllib2.Request(URL, strSoap)
if gzipped:
request.add_header('Accept-encoding', 'gzip')
if fileName[-3:].lower() == '.gz':
fileName = fileName[:-3]
fileName += '.gz'
opener = urllib2.build_opener(authinfo)
urllib2.install_opener(opener)
print '#', time.strftime('%Y/%m/%d %H:%M:%S'), 'Saving XML to File: ' + fileName + ', Encoding: ' + fileCoding
fileObj = None
if fileCoding == 'native':
urldata = opener.open(request)
outfile = open(fileName,'wb',262144)
repenc = False
elif not gzipped:
urldata = codecs.getreader('utf-8')(opener.open(request), errors='replace')
outfile = codecs.open(fileName,'wb', fileCoding, 'replace', 262144)
repenc = True
else:
raise ValueError('Codepage Translation of GZIP data not supported')
print '#', time.strftime('%Y/%m/%d %H:%M:%S'), 'Receiving XML Data', ' '*30,
fmt = ('\b'*30) + '%6d KB, %3d KB/s, %3d KB/s'
data = 'X'
bytes = 0
currb = 0
first = time.time()
last = time.time() - 1
while data:
data = urldata.read(8192)
b = len(data)
bytes += b
currb += b
if repenc:
data = string.replace(data, "encoding='utf-8'", "encoding='"+fileCoding+"'")
repenc = False
if data:
outfile.write(data)
curr = time.time()
diff = curr - last
if diff >= 0.999:
print fmt % ((bytes//1024), currb//1024//(curr-last), bytes//1024//(curr-first)),
last = curr
currb = 0
urldata.close()
outfile.close()
if fileObj:
fileObj.close()
print fmt % ((bytes//1024), 0, bytes//1024//(curr-first))
print '#', time.strftime('%Y/%m/%d %H:%M:%S'), "Data Retrieval Complete"
if __name__ == '__main__':
userName = "<username>"
password = "<password>"
FetchXML(userName, password)