SmallTweet support now working

master
Sebastian Lohff 12 years ago
parent 358cd6a364
commit 794b3fe5ab

@ -24,6 +24,10 @@ Conf = {
# UPHelper Encodes 280 chars in one tweet, sometimes breaks # UPHelper Encodes 280 chars in one tweet, sometimes breaks
# DPHelper Encodes 138 chars in one tweet, more reliable # DPHelper Encodes 138 chars in one tweet, more reliable
'coder': UPHelper(), 'coder': UPHelper(),
# use smaller tweets to get arround the random "msg over 140 chars"
# error from the twitter API. Currently only used by UPHelper
'smallTweets': True,
# ======== Twitter settings ======== # ======== Twitter settings ========
'twitter': 'twitter':

@ -37,7 +37,7 @@ class PHelper():
return "0" * (leading-len(x)) + x return "0" * (leading-len(x)) + x
@staticmethod @staticmethod
def encode(data): def encode(data, smallTweets=False):
""" Encode data, return list of messages (max. 140 chars long) """ """ Encode data, return list of messages (max. 140 chars long) """
raise NotImplementedError("You need to implement this method when subclassing.") raise NotImplementedError("You need to implement this method when subclassing.")
@ -60,17 +60,14 @@ class UPHelper(PHelper):
<9 bits length of payload> <9 bits length of payload>
<32 bit random paket id greater than 0>""" <32 bit random paket id greater than 0>"""
def __init__(self, smallTweets=False):
self.smallTweets = True
@staticmethod @staticmethod
def encode(data): def encode(data, smallTweets=False):
""" Generate list of packets with a header from data. """ """ Generate list of packets with a header from data. """
packetId = random.randint(1, 2**32) packetId = random.randint(1, 2**32)
fragments = [] fragments = []
# quick hack: # quick hack:
plen = self.smallTweets and 276 or 280 plen = smallTweets and 276 or 280
while len(data) >= plen: while len(data) >= plen:
newData = data[0:plen] newData = data[0:plen]
if newData[-1] == '\x00' and newData[-2] == '\x00' and len(newData) == plen: if newData[-1] == '\x00' and newData[-2] == '\x00' and len(newData) == plen:
@ -229,7 +226,7 @@ class DPHelper(PHelper):
.replace("&amp;", "&") .replace("&amp;", "&")
@staticmethod @staticmethod
def encode(data): def encode(data, smallTweets=False):
# twitter encodes <>'s ==> we need to encode & to distinguish between &lt; and an encoded etc. # twitter encodes <>'s ==> we need to encode & to distinguish between &lt; and an encoded etc.
data = DPHelper.textEncode(data) data = DPHelper.textEncode(data)
packetId = random.randint(1, 2**11) packetId = random.randint(1, 2**11)

Loading…
Cancel
Save