Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com)
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi
Tinderbox Users >> Exporting from Tinderbox >> Exporting to Tumblr
http://www.eastgate.com/Tinderbox/forum//YaBB.cgi?num=1314113312

Message started by Akiva R. Schoen on Aug 23rd, 2011, 11:28am

Title: Exporting to Tumblr
Post by Akiva R. Schoen on Aug 23rd, 2011, 11:28am

This may or may not be a Tinderbox issue but let's see.

I'm using runCommand and curl to submit posts to Tumblr. It works like a champ except line breaks are showing up in Tumblr as


Code:
% d% d


Since this is being done through a GET, I have to use urlEncode() and I'm wondering if that isn't where the problem is occurring.

I am editing text in Byline and then pasting it into the note but I don't see why that should have any effect. If I paste from Byline into other text editors, nothing suspicious shows up. If I paste into other text editors from Tinderbox the text originally pasted from Byline, also nothing suspicious shows up.

So, my eye is on urlEncode().

Title: Re: Exporting to Tumblr
Post by Mark Anderson on Aug 23rd, 2011, 11:50am

What command line are you trying to run & how are you constructing it in TB? It would be easier to help if we can see the code you are using. Things like passwords can be obfuscated, it's seeing what's getting encoded where that will help.

Title: Re: Exporting to Tumblr
Post by Akiva R. Schoen on Aug 24th, 2011, 11:08am

It's rather simple really: I have a note called Publish that I drop other notes onto. The command is:


Code:
$Result = runCommand("curl -d 'email=" + $Email + "&password=" + $Password + "&group=" + $Blog + "&generator=" + $Generator + "&type=regular&format=markdown&title=" + urlEncode($Name) + "&body=" + urlEncode($Text) + "&tags=" + urlEncode($Tags.replace(";", ",")) + "' http://www.tumblr.com/api/write"'); $Posted = "now"; $URL = "http://" + $Blog + "/" + $Result; $Container = "Published";


I borrowed the idea from one of the examples on the Tinderbox Tutorial CD.

Title: Re: Exporting to Tumblr
Post by Mark Anderson on Aug 24th, 2011, 12:14pm

Odd. "% d" is strange.  "%0d" (percent-zero-D) is a carriage return (i.e. a 'CR','\r'). Tinderbox internally uses Classic Mac (\r) line breaks internally, e.g. in $Text. Why a "%0d" would become "% d" I can't figure.

I'd take the just runComand part of your code, i.e. $Result = runCommand(...);, and remove the 'runCommand part and see what $Result holds. You could also pass the output to a file via the shell and see what turns up. I should note I'm not a command line expert but there are a few forum members with CL smarts who may have a better idea.

Title: Re: Exporting to Tumblr
Post by Mark Anderson on Aug 24th, 2011, 12:51pm

If the demo you worked from was my old Twitter demo, it has roots going back pre-TB v5 when output changed from ASCII to UTF-8, so that might be a factor. Still as you're effectively passing a URL, urlEncode() still seems a logical choice. I've not used the Twitter demo in a long time as since changes to the API enhancing security, I'm not sure the posting part works. However, it should still be possible to read data out from Twitter.

I think you also have an error in your string:

...+ "' http://www.tumblr.com/api/write"');  

I think the last single quote here is superfluous (and likely ignored). The previous single quote is within a string literal and in the output it closes a single-quote-delited string started in another literal, just after '-d'.

~~~~
I took this $Text:

This is para one.
This is para two.


Rule:  $MyString = urlEncode($Text)

Value of $MyString:

This%20is%20para%20one.% dThis%20is%20para%20two.

Looks like a glich in urlEncode(). I think that should be %0d.

Title: Re: Exporting to Tumblr
Post by Mark Anderson on Aug 24th, 2011, 1:07pm

Testing further, a '\f' comes out as '% c', looks like the urlEncode() operator has a problem outputting any % url-encoding where the first digit is a zero.  The second is fine - a space gives %20 .

Title: Re: Exporting to Tumblr
Post by Mark Bernstein on Aug 24th, 2011, 2:03pm

Just reported here a few minutes ago.  We expect a fix shortly.

Title: Re: Exporting to Tumblr
Post by Akiva R. Schoen on Aug 24th, 2011, 8:27pm

Wow. Thanks for the quick response on a fix.

Title: Re: Exporting to Tumblr
Post by Akiva R. Schoen on Sep 1st, 2011, 11:25am

The fix definitely works.

The issue of the double execution remains, however. I was thinking, is it possible that it's executing twice because the OnAdd code refers to $Result? In the code, it executes the runCommand() and then uses the $Result to populate $Url so that the published note refers to where it exists on the Tumblr.

It's the only thing I can think of that could be causing the double execution. There only agents I have just change a note's color based on the tag the note is given.

I'm trying now to think if the double posting started with the urlEncode() fix... If it helps, I notice that the post number returned by Tumblr is always the second post's number which leads me to believe that it's definitely something with Tinderbox. It's sending the post twice and keeping the second number.

[Edited to add]: The double posting issue was discussed in e-mail. To sum up, when I drag a note onto the adornment with the runCommand() OnAdd code, it's getting published to Tumblr twice.

Title: Re: Exporting to Tumblr
Post by Mark Anderson on Sep 1st, 2011, 12:07pm

If runCommand() produces an end in it's own right, there's no real need to use the 'Result = ' bit.  I'm not privy to the email conversation so can only go in info here, but what is the exact result of you curl command line. Does it do something via the CL and/or just return a string?

So you call the runCommand in an adornment's OnAdd. It should thus fire once, when a note is added.  Of course if a note is re-added or the 'note'  added is an alias or it's a smart adornment a note might get added/removed/re-added. But there's insufficient info at present to diagnose further.

Title: Re: Exporting to Tumblr
Post by Akiva R. Schoen on Sep 1st, 2011, 6:01pm

Allow me to go into more detail:

First, you're right about the $Result bit. To test my theory that maybe the second reference to $Result was causing the runCommand() to refire, I simply attached the runCommand() to the bit which creates the $URL. (The value returned from runCommand() is the post number which, when suffixed to the domain name, produces the permalink.) It works great without needing the $Result attribute but it still executes twice.

To post a note, I drop it on the smart adornment the OnAdd command of which executes the runCommand() code and then moves the note into a Published container.

What I'm almost now quite sure of is that it didn't initially double-post so I'm wondering if the fix that Mark B. provided might have introduced the double-post bug.

Title: Re: Exporting to Tumblr
Post by Mark Bernstein on Sep 1st, 2011, 6:09pm

Doubt it's the urlEncode fix!

Title: Re: Exporting to Tumblr
Post by Mark Anderson on Sep 1st, 2011, 6:18pm

I'd remove all the variables - i.e. make a string literal of the curl CL. I'd run it from the Terminal CL and confirm you get only one post. Now I'd make the $OnAdd just run runCommand() using the string literal. Check for double execution.

Testing with v5.9.3, I can't get other action code in an adornment $OnAdd to execute twice - IOW I don't think there's a generic double-tap going on with $OnAdd**. I doubt the fix for urlEncode would cause runCommand to run twice. If it does narrow down to runCommand in OnAdd use, I'd say it points to some edge case with the specific use of runCommand. For that level of testing, I think support might want to see your file. Anyway, i'd follow up that route - I don't think it's anything obvious that fellow users can fix.

** I have a very dim remembrance that $OnAdd has - over the years occasionally had issue, but as I say this is best followed up directly with support.

Tinderbox User-to-User Forum (for formal tech support please email: info@eastgate.com) » Powered by YaBB 2.2.1!
YaBB © 2000-2008. All Rights Reserved.