本文整理匯總了Python中restful_lib.Connection.add_rest_credentials方法的典型用法代碼示例。如果您正苦於以下問題:Python Connection.add_rest_credentials方法的具體用法?Python Connection.add_rest_credentials怎麽用?Python Connection.add_rest_credentials使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類restful_lib.Connection
的用法示例。
在下文中一共展示了Connection.add_rest_credentials方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Account
# 需要導入模塊: from restful_lib import Connection [as 別名]
# 或者: from restful_lib.Connection import add_rest_credentials [as 別名]
class Account(object):
"""A vcast account.
This class handles communication with Vcast FAUCET PVR Server
"""
def __init__(self, username, password):
"""Set up a REST connection to Vcast Server
Returns id_usr user id or raises exception"""
self.username = username
self.password = password
url = 'http://www.vcast.it/faucetpvr/api/1.0/server_rest.php'
self.connection = Connection(url)
self.connection.add_rest_credentials(username, password)
c = self.connection.request_get('/faucetid')
if c['body'] == 'Access Denied':
raise Exception('Wrong credentials')
self.id_usr = simplejson.loads(c['body'])['id_usr']
def get_channels(self):
"""Return channels.
The function returns channel as a list of dictionaries.
Each element of the list is a dictionary with two keys,
- type, whose value is a string that can be "video" or "audio";
- name, whose value is a string.
"""
try:
reply = self.connection.request_get('/channels')
return simplejson.loads(reply['body'])
except:
print reply
def get_recordings(self):
"""Return recordings.
The function returns recordings as a list of dictionaries.
Each element has the following keys whose value is a unicode
string (type: unicode).
- id_rec
- title
- channel
- channel_type (can be 'audio' or 'video')
- format
- from_time
- rec_time
- to_time
- retention
- repeat
- faucetacc (ignore it)
"""
try:
reply = self.connection.request_get('/recordings')
return simplejson.loads(reply['body'])
except:
print reply
def get_download_urls(self):
"""Return the urls of avaible recordings"""
feed = self.connection.request_get('/feed')['body']
feed = re.sub(r'\\(.)', r'\1', feed)[13:-3]
f = feedparser.parse(feed)
urls = []
for i in f.entries:
# print i['enclosures'][0]['href']
urls.append(i['enclosures'][0]['href'])
return urls
def new_recording(self, recording):
"""Invia al server una nuova programmazione"""
json = recording.toJson()
print json
a = self.connection.request_post('/recordings', body=json)
print a
def delete_recording(self, id):
repl = self.connection.request_get('/delete_recording',
args={'id_rec':str(id)})
print repl