Austin: "Who sent you?"
Mustafa: "You have to kill me!"
Austin: "Who sent you?"
Mustafa: "Kiss my ass, Powers!"
Austin: "Who sent you?"
Mustafa: "Dr. Evil."
(...)
Mustafa: "I can't stand to be asked the same question three times. It just irritates me."
You are to simulate a short dialogue in the spirit of Austin Powers and Mustafa. But the data source for the entire conversation will be a StackOverflow question (provided as input from a URL).
Rules
The question asker's username will be used in place of "Austin". The question they will ask three times comes from the last sentence in the question title, (which has been forced to end in a question mark if it did not already).
StackExchange will be playing the part of "Mustafa". The answer ultimately given comes from the first sentence in the answer that does not end in a question mark, and will be attributed to the name of the user who answered.
For a question to qualify for the game, it must (a) have an answer, and (b) there must be a sequence of comments on the original question that goes:
- comment from someone other than questioner
- (any number of skipped comments)
- comment from questioner
- comment from someone other than questioner
- (any number of skippable comments)
- comment from questioner
If this sequence is not satisfied prior to the date of the top ranked answer, the program should simply output "Oh, behave!"
StackExchange Mustafa's angry retorts come from the first sentence of the comments from someone other than the questioner that don't end with a question mark--and ensuring it ends with an exclamation mark. If no sentence exists in the comment that doesn't end in a question mark, it is skipped as a candidate for the retort. Comment retorts are attributed to the user name of the author.
Clarifications
Strip any leading "@XXX" response data from a comment.
Because StackOverflow summarizes the comments if there are many of them, you will probably have to use a second request to get the full list. That request is of the form
https://stackoverflow.com/posts/NNN/comments?_=MMM
with the post ID in N and question ID in M. See for instance: https://stackoverflow.com/posts/11227809/comments?_=211160URLs should be stripped to anchor text only.
We'll define a "sentence" as anything outside of a code block that ends in a period, question mark, or exclamation point. If a run of text has no ending punctuation of this form, then the end of the text is the end of the sentence; as if it were written with a period.
If you're looking for funny test cases that are likely to qualify, you might try using StackExchange Data Explorer, such as Posts with the Most Comments.
... more to come, I'll wager...
Samples
Sample One
Input:
https://stackoverflow.com/questions/2283937/how-should-i-ethically-approach-user-password-storage-for-later-plaintext-retrie/
Output:
shanee: "How should I ethically approach user password storage for later plaintext retrieval?"
stefanw: "I think he knows that it is not good!"
shanee: "How should I ethically approach user password storage for later plaintext retrieval?"
Rook: "Perhaps you should ask how you can implement a Buffer Overflow Vulnerability in a Secure way!"
shanee: "How should I ethically approach user password storage for later plaintext retrieval?"
Michael Burr: "Ask why the password is required to be in plaintext: if it's so that the user can retrieve the password, then strictly speaking you don't really need to retrieve the password they set (they don't remember what it is anyway), you need to be able to give them a password they can use."
Sample Two
Input:
http://scifi.stackexchange.com/questions/2611/why-dont-muggle-born-wizards-use-muggle-technology-to-fight-death-eaters
Output:
DVK: "Why don't muggle-born wizards use Muggle technology to fight Death Eaters?"
DampeS8N: "This dances on the edge again!"
DVK: "Why don't muggle-born wizards use Muggle technology to fight Death Eaters?"
DampeS8N: "Right, but this site isn't about pointing out plot holes!"
DVK: "Why don't muggle-born wizards use Muggle technology to fight Death Eaters?"
Jeff: "I believe, though I've been unable to find a reference, that JK Rowling actually mentioned this at one point."
Sample Three
Input:
https://stackoverflow.com/questions/11227809/why-is-processing-a-sorted-array-faster-than-an-unsorted-array
Output:
"Oh, behave!"
(The top rated answer time is Jun 27 '12 at 13:56
, while the second follow-up comment on the question by the questioner is at time Jun 27 '12 at 14:52
. Hence, there isn't a causal link between the second follow-up and the answer. :-P)
Winning Criteria
Code Golf - shortest code wins.