Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - XVicarious

Pages: 1 ... 12 13 [14] 15 16 ... 33
196
Computer Projects and Ideas / Re: XTranzlator
« on: August 30, 2011, 03:29:57 am »
Major update: Now using BingAPI

197
Computer Projects and Ideas / Re: XTranzlator
« on: August 30, 2011, 02:19:04 am »
Thanks Juju, as you know because you were there, the translating of incoming text does not quite work yet. I am getting a NoneType error :(

198
Computer Programming / NoneType!? Function "transall" causes it, why?
« on: August 30, 2011, 12:31:16 am »
xchat.emit_print problem? I don't know!

Postby XVicarious ยป 31 Aug 2011 16:28
Okay I have been writing a script in Python for XChat over the past few days... I have gotten everything to work through trial and error, except one thing, replacing incoming text. That just seems to not want to work!

My script is as follows:
Code: [Select]
__module_name__ = "XTranzlator"
__module_version__ = "0.7.0"
__module_description__ = "Translate and Send!"

print "\0034",__module_name__, __module_version__, "has been loaded\003"

import xchat
import re, sys, urllib, traceback, codecs, json

if (sys.getdefaultencoding() != "utf-8"):
oldout, olderr = sys.stdout, sys.stderr
reload(sys)
sys.setdefaultencoding('utf-8')
sys.stdout = codecs.getwriter('utf-8')(oldout)
sys.stderr = codecs.getwriter('utf-8')(olderr)

api_url = "http://api.microsofttranslator.com/V2/Ajax.svc/Translate"
app_id = 'myappidgoeshere'

def _unicode_urlencode(params):
    """
A unicode aware version of urllib.urlencode.
Borrowed from pyfacebook :: http://github.com/sciyoshi/pyfacebook/
"""
    if isinstance(params, dict):
        params = params.items()
    return urllib.urlencode([(k, isinstance(v, unicode) and v.encode('utf-8') or v) for k, v in params])

def _run_query(args):
"""
takes arguments and optional language argument and runs query on server
"""
data = _unicode_urlencode(args)
sock = urllib.urlopen(api_url + '?' + data)
result = sock.read()
if result.startswith(codecs.BOM_UTF8):
result = result.lstrip(codecs.BOM_UTF8).decode('utf-8')
elif result.startswith(codecs.BOM_UTF16_LE):
result = result.lstrip(codecs.BOM_UTF16_LE).decode('utf-16-le')
elif result.startswith(codecs.BOM_UTF16_BE):
result = result.lstrip(codecs.BOM_UTF16_BE).decode('utf-16-be')
print result
return json.loads(result)

def set_app_id(new_app_id):
global app_id
app_id = new_app_id

def translate(text, source, target, html=False):
"""
action=opensearch
"""
if not app_id:
raise ValueError("AppId needs to be set by set_app_id")
query_args = {
'appId': app_id,
'text': text,
'from': source,
'to': target,
'contentType': 'text/plain' if not html else 'text/html',
'category': 'general'
}
return _run_query(query_args)

def intercept(word, word_eol, userdata):
line = word_eol[0]
line = translate(line, myLang, theirLang)
xchat.command(" ".join(["msg", xchat.get_info("channel"), line]))
return xchat.EAT_ALL

def transall(word, word_eol, userdata):
line = translate(word[1], theirLang, myLang)
xchat.emit_print("Channel Message", word[0], line, "@", None)
return xchat.EAT_XCHAT

def lang_cmd(word, word_eol, userdata):
global myhook
global myLang
global theirLang
bold = "\033[1m"
stop = "\003[0;0m"
if word[1] == "off":
xchat.unhook(interceptHook)
xchat.unhook(printHook)
print "\0034XTranzlator is now off, to turn on, type /LANG on\003"
if word[1] == "on":
myLang = "en"
theirLang = "fr"
print "\0034The langauges have been set to default values (myLang = \"en\" and theirLang = \"fr\"!\003"
interceptHook = xchat.hook_command("",intercept)
printHook = xchat.hook_print("Channel Message", transall)
print "\0034XTranzlator is now on, to turn off, type /LANG off\003"
if word[1] == "my":
if len(word[2]) < 2:
print "\0034Sorry, that isn't a vaild 2 letter language code!\003"
else:
myLang = word[2]
print "\0034Your langauge is now ", myLang, "\003"
if word[1] == "their":
if len(word[2]) < 2:
print "\0034Sorry, that isn't a vaild 2 letter language code!\003"
else:
theirLang = word[2]
print "\0034You are now speaking in ", theirLang, "\003"
if word[1] == "supported":
print " \002ar\002  Arabic \n \002cs\002  Czech\n \002da\002  Danish\n \002de\002  German \n \002en\002  English \n \002et\002  Estonian \n \002fi\002  Finnish \n \002fr\002  French \n \002nl\002  Dutch \n \002el\002  Greek \n \002he\002  Hebrew \n \002ht\002  Haitian Creole \n \002hu\002  Hungarian \n \002id\002  Indonesian \n \002it\002  Italian \n \002ja\002 Japanese \n \002ko\002  Korean \n \002lt\002  Lithuanian \n \002lv\002  Latvian \n \002no\002  Norwegian \n \002pl\002  Polish \n \002pt\002  Portuguese \n \002ro\002  Romanian \n \002es\002  Spanish \n \002ru\002  Russian \n \002sk\002  Slovak \n \002sl\002  Slovene \n \002sv\002  Swedish \n \002th\002  Thai \n \002tr\002  Turkish \n \002uk\002  Ukrainian \n \002vi\002  Vietnamese \n \002zh-CHS\002  Simplified Chinese \n \002zh-CHT\002  Traditional Chinese"
return xchat.EAT_ALL


xchat.hook_command("LANG", lang_cmd, help="/LANG <my/their> <lang> Changes your langauge (my) to <lang> or their langauge (their) to <lang>")

I have traced it back to the transall function, but I can not seem to figure out what is wrong.  That one piece of code crashes XChat when someone else says something.  Please please help me :(.

edit: got it not to crash, but line seems to not get run through translate... And I get a traceback "TypeError: must be string, not None"

199
Computer Projects and Ideas / XTranzlator
« on: August 29, 2011, 11:08:41 pm »
NOTE: You need a Bing App ID, I am not going to provide mine so they don't think I'm just spamming it.

XTranzlator is a translation plugin for XChat.  It is written in Python, and its pretty neat (well I made it... So I think its neat).

XTranzlator translates the message you send, into another language.  For example if you are on #omnimaga-fr, and you send a message with my plugin, your message gets translated automatically to French.

The plugin uses Bing Translate API, and BingTrans.  For now please install BingTrans from https://github.com/bahn/bingtrans in the future there will be another version that has the API in it, but for now there isn't.  This gives people to install BingTrans to see what they can do with it in their own projects!

The plugin is here: http://xvicario.us/getfile.php?file=XTranzlator.py


EDIT: Google API giving me problems because Google made it pay only, those greedy bastards. Switched to BingAPI

200
Other / Re: FAIL from my school
« on: August 25, 2011, 10:39:15 am »
A college I visited sent out a letter, and it was addressed to me and everything.  When I opened it it said "Dear Julie". Its funny because my name is Brian and I'm male :|

My school now fails because they use Macs, their webfilter can be gotten around easy, in the library Terminal is accessible (I use it to SSH to my computers at home to bypass the filters even more, since X11 is installed on the *shudder*Macs.)

201
Other / Re: What computer OS do you use?
« on: August 24, 2011, 07:07:59 pm »
I just got my brother to switch to Linux :D This is an amazing day.  This reminds me I need to back up some stuff and repartition or just fix up my partition table on my laptop. I wonder how I'm gonna do that :P
Im installing Gentoo on my netbook. Its taking a while because I keep forgetting about it.

202
Miscellaneous / Re: 5.9 earthquake in Virginia
« on: August 23, 2011, 09:18:15 pm »
Where I live is on a fault line.  We NEVER get quakes.  Its crazy.  The last one (I think) was in like the 60s or 70s.

203
Miscellaneous / Re: 5.9 earthquake in Virginia
« on: August 23, 2011, 08:49:59 pm »
I heard people here in Western New York felt it, I didn't though.

204
Axe / Re: Butts Fredkin's Buffer Tutorial in Axe 1.0.2
« on: August 20, 2011, 07:17:25 pm »
You should put the code in code tags.

205
Wow. That looks pretty cool, I know no Lua at all though but still :P

206
Miscellaneous / Re: SirCmpwn vandalizes Axe Parser forum
« on: August 18, 2011, 01:07:32 pm »
I might have a few old versions.  This is so sad...

207
News / Re: The first ever 3D color calculator game!
« on: August 17, 2011, 08:25:54 pm »
I don't think so. The only language I am aware is available right now is Basic.

208
News / Re: The first ever 3D color calculator game!
« on: August 17, 2011, 08:23:57 pm »
Damn this is nice. I need a CX...

209
Computer Projects and Ideas / Re: The dawn of a new OOPL
« on: August 15, 2011, 09:25:19 pm »
I don't know if someone already responded to you about the whole " vs ' thing yet (I skimmed after a few posts), but for programmers now typing a " for a string is second nature. Making it easier. If it is someone who is learning to program than IDK maybe it is.
Its just my opinion because I am just so used to pressing Shift-' to make a string.

210
General Calculator Help / Re: Adding CAS to Ti-nspire Touchpad?
« on: August 15, 2011, 07:36:17 pm »
There is a library somewhere called "mcas". Let me just find it for you.

EDIT: the page is in french, but here you are, http://ti.bank.free.fr/index.php?mod=archives&ac=voir&id=1884

Pages: 1 ... 12 13 [14] 15 16 ... 33