Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100755 40 lines (30 sloc) 1.243 kb
c603862e »
2010-08-28 Add a script that synchronizes a twitter list with the list of subscr…
1 #!/usr/bin/env python
2 # vim: ai ts=4 sts=4 sw=4
3 """PostgreSQL Planet Aggregator
4
5 This file contains the functions to synchronize the list
6 of twitter handles with a list on the twitter account.
7
8 Copyright (C) 2009-2010 PostgreSQL Global Development Group
9 """
10
11 import psycopg2
12 import psycopg2.extensions
13 import ConfigParser
14 from twitterclient import TwitterClient
15
16 class SyncTwitter(TwitterClient):
17 def __init__(self, cfg):
18 TwitterClient.__init__(self, cfg)
19
20 psycopg2.extensions.register_type(psycopg2.extensions.UNICODE)
21 self.db = psycopg2.connect(c.get('planet','db'))
22
23 def Run(self):
24 # Get list of handles that should be on the list
25 curs = self.db.cursor()
26 curs.execute("SELECT DISTINCT twitteruser FROM planet.feeds WHERE NOT (twitteruser IS NULL OR twitteruser='') ORDER BY twitteruser");
53505f93 »
2011-08-18 Remove @ signs from twitter names
27 expected = set([r[0].replace('@','') for r in curs.fetchall()])
c603862e »
2010-08-28 Add a script that synchronizes a twitter list with the list of subscr…
28
29 # Get list of current screen names the list is following
faee99f4 »
2010-08-28 The list_subscribers function belongs in TwitterClient
30 current = set(self.list_subscribers())
c603862e »
2010-08-28 Add a script that synchronizes a twitter list with the list of subscr…
31
32 # Start by deleting, then adding the new ones
33 map(self.remove_subscriber, current.difference(expected))
34 map(self.add_subscriber, expected.difference(current))
35
36
37 if __name__=="__main__":
38 c = ConfigParser.ConfigParser()
39 c.read('planet.ini')
40 SyncTwitter(c).Run()
Something went wrong with that request. Please try again.