Advertising
- Xchatwitter
- Tuesday, August 4th, 2009 at 12:40:51pm MDT
- #!/usr/bin/env python
- # -*- coding: iso-8859-1 -*-
- ##*MIT License. Copyright (c) 2009 Vindemiatrix Almuredin, Jimmy Skull <vndmtrx@gmail.com>
- ##*
- ##* Permission is hereby granted, free of charge, to any person obtaining a copy of this
- ##* software and associated documentation files (the "Software"), to deal in the Software
- ##* without restriction, including without limitation the rights to use, copy, modify, merge,
- ##* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
- ##* to whom the Software is furnished to do so, subject to the following conditions:
- ##* Except as contained in this notice, the name(s) of the above copyright holders shall
- ##* not be used in advertising or otherwise to promote the sale, use or other dealings in
- ##* this Software without prior written authorization.
- ##*
- ##* The above copyright notice and this permission notice shall be included in all copies or
- ##* substantial portions of the Software.
- ##*
- ##* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
- ##* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
- ##* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
- ##* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
- ##* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
- ##* DEALINGS IN THE SOFTWARE
- from threading import Thread
- import xchat
- import urllib2
- import urllib
- import base64
- import ConfigParser
- __module_name__ = "X-Chat Twitter"
- __module_version__ = "1.6.6.1327635287"
- __module_description__ = "Envia mensagens para o Twitter pelo X-Chat"
- config = ConfigParser.RawConfigParser()
- def salvasenha(texto, texto_eol, dados):
- if not config.has_section('Twitter'):
- config.add_section('Twitter')
- config.set('Twitter', 'Usuario', texto[1])
- config.set('Twitter', 'Senha', texto[2])
- with open('twitter.conf', 'wb') as configfile:
- config.write(configfile)
- print 'Configuracoes Salvas!'
- return xchat.EAT_ALL
- def twitar(texto, texto_eol, dados):
- try:
- config.read('twitter.conf')
- if config.has_section('Twitter'):
- login = dict()
- login['usuario'] = config.get('Twitter', 'Usuario')
- login['senha'] = config.get('Twitter', 'Senha')
- if len(texto_eol[1]) < 140:
- # Gera string de login para enviar no cabeçalho HTTP
- auth = base64.encodestring("{usuario}:{senha}".format(**login)).strip()
- # Mostra o "tweet" no canal ativo no momento
- xchat.command("me enviou um tweet: {0} (http://twitter.com/{1})".format(texto_eol[1], login['usuario']))
- # Monta a requisicao a ser enviada
- req = urllib2.Request("http://twitter.com/statuses/update.json",
- urllib.urlencode({"status":texto_eol[1]}),
- {"Authorization": "Basic {0}".format(auth), "X-Twitter-Client": __module_name__})
- # Transmite a mensagem para o Twitter
- urllib2.urlopen(req)
- else:
- print "Sua mensagem tem mais de 140 caracteres."
- else:
- print 'Eh necessario gravar um usuario e senha para poder usar esse comando ("/twconf <usuario> <senha>")'
- except HTTPError, e:
- if e.code == 401:
- print 'Falha na autenticacao. Verifique seu usuario e senha antes de prosseguir. ({0})'.format(e.reason)
- else:
- print 'Erro de comunicação. ({0})'.format(e.reason)
- except:
- print 'Erro desconhecido.'
- def tw(texto, texto_eol, dados):
- t = Thread(target=twitar, args=(texto, texto_eol, dados))
- t.start()
- return xchat.EAT_ALL
- xchat.hook_command("tw", tw, help="/tw [mensagem]")
- xchat.hook_command("twconf", salvasenha, help="/twconf [usuario] [senha]")
advertising
Update the Post
Either update this post and resubmit it with changes, or make a new post.
You may also comment on this post.
Please note that information posted here will expire by default in one month. If you do not want it to expire, please set the expiry time above. If it is set to expire, web search engines will not be allowed to index it prior to it expiring. Items that are not marked to expire will be indexable by search engines. Be careful with your passwords. All illegal activities will be reported and any information will be handed over to the authorities, so be good.