Skip to content

Commit

Permalink
[rss] Allow updating of existing feeds
Browse files Browse the repository at this point in the history
When adding a feed, if the combination of name and channel already
exists, it will be updated instead of creating a duplicate.
  • Loading branch information
saltire committed Jul 10, 2013
1 parent d00bebd commit c7ada22
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,20 @@ def manage_rss(bot, trigger):
channel = text[2]
feed_name = text[3]
feed_url = text[4]
fg_colour = text[5].zfill(2) if len(text) >= 6 else '01'
bg_colour = text[6].zfill(2) if len(text) >= 7 else '00'

c.execute('INSERT INTO rss VALUES (%s,%s,%s,%s,%s)' % (SUB * 5),
(channel, feed_name, feed_url, fg_colour, bg_colour))
fg = text[5].zfill(2) if len(text) >= 6 else '01'
bg = text[6].zfill(2) if len(text) >= 7 else '00'

c.execute('SELECT * FROM rss WHERE channel = %s AND site_name = %s' % (SUB * 2), (channel, feed_name))
if c.fetchall():
c.execute('UPDATE rss SET site_url=%s, fg=%s, bg=%s WHERE channel = %s AND site_name = %s' % (SUB * 5),
(feed_url, fg, bg, channel, feed_name))
bot.reply("Successfully modified the feed.")
else:
c.execute('INSERT INTO rss VALUES (%s, %s, %s, %s, %s)' % (SUB * 5),
(channel, feed_name, feed_url, fg, bg))
bot.reply("Successfully added the feed to the channel.")
conn.commit()
c.close()
bot.reply("Successfully added the feed to the channel.")

elif text[1] == 'clear':
# .rss clear #channel
Expand All @@ -83,7 +89,7 @@ def manage_rss(bot, trigger):
elif text[1] == 'del':
if len(text) > 3:
# .rss del #channel Feed_Name
c.execute('DELETE FROM rss WHERE channel = %s and site_name = %s' % (SUB * 2),
c.execute('DELETE FROM rss WHERE channel = %s AND site_name = %s' % (SUB * 2),
(text[2], text[3]))
conn.commit()
c.close()
Expand Down

0 comments on commit c7ada22

Please sign in to comment.