2718.us blog » asLJ http://2718.us/blog Miscellaneous Technological Geekery Tue, 18 May 2010 02:42:55 +0000 en hourly 1 http://wordpress.org/?v=3.0.4 Reposting from the AML TempSite http://2718.us/blog/2009/09/06/reposting-from-the-aml-tempsite/ http://2718.us/blog/2009/09/06/reposting-from-the-aml-tempsite/#comments Mon, 07 Sep 2009 01:43:41 +0000 2718.us http://2718.us/blog/?p=172 This is not likely to be of interest to many people, but for anyone who used uJournal (uJ) or AboutMyLife (AML), which absorbed uJ after its demise, it is worth knowing that there has been a temporary site up at http://aboutmylife.net/tempsite/ at which one can get a very bare dump of their entire journal.  For those interested, it may also be of interest to take all those entries and post them into one’s current journal.  Here is a process for doing that.

THIS INFORMATION IS PROVIDED AS-IS WITH NO EXPRESS OR IMPLIED WARRANTY. USE AT YOUR OWN RISK. It worked for me, but who knows what that may mean for you.

Requires: Python v2.something (maybe 2.4?)–Mac OS X 10.4 works fine, as will most current linux/unix things, I think.

  1. Go to the AML tempsite, log in, and save the file that shows up (which is all your entries, but totally lacking formatting, etc.) as “entries.html”
  2. Download pyLJxmlrpc.py from Google Code (I just put it there; I wrote it), save it in the same directory as entries.html
  3. Copy/paste the following into a file (I called it “processEntries.py” but it doesn’t really matter), and change the USERNAME and PASSWORD to the username and password of the account to which you want to post (you can also change “www.livejournal.com” to other journal sites–it should work on any LJ site that supports the XML-RPC protocol). line wrapping and whitespace are important
    
    #!/usr/bin/python
    
    import re
    
    f = open('entries.html')
    s = f.read()
    a = s.split('</td></tr><tr></tr><tr><td width="25%">')
    r = re.compile(r'([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):[0-9]{2}</td><td width="75%">(.*)</td></tr><tr><td> </td><td>(.*)',re.DOTALL)
    
    processedEntries = {}
    for e in a:
        m = r.search(e)
        t = "%s-%s-%s %s:%s" % (m.group(1), m.group(2), m.group(3), m.group(4), m.group(5))
        processedEntries[t] = {'year':m.group(1), 'mon':m.group(2), 'day':m.group(3), 'hour':m.group(4), 'min':m.group(5), 'subject':m.group(6), 'body':m.group(7)}
    
    sk = processedEntries.keys()
    sk.sort()
    
    import pyLJxmlrpc
    
    lj = pyLJxmlrpc.pyLJxmlrpc()
    
    for k in sk:
        lj.call_withParams_atURL_forUser_withPassword_('postevent',{'event':processedEntries[k]['body'],'linenedings':'unix','subject':processedEntries[k]['subject'],'security':'private','year':processedEntries[k]['year'],'mon':processedEntries[k]['mon'],'day':processedEntries[k]['day'],'hour':processedEntries[k]['hour'],'min':processedEntries[k]['min'],'props':{'opt_backdated':True,'taglist':'aml-raw'}},'http://www.livejournal.com/interface/xmlrpc/','USERNAME','PASSWORD')
        print "%s: %s" % (k,processedEntries[k]['subject'])
    
  4. At a command prompt (Mac: run Terminal), change to the directory in which you saved the two .py files and entries.html, and run
    python processEntries.py

    and watch it go–it’ll only take a few seconds to pull apart the HTML file, but reposting entries takes time; it prints the date/subject of each entry *after* attempting to post it, so errors you might see pertain to the date/subject immediately after the error.

Every entry from AML that didn’t have an empty body will be posted with its date-time maintained, set to private, and backdated; you will see error messages for any entries that were blank (since the AML tempsite thing strips out all HTML, this left me with some blank entries where meme/quiz results had been).

]]>
http://2718.us/blog/2009/09/06/reposting-from-the-aml-tempsite/feed/ 0
Open Source (BSD/MIT License) http://2718.us/blog/2009/09/06/open-source-bsd-license/ http://2718.us/blog/2009/09/06/open-source-bsd-license/#comments Sun, 06 Sep 2009 10:24:58 +0000 2718.us http://2718.us/blog/?p=170 I’ve released a few things as open source recently, under BSD or MIT license, hosted at Google Code.

  • asLJCore is the primary component of the LiveJournal client asLJ, managing all communication with the server.
  • YDDecode is a Cocoa class wrapped around some public-domain C code for decoding data encoded with YEnc.
  • NCIDStatusBarMenu is a utility to help pull NCID-based callerID notifications and display them as Growl notifications (among other things).  I’d been meaning to update it for nearly 2 years with no success and the future isn’t looking much better, so I’m releasing the source instead.

(My musings on licensing below the cut.)Permissive BSD/MIT licenses because in writing asLJ among other things, I’ve had to work to find libraries, frameworks, components, classes, etc., that weren’t GPL-licensed so that I could continue to choose how I wanted to release my software.  I am also heavily influenced by the simplicity of the BSD and MIT licenses compared to the lengthy GPL (and while the LGPL ought to be workable for many libraries, I couldn’t quite wrap my head around the language of it–the LGPL is several paragraphs of modification to the GPL).

(The song lyrics and commentary for OpenBSD4.3 have a lot to do with how I feel about GPL versus BSD/MIT.)

]]>
http://2718.us/blog/2009/09/06/open-source-bsd-license/feed/ 0
NSTextView [Mis]Spelling Underlines Misplaced http://2718.us/blog/2009/07/25/nstextview-misspelling-underlines-misplaced/ http://2718.us/blog/2009/07/25/nstextview-misspelling-underlines-misplaced/#comments Sat, 25 Jul 2009 21:47:15 +0000 2718.us http://2718.us/blog/?p=163 I’ve just spent a total of about 2 hours taking apart and rebuilding an interface window because those little red dotted underlines on misspelled words  in an NSTextView were appearing about a line and a half too high and about 4em to the right.  Net result?  It seems that if core animation is enabled for the content view of a window, which is also the parent view of the NSTextView, spelling underlining becomes very broken.  Adding a custom view inside the content view and enabling core animation for that custom view (and putting the objects that needed their parent to have core animation enabled inside that custom view) seems to have solved the issue.

]]>
http://2718.us/blog/2009/07/25/nstextview-misspelling-underlines-misplaced/feed/ 0
XML-RPC and Mac Programming, Revisited http://2718.us/blog/2009/04/26/xml-rpc-and-mac-programming-revisited/ http://2718.us/blog/2009/04/26/xml-rpc-and-mac-programming-revisited/#comments Sun, 26 Apr 2009 05:59:02 +0000 2718.us http://2718.us/blog/?p=139 I might have been wrong, or at least not entirely right, when I said that AppleScript’s XML-RPC was doing something screwy with UTF8-encoded responses to XML-RPC requests.  I’m not sure if it’s LiveJournal (and other sites based on their code), or if it’s something inherent in XML-RPC, but whether I make the XML-RPC calls in AppleScript (with its built-in mechanism for calling XML-RPC), in Python (with xmlrpclib), or in Objective-C/Cocoa (using the XML-RPC framework from here), things that I was expecting to be UTF8 strings were instead coming through as binary data that needed to be decoded.

Beyond that point, however, AppleScript was severely lacking in that the form in which that data was stored made it entirely unusable–AppleScript couldn’t convert it, couldn’t pass it off to an Objective-C method, etc.  As suggested in my previous post, there was a way around it, and messy though it was, I went about implementing that fix and by and large it worked (though it exposed another minor bug elsewhere).  But it really bothered me.

So I went back to looking at trying to integrate Python code into my tangled web of AppleScript and Objective-C, since XML-RPC is fairly easy in Python, though not quite as easy as in AppleScript.  And, eventually, I succeeded in integrating a class written in Python into the program (documentation on using the PyObjC bridge in this direction is woefully inadequate), using a less ineligant means of fixing the binary UTF8 data—

unicode(theResult.data,'utf-8')

(and Python also allowed me to generically recurse through the entire return structure, which wasn’t possible in Applescript).  Unfortunately, this version was substantially slower than the broken-Unicode version and not particularly any faster (perhaps slower) than the AppleScript-fixed Unicode version.

This led me to look for a way to do the XML-RPC stuff in Objective-C.  Now, mind you, the single thing that enabled me to even think about writing a client for LJ for Mac was seeing just how easy AppleScript XML-RPC calls were.  While I didn’t particularly want to try Python, the XML-RPC calls there weren’t that much harder.  But going to Objective-C for XML-RPC…  that’s a fundamental change in the program.  At least, to me.

I did a lot of Googling and found that there are actually a few XML-RPC frameworks for Objective-C/Cocoa (the one I used by Eric Czarny, the one from Brent Simmons, the Mulle one, XMLRPCObjC, SOPE).  Supposedly, there’s a way to do it with Apple’s own Cocoa stuff, but the documentation is woefully inadequate (none of the frameworks have amazing and wonderful documentation, but Apple’s documentation is bad) and almost every mention of it that I found on mailing lists and discussion boards said it was broken.  In the end, my framework choice was largely dictated by licensing, though there were also some issues with usability and dependencies.  As with AppleScript and Python, the UTF8 strings weren’t coming through as strings, but as NSData objects, which are fairly easy to convert with

[[NSString alloc] initWithData:theObject encoding:NSUTF8StringEncoding]

Recursing through the entire returned structure wasn’t particularly any harder in Objective-C than in Python.

The best part is that the resulting client with Objective-C-based-XML-RPC feels faster than the non-Unicode AppleScript-based-XML-RPC client.  In vaguely-objective tests (determine a set of steps that constitute a test and record the total time for just the XML-RPC calls in those steps, run the test several times under each app, compare times), the new version is measurably faster than the old version.

Bottom lines: (1) expect a new version of asLJ in the next few days, as soon as I get feedback from my early testers; (2) expect another post or two about other things I’ve learned in rewriting the XML-RPC aspect of asLJ in Objective-C.

]]>
http://2718.us/blog/2009/04/26/xml-rpc-and-mac-programming-revisited/feed/ 0
AppleScript’s XML-RPC Doesn’t Get Along with UTF8 http://2718.us/blog/2009/02/14/applescripts-xml-rpc-doesnt-get-along-with-utf8/ http://2718.us/blog/2009/02/14/applescripts-xml-rpc-doesnt-get-along-with-utf8/#comments Sun, 15 Feb 2009 00:53:02 +0000 2718.us http://2718.us/blog/?p=131 While the ease of making XML-RPC calls in AppleScript is wonderful for, say, writing a LiveJournal Client in mostly AppleScript Studio, it seems to be doing something really messed up with UTF8 strings returned by the server—they come into AppleScript as raw data objects, which it seems can’t be cast into any other type and can’t be passed easily into a Cocoa method to convert them. The easiest way to properly decode them seems to be the following:

  1. if class of theReturnedValue is "data" then
  2.  try
  3.   (* this will fail on a data object and then we will pull the (hex) bytes out as text
  4.   and bring them back as a utf8 string object *)
  5.   theReturnedValue as text
  6.  on error errmess – extract the data from the error message
  7.   set bytesString to text ((offset of "«" in errmess) + 10) thru ((offset of "»" in errmess) - 1) of errmess
  8.   set theReturnedValue to (run script "«data utf8" & bytesString & "»")
  9.  end try
  10. end if

This checks the class of the returned value and, if it’s a raw data object, attempts to cast it as text which raises an error, then extracts the string of hexadecimal values from the error message and puts it into a proper UTF8 object, making everything happy again.

If anyone wants to tell me I’m wrong and there’s a simpler fix, I’d love to hear it, since this is essentially unworkable.

]]>
http://2718.us/blog/2009/02/14/applescripts-xml-rpc-doesnt-get-along-with-utf8/feed/ 1
Dynamic URLs for XML-RPC Calls in AppleScript http://2718.us/blog/2009/02/12/dynamic-urls-for-xml-rpc-calls-in-applescript/ http://2718.us/blog/2009/02/12/dynamic-urls-for-xml-rpc-calls-in-applescript/#comments Thu, 12 Feb 2009 16:42:38 +0000 2718.us http://2718.us/blog/?p=123 I started working on asLJ after I came across this. One of the problems that I quickly ran into was that the URLs in the
tell application "<url>" to call xmlrpc ...

bits had to be hard-coded. That is, AppleScript didn’t like it when I tried to assemble the URL string on the fly. It took me a while to come up with a workaround, which should slightly impact the speed of the call, but doesn’t seem to make a noticeable difference. Here’s my generic handler for making LJ-based server XML-RPC calls:

– make a LiveJournal-type XML-RPC call to serverString for the method methodName with the parameters in parameterArray
  1. on callLJraw(serverString, methodName, parameterArray)
  2.     run script "on run {paramArray}
  3.                 tell application \"http://" & serverString & "/interface/xmlrpc\" to call xmlrpc ¬
  4.                     {method name:\"LJ.XMLRPC.\" & \"" & methodName & "\", parameters:{paramArray}}
  5.             end run" with parameters {parameterArray}
  6.     return result
  7. end callLJraw
]]>
http://2718.us/blog/2009/02/12/dynamic-urls-for-xml-rpc-calls-in-applescript/feed/ 0
asLJ: a Mac OS X 10.5+ LiveJournal Client http://2718.us/blog/2009/02/09/aslj/ http://2718.us/blog/2009/02/09/aslj/#comments Mon, 09 Feb 2009 08:24:18 +0000 2718.us http://2718.us/blog/?p=121 asLJ is a new client for Macs running Leopard that easily handles multiple accounts on LiveJournal and other LJ-based sites and facilitates cross-posting across accounts. Release notes and download link are in [info]aslj_client. The community for users is [info]aslj_users.

(As it is very LJ-centric, most of the information about it will be over at LJ, in the two places linked above, but there is a page for it here, as well.)

]]>
http://2718.us/blog/2009/02/09/aslj/feed/ 0