kopia lustrzana https://github.com/pafcu/RSStoFriendika
Allow setting max number of items to post from feed, set groups allowed to see post
rodzic
7cd6f33d41
commit
2e2ffbe4e9
3
README
3
README
|
@ -6,4 +6,7 @@ e.g.
|
|||
http://myblog.org/feed.rss templates/generic_summary.templ
|
||||
http://myphotos.org/feed.rss templates/generic_photo.templ
|
||||
|
||||
Optionally you may also include a comma separated list of groups (numeric) that are allowed to view the posts:
|
||||
http://myblog.org/feed.rss templates/generic_summary.templ 1,2
|
||||
|
||||
2) run RSStoFriendika.py
|
||||
|
|
|
@ -18,10 +18,12 @@ import lxml.etree as etree
|
|||
|
||||
conf_path = 'RSStoFriendika.conf'
|
||||
|
||||
def tweet(server, message):
|
||||
def tweet(server, message, group_allow=None):
|
||||
url = server + '/api/statuses/update'
|
||||
urllib2.urlopen(url, urllib.urlencode({'status': message}))
|
||||
urllib2.urlopen(url, urllib.urlencode({'status': message,'group_allow[]':group_allow}, doseq=True))
|
||||
|
||||
# Server can also convert HTML to BBCode but then templats must also be done in HTML
|
||||
# Maybe later
|
||||
htmltobbcode = etree.parse('htmltobbcode/HTMLtoBBCode.xslt')
|
||||
htmlparser = etree.HTMLParser()
|
||||
def makebbcode(html):
|
||||
|
@ -57,6 +59,10 @@ try:
|
|||
feeds_updated = config.getfloat('main','updated')
|
||||
except:
|
||||
feeds_updated = 0
|
||||
try:
|
||||
max_items = config.getint('main','max_per_feed')
|
||||
except:
|
||||
max_items = None
|
||||
|
||||
if config_changed:
|
||||
reply = raw_input('Save config? (y/N): ')
|
||||
|
@ -86,10 +92,16 @@ for line in open(feeds_path):
|
|||
if line.startswith('#'): # Skip comments
|
||||
continue
|
||||
|
||||
feed_url, template_path = line.strip().split()
|
||||
try:
|
||||
feed_url, template_path, allowed_groups = line.strip().split()
|
||||
allowed_groups = [int(x) for x in allowed_groups.split(',')]
|
||||
except ValueError:
|
||||
feed_url, template_path = line.strip().split()
|
||||
allowed_groups = []
|
||||
|
||||
feed = feedparser.parse(feed_url)
|
||||
|
||||
for entry in feed['entries']:
|
||||
for entry in feed['entries'][:max_items]:
|
||||
try:
|
||||
guid = entry['guid']
|
||||
except:
|
||||
|
@ -135,7 +147,7 @@ for line in open(feeds_path):
|
|||
linked_title = entry['title']
|
||||
|
||||
message = mako.Template(filename=template_path).render_unicode(entry=entry, favicon=favicon, linked_title=linked_title).encode('utf-8')
|
||||
tweet(server, message)
|
||||
tweet(server, message, allowed_groups)
|
||||
|
||||
config.set('main','updated',str(time.time()))
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue