mirror of
https://github.com/fergalmoran/dss.radio.git
synced 2025-12-22 09:48:21 +00:00
Added twitter feed
This commit is contained in:
17
ice_relay.py
17
ice_relay.py
@@ -5,6 +5,7 @@ import urllib
|
|||||||
import shout
|
import shout
|
||||||
import urllib2
|
import urllib2
|
||||||
import requests
|
import requests
|
||||||
|
from util.social import Twitter
|
||||||
|
|
||||||
BUF_LEN = 4096
|
BUF_LEN = 4096
|
||||||
|
|
||||||
@@ -37,6 +38,12 @@ class IceRelay(Thread):
|
|||||||
self.channel.port = int(options['ice_port'])
|
self.channel.port = int(options['ice_port'])
|
||||||
self.channel.user = options['ice_user']
|
self.channel.user = options['ice_user']
|
||||||
self.channel.password = options['ice_password']
|
self.channel.password = options['ice_password']
|
||||||
|
|
||||||
|
self.twitter_consumer_key = options['twitter_consumer_key']
|
||||||
|
self.twitter_consumer_secret = options['twitter_consumer_secret']
|
||||||
|
self.twitter_access_token = options['twitter_access_token']
|
||||||
|
self.twitter_access_token_secret = options['twitter_access_token_secret']
|
||||||
|
|
||||||
self.channel.public = 1
|
self.channel.public = 1
|
||||||
if self.channel.format == 'mp3':
|
if self.channel.format == 'mp3':
|
||||||
self.channel.audio_info = {
|
self.channel.audio_info = {
|
||||||
@@ -142,6 +149,15 @@ class IceRelay(Thread):
|
|||||||
logging.debug("Playing: {}".format(item['description']))
|
logging.debug("Playing: {}".format(item['description']))
|
||||||
self.stream = self.file_read_remote(item['url'])
|
self.stream = self.file_read_remote(item['url'])
|
||||||
|
|
||||||
|
if self.twitter_access_token and self.twitter_access_token_secret and \
|
||||||
|
self.twitter_consumer_secret and self.twitter_consumer_key:
|
||||||
|
try:
|
||||||
|
tw = Twitter(key=self.twitter_consumer_key, secret=self.twitter_consumer_secret,
|
||||||
|
access_key=self.twitter_access_token, access_secret=self.twitter_access_token_secret)
|
||||||
|
tw.post("Now playing on DSS Radio - {}\nhttp://deepsouthsounds.com/".format(item['description']))
|
||||||
|
except Exception as ex:
|
||||||
|
logging.error("Unable to post to twitter: {}".format(ex))
|
||||||
|
|
||||||
self._ended = False
|
self._ended = False
|
||||||
return True
|
return True
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
@@ -155,7 +171,6 @@ class IceRelay(Thread):
|
|||||||
now_playing = self.get_next_play_item()
|
now_playing = self.get_next_play_item()
|
||||||
if now_playing is not None:
|
if now_playing is not None:
|
||||||
|
|
||||||
|
|
||||||
for self.chunk in self.stream:
|
for self.chunk in self.stream:
|
||||||
try:
|
try:
|
||||||
self.channel.send(self.chunk)
|
self.channel.send(self.chunk)
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
python-twitter
|
||||||
twisted
|
twisted
|
||||||
cython
|
cython
|
||||||
requests
|
requests
|
||||||
|
|||||||
@@ -71,6 +71,11 @@ define("ice_format", default='mp3', help="Format of the icecast server (mp3, vor
|
|||||||
define("ice_protocol", default='http', help="Protocol (currently only http)")
|
define("ice_protocol", default='http', help="Protocol (currently only http)")
|
||||||
define("api_host", default='api.deepsouthsounds.com', help="API Host for serving audio")
|
define("api_host", default='api.deepsouthsounds.com', help="API Host for serving audio")
|
||||||
|
|
||||||
|
define("twitter_consumer_key", default='', help="Key for posting to twitter")
|
||||||
|
define("twitter_consumer_secret", default='', help="Secret for posting to twitter")
|
||||||
|
define("twitter_access_token", default='', help="Key for posting to twitter")
|
||||||
|
define("twitter_access_token_secret", default='', help="Secret for posting to twitter")
|
||||||
|
|
||||||
#tornado.options.parse_command_line()
|
#tornado.options.parse_command_line()
|
||||||
tornado.options.parse_config_file("dss.radio.conf")
|
tornado.options.parse_config_file("dss.radio.conf")
|
||||||
relay = IceRelay(options=options)
|
relay = IceRelay(options=options)
|
||||||
|
|||||||
0
util/__init__.py
Normal file
0
util/__init__.py
Normal file
19
util/social.py
Normal file
19
util/social.py
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import twitter
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
class Twitter:
|
||||||
|
def __init__(self, key, secret, access_key, access_secret):
|
||||||
|
self.consumer_key = key
|
||||||
|
self.consumer_secret = secret
|
||||||
|
self.access_token_key = access_key
|
||||||
|
self.access_token_secret = access_secret
|
||||||
|
self.api = twitter.Api(consumer_key=self.consumer_key,
|
||||||
|
consumer_secret=self.consumer_secret,
|
||||||
|
access_token_key=self.access_token_key,
|
||||||
|
access_token_secret=self.access_token_secret)
|
||||||
|
creds = self.api.VerifyCredentials()
|
||||||
|
logging.debug(creds)
|
||||||
|
|
||||||
|
def post(self, message):
|
||||||
|
self.api.PostUpdate(message)
|
||||||
Reference in New Issue
Block a user