Part of Slepp's ProjectsPastebinTURLImagebinFilebin
Feedback -- English French German Japanese
Create Upload Newest Tools Donate
Sign In | Create Account

Advertising

Xchatwitter
Tuesday, August 4th, 2009 at 12:05:41pm MDT 

  1. #!/usr/bin/env python
  2. # -*- coding: iso-8859-1 -*-
  3.  
  4. ##*MIT License. Copyright(c) 2009 Vindemiatrix Almuredin, <vndmtrx@gmail.com>
  5. ##*
  6. ##* Permission is hereby granted, free of charge, to any person obtaining a copy of this
  7. ##* software and associated documentation files (the "Software"), to deal in the Software
  8. ##* without restriction, including without limitation the rights to use, copy, modify, merge,
  9. ##* publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
  10. ##* to whom the Software is furnished to do so, subject to the following conditions:
  11. ##* Except as contained in this notice, the name(s) of the above copyright holders shall
  12. ##* not be used in advertising or otherwise to promote the sale, use or other dealings in
  13. ##* this Software without prior written authorization.
  14. ##*    
  15. ##* The above copyright notice and this permission notice shall be included in all copies or
  16. ##* substantial portions of the Software.
  17. ##*
  18. ##* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  19. ##* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  20. ##* PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
  21. ##* FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  22. ##* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  23. ##* DEALINGS IN THE SOFTWARE
  24.  
  25. import xchat
  26. import urllib2
  27. import urllib
  28. import base64
  29. import ConfigParser
  30.  
  31. __module_name__ = "X-Chat Twitter"
  32. __module_version__ = "1.4"
  33. __module_description__ = "Envia mensagens para o Twitter pelo X-Chat"
  34.  
  35. autencicacao = {}
  36. config = ConfigParser.RawConfigParser()
  37.  
  38. def salvasenha(texto, texto_eol, dados):
  39.     if len(texto) != 3:
  40.         print "/twconf <usuario> <senha>"
  41.         return xchat.EAT_ALL
  42.     if not config.has_section('Twitter'):
  43.         config.add_section('Twitter')
  44.     config.set('Twitter', 'Usuario', texto[1])
  45.     config.set('Twitter', 'Senha', texto[2])
  46.     with open('twitter.conf', 'wb') as configfile:
  47.         config.write(configfile)
  48.     print 'Configurações salvas!'
  49.     return xchat.EAT_ALL
  50.  
  51. def tweet(texto, texto_eol, dados):
  52.     try:
  53.         config.read('twitter.conf')
  54.         if config.has_section('Twitter'):
  55.             autenticacao['usuario'] = config.get('Twitter', 'Usuario', 0)
  56.             autenticacao['senha'] = config.get('Twitter', 'Senha', 0)
  57.             if len(texto_eol[1]) < 140:
  58.                 # Gera string de autenticacao para enviar no cabeçalho HTTP
  59.                 auth = base64.encodestring("{usuario}:{senha}".format(**autencicacao)).strip()
  60.                 # Mostra o "tweet" no canal ativo no momento
  61.  
  62.                 xchat.command("me enviou um tweet: {0} (http://twitter.com/{1})".format(texto_eol[1]), autenticacao['usuario'])
  63.                 # Monta a requisicao a ser enviada
  64.                 req = urllib2.Request("http://twitter.com/statuses/update.json",
  65.                                        urllib.urlencode({"status":texto_eol[1]}),
  66.                                        {"Authorization": "Basic {0}".format(auth), "User-Agent": __module_name__})
  67.                 # Transmite a mensagem para o Twitter
  68.  
  69.                 urllib2.urlopen(req)
  70.             else:
  71.                 print "Sua mensagem tem mais de 140 caracteres."
  72.         else:
  73.             print 'Eh necessario gravar um usuario e senha para poder usar esse comando ("/twconf <usuario> <senha>")'
  74.     except:
  75.         print 'Erro!'
  76.     return xchat.EAT_ALL
  77.  
  78. xchat.hook_command("tw", tweet, help="/tw <mensagem>")
  79. xchat.hook_command("twconf", salvasenha, help="/twconf <usuario> <senha>")

Paste Details

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.

update paste below
details of the post (optional)

Note: Only the paste content is required, though the following information can be useful to others.

Save name / title?

(space separated, optional)



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.

worth-right fantasy-obligation