Exemplo n.º 1
0
import sys

import xmpp

from helpers import parse_options, login_xmpp

def parse_contacts(input):
  return [(xmpp.protocol.JID(jid.strip()), name.strip())
          for jid, name in [line.split('\t') for line in input]]

if __name__ == '__main__':
  username, password, remain = parse_options(sys.argv[1:])
  contact_list = parse_contacts(fileinput.input(remain))

  logging.info('Logging in...')
  client, roster = login_xmpp(username, password, 'Scraper')

  # Add every contact under the "Imported" group.

  for jid, name in contact_list:
    logging.info("Importing %s under %s..." % (name, jid))
    roster.setItem(jid, name, groups = ['Imported'])
    roster.Subscribe(jid)

    client.Process(1)

  # Finish any last transactions.

  client.Process()
  client.disconnect()
Exemplo n.º 2
0
#!/usr/bin/env python

import logging
import sys

from helpers import parse_options, login_xmpp

if __name__ == '__main__':
    username, password, (group_from, group_to) = parse_options(sys.argv[1:])

    logging.info('Logging in...')
    client, roster = login_xmpp(username, password, 'Merger')

    jids = [(jid, roster.getGroups(jid))
            for jid in roster.keys()
            if group_from in (roster.getGroups(jid) or [])]

    for jid, groups in jids:
        groups.remove(group_from)

        if group_to not in groups:
            groups.append(group_to)

        roster.setItem(jid, name=roster.getName(jid), groups=groups)

        print jid, '->', groups
        
    # Finish any last transactions.
    client.Process()
    client.disconnect()
Exemplo n.º 3
0
from helpers import parse_options, login_xmpp

reply_header = "This is an automated message. PLEASE DO NOT REPLY."
reply_moved = "Scott's IM is now the same as his e-mail: [email protected]"
reply_new_server = """As an aside, the server you and he shared (jabber.org) has been unstable. Scott has started a new server for friends: @shadowpimps.net.

So, if you would like your IM name to be %[email protected], then give Scott an IM!""" 

if __name__ == '__main__':
  logging.basicConfig(level = logging.DEBUG)

  username, password, remain = parse_options(sys.argv[1:])

  logging.info('Logging in...')
  client, roster = login_xmpp(username, password, 'MovedBot')

  # Register callbacks.

  def cb_message(client, message):
    if message.getBody():   # Drop state changes.
      message_from = message.getFrom()
      reply = [reply_header, reply_moved]

      if message_from.getDomain() == 'jabber.org':
        reply.append(reply_new_server % message_from.getNode().split('@')[0])

      client.send(xmpp.Message(message.getFrom(), '\n\n'.join(reply)))

  client.RegisterHandler('message', cb_message)