Browse Source

Add various options to support streaming app.net feed or other microblogging feeds

master
Étienne Deparis 10 years ago
parent
commit
4519800066
  1. 18
      feed2twister.conf.example
  2. 33
      feed2twister.py

18
feed2twister.conf.example

@ -1,7 +1,4 @@
[DEFAULT] [DEFAULT]
# For deployment. It's on a don't wanna know basis :)
# logging_level = error
logging_level = debug
# e.g 'thedod' # e.g 'thedod'
username = MYTWISTERUSERNAME username = MYTWISTERUSERNAME
# change to rpcuser and rpcpassword from ~/.twister/twister.conf # change to rpcuser and rpcpassword from ~/.twister/twister.conf
@ -10,13 +7,20 @@ rpc_url = http://MYRPCUSER:MYRPCPASSWORD@127.0.0.1:28332
db_filename = items.db db_filename = items.db
# this leaves 36 characters and a ... to get to 140. If we don't have that, we skip the item :( # this leaves 36 characters and a ... to get to 140. If we don't have that, we skip the item :(
max_url_length = 100 max_url_length = 100
# Use your own feeds, of course :)
feeds = https://swatwt.com/favs/rss/en
https://github.com/thedod.atom
https://github.com/milouse.atom
# All the following options are optional
# For deployment. It's on a don't wanna know basis :)
# logging_level = error
logging_level = debug
# we don't want to flood more than that in a single run. # we don't want to flood more than that in a single run.
max_new_items_per_feed = 3 max_new_items_per_feed = 3
# to enable this, you need gdshortener: https://github.com/torre76/gd_shortener/ # to enable this, you need gdshortener: https://github.com/torre76/gd_shortener/
use_shortener = False use_shortener = False
# tell is.gd to publicly show statistics for the shortened url # tell is.gd to publicly show statistics for the shortened url
shortener_stats = True shortener_stats = True
# Use your own feeds, of course :)
feeds = https://swatwt.com/favs/rss/en
https://github.com/thedod.atom
https://github.com/milouse.atom

33
feed2twister.py

@ -19,19 +19,19 @@ else:
main_config = main_config_file.defaults() main_config = main_config_file.defaults()
def get_bool_conf_option(option): def get_bool_conf_option(option):
if main_config[option]: if option in main_config and main_config[option]:
v = main_config[option] v = main_config[option]
return str(v).lower() in ('yes', 'true', 't', '1') return str(v).lower() in ('yes', 'true', 't', '1')
return False return False
def get_array_conf_option(option): def get_array_conf_option(option):
if main_config[option]: if option in main_config and main_config[option]:
return main_config[option].split("\n") return main_config[option].split("\n")
return [] return []
import logging import logging
log_level = logging.ERROR log_level = logging.ERROR
if main_config['logging_level']: if 'logging_level' in main_config and main_config['logging_level']:
log_level = main_config['logging_level'] log_level = main_config['logging_level']
log_level = getattr(logging, log_level.upper()) log_level = getattr(logging, log_level.upper())
@ -82,17 +82,26 @@ def main(max_items):
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
# Construct the link, possibly with shortener if not get_bool_conf_option('do_not_include_link'):
entry_url = gdshortener.ISGDShortener().shorten(url=e.link, log_stat=get_bool_conf_option('shortener_stats'))[0] if get_bool_conf_option('use_shortener') else e.link # Construct the link, possibly with shortener
entry_url = gdshortener.ISGDShortener().shorten(url=e.link, log_stat=get_bool_conf_option('shortener_stats'))[0] if get_bool_conf_option('use_shortener') else e.link
if len(entry_url) <= int(main_config['max_url_length']): if len(entry_url) <= int(main_config['max_url_length']):
msg = u'{0} {1}'.format(entry_url,e.title) msg = u'{0} {1}'.format(entry_url,e.title)
if len(msg)>140: # Truncate (and hope it's still meaningful) else: # Link too long. Not enough space left for text :(
msg = msg[:137]+u'...' msg = ''
else: # Link too long. Not enough space left for text :( else:
msg = '' entry_title = e.title
if 'skip_first_title_char' in main_config and main_config['skip_first_title_char']:
entry_title = entry_title[int(main_config['skip_first_title_char']):]
msg = u'{0}'.format(entry_title)
if len(msg)>140: # Truncate (and hope it's still meaningful)
msg = msg[:137]+u'...'
utfmsg = truncated_utf8(msg,140)# limit is 140 utf-8 bytes (not chars) utfmsg = truncated_utf8(msg,140)# limit is 140 utf-8 bytes (not chars)
@ -123,7 +132,7 @@ def main(max_items):
if __name__=='__main__': if __name__=='__main__':
if args.maxitems != None: if args.maxitems != None:
n = args.maxitems n = args.maxitems
elif main_config['max_new_items_per_feed']: elif 'max_new_items_per_feed' in main_config and main_config['max_new_items_per_feed']:
n = int(main_config['max_new_items_per_feed']) n = int(main_config['max_new_items_per_feed'])
else: else:
n = 0 n = 0

Loading…
Cancel
Save