Rosetta Code/Count examples: Difference between revisions

→‎{{header|PureBasic}}: Update code to use new Media API and to properly retrieve the plethora of tasks
(→‎{{header|PureBasic}}: Update code to use new Media API and to properly retrieve the plethora of tasks)
Line 1,630:
 
=={{header|PureBasic}}==
<lang PureBasic>OpenConsoleProcedure handleError(value, msg.s)
If jvalue = 0
URLDownloadToFile_( #Null, "http://www.rosettacode.org/w/api.php?action=query&list=categorymembers&cmtitle=Category:Programming_Tasks&cmlimit=500&format=xml", "tasks.xml", 0, #Null)
MessageRequester("Error", msg)
ReadFile(0, "tasks.xml")
End
x1$ = ReadString(0)
RepeatEndIf
EndProcedure
 
handleError(InitNetwork(), "Unable to initialize network functions.")
If OpenConsole()
Define url$, x1$, y1$, title$, unescapedTitle$, encodedURL$
Define x2, i, j, totalExamples, totalTasks
url$ = "http://www.rosettacode.org/mw/api.php?action=query" +
"&list=categorymembers&cmtitle=Category:Programming_Tasks" +
"&cmlimit=500&format=xml"
Repeat
handleError(ReceiveHTTPFile(url$, "tasks.xml"), "Unable to access tasks URL.")
handleError(ReadFile(0, "tasks.xml"), "Unable to read 'task.xml' file.")
x1$ = ReadString(0)
CloseFile(0)
Repeat
x2 = FindString(x1$, "title=", x2 + 1)
If x2
title$ = Mid(x1$, x2 + 7, 99)
title$ = Left(title$, FindString(title$, ">", 1) - 4)
unescapedTitle$ = UnescapeString(ReplaceString(title$, "&#039;", "&apos;"), #PB_String_EscapeXML)
encodedURL$ = URLDownloadToFile_URLEncoder( #Null, "http://www.rosettacode.org/wmw/index.php?title=" + titleunescapedTitle$ + "&action=raw", "task.xml", 0, #Null)
ReadFile(1, "task.xml")
If WhileReceiveHTTPFile(encodedURL$, Not Eof(1"task.xml")
ReadFile(0, "task.xml") y1$ = ReadString(1)
While Not If FindStringEof(y1$, "=={{header|", 10)
y1$ = j + 1ReadString(0)
If FindString(y1$, "=={{header|", 1, #PB_String_NoCase)
totalExamples + 1
EndIf
Wend
PrintN( title$ +": " + StrCloseFile(j0) + " examples")
k + j
PrintN(unescapedTitle$ +"Total: " + Str(ktotalExamples) + " examples")
j = 0
CloseFile(1)
totalTasks + totalExamples
totalExamples = 0
EndIf
EndIf
Until x2 = 0
PrintN("Total: " + Str(k) + " examples")
;check for additional pages of tasks
Input()</lang>
x2 = FindString(x1$, "cmcontinue=")
If x2
i = FindString(x1$, #DQUOTE$, x2 + 1)
j = FindString(x1$, #DQUOTE$, i + 1)
url$ = URLEncoder("http://www.rosettacode.org/mw/api.php?action=query" +
"&list=categorymembers&cmtitle=Category:Programming_Tasks" +
"&cmlimit=500&format=xml&cmcontinue=" + Mid(x1$, i + 1, j - i))
Else
Break ;all done
EndIf
ForEver
PrintN("Total: " + Str(totalTasks) + " examples")
Input()</lang>
CloseConsole()
EndIf</lang>
Sample output:
<pre>100 doors: 224 examples
24 game: 78 examples
24 game/Solve: 46 examples
9 billion names of God the integer: 33 examples
99 Bottles of Beer: 253 examples
A+B: 187 examples
......
Zeckendorf arithmetic: 6 examples
Zeckendorf number representation: 37 examples
Zero to the zero power: 71 examples
Zhang-Suen thinning algorithm: 18 examples
Zig-zag matrix: 83 examples
Total: 44140 examples</pre>
 
=={{header|Python}}==
Anonymous user