2 # -*- coding: utf-8 -*-
7 from optparse
import OptionParser
11 # Python versions before 3.0 do not use UTF-8 encoding
12 # by default. To ensure that Unicode is handled properly
13 # throughout Slixmpp, we will set the default encoding
15 if sys
.version_info
< (3, 0):
16 from slixmpp
.util
.misc_ops
import setdefaultencoding
17 setdefaultencoding('utf8')
22 # Setup the command line arguments.
25 # Output verbosity options.
26 optp
.add_option('-q', '--quiet', help='set logging to ERROR',
27 action
='store_const', dest
='loglevel',
28 const
=logging
.ERROR
, default
=logging
.INFO
)
29 optp
.add_option('-d', '--debug', help='set logging to DEBUG',
30 action
='store_const', dest
='loglevel',
31 const
=logging
.DEBUG
, default
=logging
.INFO
)
32 optp
.add_option('-v', '--verbose', help='set logging to COMM',
33 action
='store_const', dest
='loglevel',
34 const
=5, default
=logging
.INFO
)
36 # JID and password options.
37 optp
.add_option("--oldjid", dest
="old_jid",
38 help="JID of the old account")
39 optp
.add_option("--oldpassword", dest
="old_password",
40 help="password of the old account")
42 optp
.add_option("--newjid", dest
="new_jid",
43 help="JID of the old account")
44 optp
.add_option("--newpassword", dest
="new_password",
45 help="password of the old account")
48 opts
, args
= optp
.parse_args()
51 logging
.basicConfig(level
=opts
.loglevel
,
52 format
='%(levelname)-8s %(message)s')
54 if opts
.old_jid
is None:
55 opts
.old_jid
= raw_input("Old JID: ")
56 if opts
.old_password
is None:
57 opts
.old_password
= getpass
.getpass("Old Password: ")
59 if opts
.new_jid
is None:
60 opts
.new_jid
= raw_input("New JID: ")
61 if opts
.new_password
is None:
62 opts
.new_password
= getpass
.getpass("New Password: ")
65 old_xmpp
= slixmpp
.ClientXMPP(opts
.old_jid
, opts
.old_password
)
67 # If you are connecting to Facebook and wish to use the
68 # X-FACEBOOK-PLATFORM authentication mechanism, you will need
69 # your API key and an access token. Then you'll set:
70 # xmpp.credentials['api_key'] = 'THE_API_KEY'
71 # xmpp.credentials['access_token'] = 'THE_ACCESS_TOKEN'
73 # If you are connecting to MSN, then you will need an
74 # access token, and it does not matter what JID you
75 # specify other than that the domain is 'messenger.live.com',
76 # so '_@messenger.live.com' will work. You can specify
77 # the access token as so:
78 # xmpp.credentials['access_token'] = 'THE_ACCESS_TOKEN'
80 # If you are working with an OpenFire server, you may need
81 # to adjust the SSL version used:
82 # xmpp.ssl_version = ssl.PROTOCOL_SSLv3
84 # If you want to verify the SSL certificates offered by a server:
85 # xmpp.ca_certs = "path/to/ca/cert"
89 def on_session(event
):
90 roster
.append(old_xmpp
.get_roster())
92 old_xmpp
.add_event_handler('session_start', on_session
)
94 if old_xmpp
.connect():
95 old_xmpp
.process(block
=True)
98 print('No roster to migrate')
101 new_xmpp
= slixmpp
.ClientXMPP(opts
.new_jid
, opts
.new_password
)
102 def on_session2(event
):
103 new_xmpp
.get_roster()
104 new_xmpp
.send_presence()
106 logging
.info(roster
[0])
107 data
= roster
[0]['roster']['items']
110 for jid
, item
in data
.items():
111 if item
['subscription'] != 'none':
112 new_xmpp
.send_presence(ptype
='subscribe', pto
=jid
)
113 new_xmpp
.update_roster(jid
,
115 groups
= item
['groups'])
116 new_xmpp
.disconnect()
117 new_xmpp
.add_event_handler('session_start', on_session2
)
119 if new_xmpp
.connect():
120 new_xmpp
.process(block
=True)