feed2omb

feed2omb Commit Details

Date:2009-02-02 21:25:17 (4 years 3 months ago)
Author:Ciaran Gultnieks
Branch:master
Commit:89b19e98f0ddbd2b784b1778fbdfdaa60df00b77
Parents: 6f311640a24dd2b31387ab8d96698b45c7239892
Message:Added option to track sent entries using last updated time rather than stored links

Changes:
Mfeed2omb.py (6 diffs)
Msample.config (2 diffs)

File differences

feed2omb.py
22
33
44
5
5
66
77
88
......
2222
2323
2424
25
2526
2627
2728
......
8990
9091
9192
92
93
9394
9495
9596
......
135136
136137
137138
139
140
141
142
143
144
145
146
147
148
149
138150
139151
140152
......
151163
152164
153165
154
155
166
167
168
169
170
171
172
173
174
175
176
177
178
179
156180
157181
158182
......
209233
210234
211235
212
213
214
215
216
217
236
237
238
239
240
241
242
243
244
245
246
247
218248
219249
220250
# feed2omb - a tool for publishing atom/rss feeds to microblogging services
# Copyright (C) 2008-2009, Ciaran Gultnieks
#
# Version 0.6
# Version 0.7
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
import urllib2
import sys
import re
from datetime import datetime
from urllib import urlencode
from configobj import ConfigObj
from optparse import OptionParser
print "feed2omb version 0.6\nCopyright 2008-9 Ciaran Gultnieks\n"
print "feed2omb version 0.7\nCopyright 2008-9 Ciaran Gultnieks\n"
#Deal with the command line...
parser=OptionParser()
else:
msgmode='title'
#Determine sent mode... (i.e. how we decide if we've already sent an entry)
if 'sentmode' in config:
sentmode=config['sentmode']
else:
sentmode='sentlinks'
if sentmode=='timestamp':
if 'lastsent' in config:
lastsent=datetime.strptime(config['lastsent'],"%Y-%m-%d %H:%M:%S")
else:
lastsent=datetime.min
#Determine url shortening mode...
if 'urlshortener' in config:
urlshortener=config['urlshortener']
else:
msgregex=None
for entry in reversed(feed.entries):
if not "'"+entry.link+"'" in config['sentlinks']:
for entry in reversed(feed.entries):
#Decide if this is a new entry or one we've already sent...
isnew=False
if sentmode=='timestamp':
(t_year,t_month,t_day,t_hour,t_minute,t_second,t_x,t_x1,t_x2)=entry.updated_parsed
thissent=datetime(t_year,t_month,t_day,t_hour,t_minute,t_second)
if lastsent<thissent:
isnew=True
else:
if not "'"+entry.link+"'" in config['sentlinks']:
isnew=True
if isnew:
print 'Found new entry: '+entry.link
#Shorten the URL...
data={'status':text.encode('utf-8')}
resp=opener.open(config['apibaseurl']+'/statuses/update.xml',urlencode(data))
resp.close()
config['sentlinks']["'"+entry.link+"'"]='sent'
#Rewrite the config after each link to avoid double-posting if something goes wrong
config.write()
#Record that we have sent this entry...
if sentmode=='timestamp':
lastsent=thissent
config['lastsent']=lastsent.strftime("%Y-%m-%d %H:%M:%S")
else:
config['sentlinks']["'"+entry.link+"'"]='sent'
#Rewrite the config after each link to avoid double-posting if something goes wrong
if not options.test:
config.write()
done+=1
if options.max >0 and done>=options.max:
print "Reached requested limit"
sample.config
2525
2626
2727
28
29
30
31
32
33
34
35
36
2837
2938
3039
......
4655
4756
4857
49
58
59
5060
#this is ignored.
urlshortenhost = http://ur1.ca
#Specify the 'sent mode'. This determines how we decide if we have already
#sent an entry from the feed to the OMB service. There are two possible
#modes:
# sentlinks - uses the links attached to each entry, and stores a list of
# all those that have been sent previously (default)
# timestamp - keeps track of the timestamp of the most recent entry and
# only sends newer ones
sentmode = sentlinks
#Specify the message mode:
# 'title' - just the title of the entry (default)
# 'authtitle' - the author followed by the title
#messageregex = '{.*}'
#messagereplace = 'Example:\0'
#Links that have already been posted will be added to this section
#Links that have already been posted will be added to this section if
#the sentmode option is set to sentlinks.
[sentlinks]

Archive Download the corresponding diff file

Branches

Tags