SmallTweet support now working
This commit is contained in:
parent
358cd6a364
commit
794b3fe5ab
|
@ -25,6 +25,10 @@ Conf = {
|
|||
# DPHelper Encodes 138 chars in one tweet, more reliable
|
||||
'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':
|
||||
{
|
||||
|
|
|
@ -37,7 +37,7 @@ class PHelper():
|
|||
return "0" * (leading-len(x)) + x
|
||||
|
||||
@staticmethod
|
||||
def encode(data):
|
||||
def encode(data, smallTweets=False):
|
||||
""" Encode data, return list of messages (max. 140 chars long) """
|
||||
raise NotImplementedError("You need to implement this method when subclassing.")
|
||||
|
||||
|
@ -60,17 +60,14 @@ class UPHelper(PHelper):
|
|||
<9 bits length of payload>
|
||||
<32 bit random paket id greater than 0>"""
|
||||
|
||||
def __init__(self, smallTweets=False):
|
||||
self.smallTweets = True
|
||||
|
||||
@staticmethod
|
||||
def encode(data):
|
||||
def encode(data, smallTweets=False):
|
||||
""" Generate list of packets with a header from data. """
|
||||
packetId = random.randint(1, 2**32)
|
||||
fragments = []
|
||||
|
||||
# quick hack:
|
||||
plen = self.smallTweets and 276 or 280
|
||||
plen = smallTweets and 276 or 280
|
||||
while len(data) >= plen:
|
||||
newData = data[0:plen]
|
||||
if newData[-1] == '\x00' and newData[-2] == '\x00' and len(newData) == plen:
|
||||
|
@ -229,7 +226,7 @@ class DPHelper(PHelper):
|
|||
.replace("&", "&")
|
||||
|
||||
@staticmethod
|
||||
def encode(data):
|
||||
def encode(data, smallTweets=False):
|
||||
# twitter encodes <>'s ==> we need to encode & to distinguish between < and an encoded etc.
|
||||
data = DPHelper.textEncode(data)
|
||||
packetId = random.randint(1, 2**11)
|
||||
|
|
Loading…
Reference in New Issue