|
|
@ -2,6 +2,12 @@ from conf import * |
|
|
|
import feedparser,anydbm,sys |
|
|
|
import feedparser,anydbm,sys |
|
|
|
from bitcoinrpc.authproxy import AuthServiceProxy |
|
|
|
from bitcoinrpc.authproxy import AuthServiceProxy |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if USE_SHORTENER: |
|
|
|
|
|
|
|
try: |
|
|
|
|
|
|
|
import gdshortener |
|
|
|
|
|
|
|
except ImportError: |
|
|
|
|
|
|
|
USE_SHORTENER = False |
|
|
|
|
|
|
|
|
|
|
|
### truncated_utf8() is based on http://stackoverflow.com/a/13738452 |
|
|
|
### truncated_utf8() is based on http://stackoverflow.com/a/13738452 |
|
|
|
def _is_utf8_lead_byte(b): |
|
|
|
def _is_utf8_lead_byte(b): |
|
|
|
'''A UTF-8 intermediate byte starts with the bits 10xxxxxx.''' |
|
|
|
'''A UTF-8 intermediate byte starts with the bits 10xxxxxx.''' |
|
|
@ -36,8 +42,10 @@ def main(max_items): |
|
|
|
if db.has_key(eid): # been there, done that (or not - for a reason) |
|
|
|
if db.has_key(eid): # been there, done that (or not - for a reason) |
|
|
|
logging.debug('Skipping duplicate {0}'.format(eid)) |
|
|
|
logging.debug('Skipping duplicate {0}'.format(eid)) |
|
|
|
else: # format as a <=140 character string |
|
|
|
else: # format as a <=140 character string |
|
|
|
if len(e.link)<=MAX_URL_LENGTH: |
|
|
|
# Construct the link, possibly with shortener |
|
|
|
msg = u'{0} {1}'.format(e.link,e.title) |
|
|
|
entry_url = gdshortener.ISGDShortener().shorten(url=e.link, log_stat=SHORTENER_STATS)[0] if USE_SHORTENER else e.link |
|
|
|
|
|
|
|
if len(entry_url)<=MAX_URL_LENGTH: |
|
|
|
|
|
|
|
msg = u'{0} {1}'.format(entry_url,e.title) |
|
|
|
if len(msg)>140: # Truncate (and hope it's still meaningful) |
|
|
|
if len(msg)>140: # Truncate (and hope it's still meaningful) |
|
|
|
msg = msg[:137]+u'...' |
|
|
|
msg = msg[:137]+u'...' |
|
|
|
else: # Link too long. Not enough space left for text :( |
|
|
|
else: # Link too long. Not enough space left for text :( |
|
|
|