10 Replies - 1651 Views - Last Post: 06 June 2011 - 07:18 PM Rate Topic: -----

#1 The Architect 2.0  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 351
  • Joined: 22-May 08

Making a Desktop App for Facebook

Posted 04 June 2011 - 01:58 AM

Hello,

I've been trying to learn c#. In particular, how to connect to web apps, starting with facebook.

I am under the impression that c# allows me to call a specific URL for a web API and get some HTML/XML/JSON back just like if I was calling it from an actual webpage. From there, I could just simply manipulate that data and display however I feel like in windows forms.

i'm currently trying to get an authentication token. Normally, desktop apps load an html login page. I want to be able handle all the HTTP login stuff in the background without showing the user the login page. I've been trying to use httpwebrequst/response to handle this, but i honestly don't know where i'm going with it.


https://developers.f...authentication/ - guide I've been trying to follow

Is This A Good Question/Topic? 0
  • +

Replies To: Making a Desktop App for Facebook

#2 Shane Hudson  Icon User is offline

  • D.I.C Technophile
  • member icon

Reputation: 343
  • View blog
  • Posts: 1,286
  • Joined: 06-December 09

Re: Making a Desktop App for Facebook

Posted 04 June 2011 - 02:09 AM

This can be done, of course, but Facebook is really not a good example. Their API is dreadful from what I can remember!
Was This Post Helpful? 0
  • +
  • -

#3 The Architect 2.0  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 351
  • Joined: 22-May 08

Re: Making a Desktop App for Facebook

Posted 04 June 2011 - 02:39 AM

basically, what i THINK i need to do is:

*understand the login html page and figure out what it is being included in the POST request that it sends to the facebook server and then make my code manually send an identical POST request
*make sure that a cookie is being saved - I don't know if my 'background' stuff would prevent cookies from working right
*understand the app authorization page and figure out and copy its POST request.
*parse the redirect_uri and get the token that is included in that URL

at this point....i'm not sure how to do any of that. maybe somebody can point me to a good tutorial for parsing URLs? the ones i found all use asp.net and i'm not sure what c# code to use.
Was This Post Helpful? 0
  • +
  • -

#4 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Making a Desktop App for Facebook

Posted 04 June 2011 - 06:29 PM

There are two ways to accomplish your goals:
1) Use web APIs that the website wrote just for you, so you'd have an easier time getting data from their server.
2) Rip the data straight from their html interface, let them try and stop ya, let em try! =)

Option 1 is easier, but you're limited to taking what the website owner wants you to take. Facebook is notoriously FBI slanted, so they can entrap Muslims easier. I immediately presume that Facebook's web API is difficult to use (and probably quite limited) because they're not interested in sharing technology with the whole of the population, only a subset (eg the FBI).

I've never used a websites API, so I can't speak with the deepest bounding of knowledge, but... I wrote a cool thing once in vbscript that parses data from an html page, and manipulates it. I wonder if the source site is still up... OMG It's still alive! lol, this will be fun.

So here's my .vbs (I'll give you translations for C#)
(Quiz parser (online to instant).vbs)
'To work this script, take the online quiz (you don't need answers graded back).  
'Then in google chrome, view the source, click and highlight everything (ctrl+A), and then paste it into a new file named "testz.txt"  
'Then run the script in the same directory as "testz.txt" and it will read through the file and output tons of .htm files which will comprize a quiz (an instant feedback quiz).  
' Title Page.htm is the index of the quiz
' double check answers for the first run, especially if you're trying this with a quiz that isn't for audit or cost


'NOTE!  The txt file must be ANSI format (default for windows notepad).  If your feedback comes back all messed up, then you saved testz.txt as a unicode file.  
' if feedback is empty, that's just because mcgraw hill is lazy and doesn't care.  





'quiz ideas
'
'1) come up with html that corrects the quiz on the same page that answers are presented (so you don't have to click to a new page to see if you're right/ wrong)... like a fancy change on the page to a green square if you're right, or a red square if you're wrong.  and a proceed button/ menu button at bottom.
'feedback would display too.  
'
'2) links to definitions and concept paradigms  (search through for terms and make then hyperlinks...)
'
'
'3) for math problems, come up with a note card like system...  Consider a table with cards on it (the cards are flipped over, you can't see contents).  The contents of the card are equations...  each equation is a step towards completed the math problem asked.  Clicking on each card... either displays the equation (simple, easy, first iteration of programming), or it displays a list of things and you choose correct (a lil harder) Or you are presented a field where you type in the accounts involved in the first procedure (way complex, but worth it in free time) then it would ask you to click and drag the accounts into the possitions you thought were valid, and finally it would grade your arrangement of the accounts and operators (just for that card).  
'
'
'



Set fso = CreateObject("Scripting.FileSystemObject")
' Open the file.  Change the path to where you have your file saved.
if not fso.FileExists(fso.GetAbsolutePathName(".") & "\testz.txt") then
   msgbox "Instructions:  To create an interactive .htm quiz you need to:" & vbcrlf & "1.  Browse to the highered.mcgraw-hill.com quiz that you would like to study" & vbcrlf & "2. Right click the page and view the source code" & vbcrlf & "Copy and paste that source code into a new text file, name it ""testz.txt"" ... put it in a folder called ""ch X""" & vbcrlf & "3.  Run this script in the same folder ""testz.txt"" is in." & vbcrlf & "4.  Take the quiz by double clicking ""Title Page.htm""" & vbcrlf & vbcrlf & "BE WARNED, this script is huge and may have bugs.  It might be a good idea to double check the answers the first time you click through."  & vbcrlf & "note: to see this msg, run script in folder with out testz.txt"
else

const ForReading = 1
Set ts = fso.OpenTextFile(fso.GetAbsolutePathName(".") & "\testz.txt",ForReading,0,0)      'open it as a unicode doc!  Important for decryption...


'TODO
' Parse for "Use the following" & ":"   and apply that to all numbers... that's goona take atleast an hour to figure out properly...
' 



dim quitz       ' PROMPT TO RUN SCRIPT
quitz = msgbox ("Are you sure you want to execute this script?", 4, "Execute script?")
if (quitz = 7) then wscript.Quit   'stop script if NO selected
Dim Replayce
Dim withthis
' Problem characters: WAS... but it turned out to be something else... "'"  Vs  "'" 
' I'm doing this the wrong way, I need to parse out all markup in the question... instr "<" then see "<b>"  then replace with "" and store it's removal position in  Removalz(qcount,i)
Replayce = Array("/sites/dl/free",                                "","","", "–", ""              , "<u>after</u>", "<b>not</b>"    , "<b>NOT</b>"   ,       "<u>not</u>" , "<u>most likely</u>"  , "<i>least likely </i>" ,"<u>least </u>", "<u>least</u>" , "<u>except</u>" , "<i>least</i>" , "<i>false</i>" )         ' hmmm...  that actual hyphen... should I leave it?... nah, i'm taking out the natural hyphen
withthis = Array("http://highered.mcgraw-hill.com/sites/dl/free", "/","-","6", "&ndash;", "&ndash;"        , "after"       ,"not"            , "not"         ,       "not"        , "most likely"         ,  "least likely "        , "least "      ,   "least",      "except"        , "least"        , "false" )

'after slips away... maybe link it to "occurs after"...   ...  so does least alone...
repquest =     Array(" NOT ",        " not ",         "most likely"      , "least likely",           "except:"        , "is false"     )   'replace in question
repquestwith = Array(" <b>NOT</b> ", " <b>NOT</b> ",  "<u>most likely</u>" , "<i>least likely</i>" , "<u>except</u>:" , "is <i>false</i>"         ) ' with this

newliner = Array("A.", "B.", "C.", "D.", "E.",":",";") ', ";",":") ' Items here get suffixed with vbCrLf & <li>                    UBound(newliner) = array size  
newliner2 = Array("(1)", "(2)", "(3)","(4)","(5)","(6)")      'put items here, they get prefixed with vbCrLf & <br>                 'I disabled this one



Function decrypt(theText)
 	'//XOR decryption code for the feedback text and title 
	Dim key  '//Hardcoded as of Now	  "he wrote that, lol"
	key = 150
	Dim pos '= theText.indexOf(""+key);
	pos = InStr(1,theText,"" & key)
	if(pos > 0) then
		theText =  mid(theText,1,pos)                  ' theText.substring(0,pos);
		'//alert("Removed key: "+ theText);
	end if
	
	Dim length
	length = Len(theText)
	dim output 
	output = ""
	dim temp 
	temp = ""

	for i = 0 to length-2
		'msgbox Asc(mid(theText,i+1,1)) 
		                                      'temp =((theText.charCodeAt(i) ^ key));
		temp = Asc(mid(theText,i+1,1)) Xor key          'I removed an all inclusive Cint(all)
		                                      'output += String.fromCharCode(temp);
		output = output & Chr(temp)
		
	Next
	
	  '//alert(output);    
    decrypt = output
End Function



Function parset(theText)     'parse feedback   (I thought question too, but nope...)
   


   
   possitionz = InStr(1, theText, ": ")
   if possitionz <> 0 And 0 = InStr(1,strLine, "(1)") then 
      for i = 0 to UBound(newliner)
         theText = Replace(theText, newliner(i), newliner(i) & "<br>" & vbCrLf) 
      next
   End if
   
   For i = 0 to UBound(newliner2)
         theText = Replace(theText, newliner2(i), vbCrLf & "<br>" & newliner2(i) ) 
   Next

      'Cycle through the Replayce variables...  there's a set number, do loop for that set number...  set all the replace variables into an array and cycle up the array.  
   For i = 0 to UBound(Replayce)                                 
       theText = Replace(theText, Replayce(i), withthis(i))         ' replace all the stuff in the buffered file line appropriately
   Next 
   

   parset = theText   
End function


Sub parseqpost        'does the engulfer code on any question(i)... cutting the body, and pasting it to following questions
theText = ""
engulfer = Array("Use the following information to answer questions ", "The following information applies to questions ")      '11 – 13:    ' items here will be searched for, and if found, their following body shall be engulfed and displaced to the next n questions, where n is  x-y

for x = 0 to numbq-1       'loop through each question(i)
   theText = question(x)

for each i in engulfer            'loop through each engulfer statement...  search for each engulfer statement in the question(x) which is not theText
   possitionz = InStr(1,theText,i)
   if possitionz <> 0 then          'see if question(x)  contains the engulfer statement
      refpnt = instr(1,theText,":")  ' search for ":"    
                                     ' parse the numbers in the engulfer
      numberst = mid(theText,possitionz+Len(i),refpnt-possitionz-Len(i))         'number string =  the numbers  ... this one is only going to work for 1 or 2 digit numbers only  start cutting based on where the engulfer statement appears + the len of engulfer statement (which gives us the location of the end of E stmt) and then go as far as until the ":" is found.  
      'msgbox refpnt & "refpnt  VS.  " & possitionz+Len(i) & " possitionz" & vbcrlf & numberst
      Nz = Cint(trim(Right(numberst,2))) - Cint(trim(Left(numberst,2))) ' subtract the two numbers to get Nz                                                    
      
      'refpntR = InStr(1, theText,"<br>")' Search for <br> which marks the end of the body
       'msgbox "<td id=""LID" & x+1 & "_1"
       'refpntR = InStr(1, theText,"<td id=""LID" & x+1 & "_1") 'there's no need, just use end of string                                  'no, search for the "<td id=""LID" & 5 & "_1"  ... 
       'msgbox theText
       'refpntR = InStrRev(theText,"<tr ")   'not needed...                                ' and backtrack from there to the "<tr "
       refpntR = InStrRev(theText,"<p></p>")                                   ' and then back track from there to the "<p></p>"
       
       if refpntR - refpnt < 5 then                      'weak workaround setting for cost ch16 #14
          'msgbox "HIT question:" & x+1
          refpntR = InStrRev(theText,"</td></tr>")
       end if
       'refpntR = refpointR-1                                          'which marks the position of the end of the thing body
       'msgbox "Length of theText:  " & Len(theText)    &vbcrlf & "The position of <P>" & refpntR                                                                           'a better coder would backtrack to the next "<p></p>" AFTER the one that leads the body paragraph text, but screw that
      'msgbox refpntR
      'pBody = mid(theText, refpnt, refpntR)  ' parse the body  
      refpnttab = InStrRev(theText,"</table>") 
      if refpnttab > refpntR then refpntR = refpnttab    
      'msgbox refpntR  & "  " & refpnttab
               
      pBody = mid(theText, 1, refpntR-1)      
      
      for z = x+1 to x + Nz          'for THE NEXT question, and all following until NZ gets done...
         'msgbox pBody
         'refpointl = instr(1,question(z),"<td valign")          'this chunk tries to get the question the changes to be bold...
         'refpointr = instr(refpointl ,question(z) ,"<br>")
         'tmptext = mid(question(z),refpointr, 4)
         'question(z) = Replace(question(z),tmptext,"<br><b>",refpointr,1) 
         
         question(z) = pBody & "<br><br><b>" & question(z) & "</b></tr></table>"  '  prefix the body for question(qcount+i)  add the body       '  z = the next problem-the last problem to be worked on
         
         x = x + 1    ' skip ahead these problems cause they won't have any engulfer statements
         'msgbox question(z)
         pwzflag = 1
      Next
   end if


next
Next
End Sub






Dim numba  'number of answers
numba = 4    '   A dummy number must exist (one that multiplies with zero to make zero.  numba is found by the script itself (damn I'm clever)
Dim numbq  ' the number of questions... it's found at the end, using qcount

Dim question(40)           'needs to be an array
Dim correct(40)            'zero is a field, 0 can be an answer
Dim answer(210)
Dim feedBk(210)
Dim chaptern               'finds the chapternumber, stores here, the whole string! "chapter n"
Dim acount
Dim fcount
Dim qcount
Dim refpoint     'position reference for where we pull our answers and questions and stuff
Dim correctsymbol
Dim ftcount
Dim feedbkt(40)
' correctsymbol = "150"              'the symbol is found automatically now
correctsymbol = "0pTiMus PrImE"
qcount = -1      ' you have to start at -1 lol
fcount = 0
acount = 0
ftcount = 0

for i = 0 to 5                  'finds the chapter number
   tvar = ts.readline 
   refpoint = instr(1,tvar,"<input value=""Chapter ")
   if refpoint > 0 then
     chaptern = mid(tvar,refpoint+14,10)
     if instr(1,chaptern,"""") then chaptern = mid(chaptern,1,9)    'if it's a single digit chapter, get rid of the extra comma parsed
   end if
next











'Dim curline
'curline = 0

Do While Not ts.AtEndOfStream                                'this is the big loop that reads a line at a time, replaces the contents of the line with reasonable text, and stores the relevent text into  question(), answer(), feedBk(), and... yeah...


tvar = ts.ReadLine

'curline = curline + 1
'if curline = 35 then
'   msgbox tvar
'end if


   for i = 0 to UBound(replayce)                             
      tvar = Replace(tvar,replayce(i), withthis(i))
   Next




If Instr(1, tvar,"new makeQuestionObject") Then
  qcount = qcount + 1   '!!!! move this to the end of the interation   <<you can't follow this suggestion... I think it's taken care of ok like this

  refpoint = InStrRev(tvar,"'", Len(tvar)-3)
  question(qcount) = mid(tvar,refpoint+1,Len(tvar)-refpoint-3)
  'if qcount = 14 then msgbox question(qcount)
end if


if Instr(1, tvar,"new makeAnswerObject") Then
  if qcount > 0 then               
     if acount = numba then acount = 0
  end if

  refpoint = InStrRev(tvar,"'", Len(tvar)-3)
  answer(qcount*numba + acount) = mid(tvar,refpoint+1,Len(tvar)-refpoint-3)

  acount = acount + 1
end if

    ' I can do algorithm that finds what ever new variable they use as correct answer... just so long as variable names are the same.  
'feedBackTitle        if feedbkt(0) != feedbkt(1)   and feedbkt(0) = feedbkt(2) then Correctsymbol = feedbkt(1) else correctsymbol = feedbkt(1)
' This subroutine also finds the value of numba !!!

if qcount = 0 And Instr(1, tvar,"feedBackTitle =") Then           'only do this loop for the first question section
  refpoint = InStr(1,tvar,"=")
  refpoint = InStr(refpoint,tvar,"'")+1         'reference the first char of string positioning
  feedbkt(ftcount) = mid(tvar,refpoint, InStrRev(tvar,"'") - refpoint)         ' captures everything between the single quotes  (so the symbol in question
  
  'msgbox feedbkt(ftcount)
             'and compare the second string with the first and the third and determine the odd ball... then set the oddball to correctsymbol and set correct(0) = what it should be
    if ftcount > 1 then    'if you have atleast 3 symbols to compare
      if Asc(feedbkt(ftcount)) <> Asc(feedbkt(ftcount-1)) then  ' if 3 and 2 are different then        (2 is correct or 3 is correct)
      'msgbox feedbkt(ftcount) & " " & feedbkt(ftcount-1)
         if Asc(feedbkt(ftcount)) <> Asc(feedbkt(ftcount-2)) then   'if 3 and 1 are different then     (it must be 3)
            'msgbox feedbkt(ftcount) & " " & feedbkt(ftcount-1)                           'else it must be 3
            correctsymbol = feedbkt(ftcount)             'else set 3 correct
            correct(qcount) = ftcount
            'msgbox "correct symbol:   " & correctsymbol & vbcrlf & "first correct:  " & ftcount

         else 'if Asc(feedbkt(ftcount)) <> Asc(feedbkt(ftcount-2)
            correctsymbol = feedbkt(ftcount-1)           'set 2 correct
            correct(qcount) = ftcount-1    
            'msgbox "correct symbol:   " & correctsymbol & vbcrlf & "first correct:  " & ftcount
         end if
      else 
         if ftcount = 2 And Asc(feedbkt(qcount*numba + ftcount)) <> Asc(feedbkt(qcount*numba + ftcount-2)) then 
            correctsymbol = feedbkt(qcount*numba + ftcount-2)                               ' if 3 and 1 are different then 1 must be the correctsymbol
            correct(qcount) = 0
            'msgbox correctsymbol
         end if
      end if
    end if


  ftcount = ftcount + 1
  numba = ftcount
  'if ftcount = numba then ftcount = 0
end if



if Instr(1, tvar,correctsymbol) Then

    refpoint = InStr(1, tvar,"].feed")
   ' msgbox "this is correctsymbol fucn: " & correctsymbol
    correct(qcount) = CInt(mid(tvar,refpoint-1,1))-1
    'msgbox correct(qcount)
    
end if





if Instr(1, tvar,"feedBackText = '") Then
  refpoint = InStr(1,tvar,"=")
  refpoint = InStr(refpoint,tvar,"'")+1         'reference the first char of string positioning
  
  if qcount < 2 then
  'msgbox decrypt("answerObjectArrayLID1[1].feedBackText = '帶⺶帶")
  'msgbox decrypt(mid(tvar,refpoint, InStrRev(tvar,"'") - refpoint))
  end if
  
  feedBk(qcount*numba + fcount) = decrypt(mid(tvar,refpoint, InStrRev(tvar,"'") - refpoint))
  
  feedBk(qcount*numba + fcount) = parset(feedBk(qcount*numba + fcount))


  fcount = fcount + 1
  if fcount = numba then fcount = 0
end if
Loop





ts.close
numbq = qcount+1         'save the number of answers read!


for i = 0 to numbq-1
'   msgbox question(i)
'    msgbox feedBk(i*numba)
next








'BEGIN  parse htm

Dim refpoint2    'this marks the end of the question text
Dim refpointl    ' this marks the leftmost point of question(i) or answer(i) ... the HTML bound
Dim acode        ' this is the answer code... used in finding refpointr
Dim refpointr    ' this marks right most point of x(i)
tvar = ""
Set ts = fso.OpenTextFile(fso.GetAbsolutePathName(".") & "\testz.txt")
Do While Not ts.AtEndOfStream
   tvar = tvar & ts.ReadLine
loop      'tvar now has the entire html data file
ts.close
   for i = 0 to UBound(replayce)              
      tvar = Replace(tvar,replayce(i), withthis(i))
   Next

for i = 0 to qcount        'this loop searches the data for the question string, and then cuts the HTML data for each question out properly and stores it in question(i)
                            '// NOTE!!!  THIS WHOLE STYLE OF FINDING THE QUESTION STRING SUXX!!! I SHOULD HAVE Searched For   <td id="quest4" ...  SOO EASY and it IS a unique occurance in whole data population!!!
'   refpoint2 = instr(1,question(i),":")        'refpoint of end of question(i) to search for
'                                               'we need to check for punctuation too.... oh, add a space
'                                                  
'   if refpoint2 = 0 then refpoint2 = Len(question(i))
'   halfquestion = mid(question(i),1, refpoint2)
'                                          'searches tvar for the question phrase
'   halfquestion = Replace(halfquestion,"'","'")
'   'halfquestion = Replace(halfquestion,"-","&ndash;")
   
   'Force string  // helpful debug step 3 item for catching missing elements in replayce(i)
   'if i = 3 then halfquestion = "With respect to the issuance of an audit report which is dual dated because of an event occurring after the date on which the auditor has obtained sufficient appropriate audit evidence  but before the audit report was issued, the auditor's responsibility for events occurring after the completion of fieldwork is:"
   
   
   'I NEED TO DO SOMETHING HERE THAT ACCOUNTS FOR THE VARIENCE IN - / &ndash; / –   ... OH, JUST REPLACE ALL IN FILE WITH 1
   
'   refpoint = instrRev(tvar, halfquestion,len(tvar),1)   'SEARCH FOR QUESTION        ' cut tvar  beggining where question begins  and ending where question stops OR where : is... 
   
   
   'if i = 3 then msgbox refpoint
   ' catch for typos... extra spaces... just random BS
'   if refpoint = 0 then
'      if Len(halfquestion) > 70 then halfquestion = mid(halfquestion,1,70)
'      refpoint = instrRev(tvar, halfquestion,len(tvar),1) 
'   end if
   'if i = 3 then msgbox halfquestion
   
   

'   possitionz = instr(1,halfquestion,". ")
'   if possitionz <> 0 and asc(  mid(halfquestion, possitionz+2,1)) < 91  then
'    lazyprog = 0
'      do while lazyprog = 0       '  was....     do while possitionz > 0 
'         if asc(  mid(halfquestion, possitionz+2,1)) < 91 then            'if the character after the first space of that ". " statement is a capital letter (or a space)  then
'                                                                                                           ' this presents a possible bug... it may not be unique (the segment of 5 chars) and it may be > Len(halfquestion) would would error
'             halfquestion = Replace(halfquestion, mid(halfquestion, possitionz-2,5)  , mid(halfquestion, possitionz-2,4) & " " &  mid(halfquestion, possitionz+2,1))          '  finds:    "xe. F" and replaces it with   "xe.  " & "F"   ...yikes!
'             halfquestion = left(halfquestion,possitionz)
            'halfquestion = Replace(halfquestion,". ",".  ",possitionz,1)                  'replace that statement with proper punctuation
'            possitionz = instr(possitionz+1, halfquestion,". ")           ' this shouldn't be here, but I don't know how the do while loops works so I'm being redundant.  
'         lazyprog = 1  
'         end if                                     
'         possitionz = instr(possitionz+1, halfquestion,". ")                 'and set possitionz to the next occurance of ". "  
'      loop
'      refpoint = instrRev(tvar, halfquestion,len(tvar),1)  ' this redoes refpoint so it will find the correct string position
'   end if

      'msgbox question(1)
   'if i = 1 then msgbox refpoint
   'if i = 1 then msgbox "length " & len(tvar)
   '//Debug step 1, find the erroring question number...  then review the html source
   'msgbox 1+i
   '// Debug step 2,  note that halfquestion must be located in the html source, exactly as written
   'if i = 3 then msgbox halfquestion
   
   '"'"  Vs  "'" 
   
'   refpointl = InStrRev(tvar, "<td valign", refpoint)                          '(BUT back tracking to the first occurance of "<td>")         ' refpoint now contains the leftmost bound of question(i) (including the html
'   acode = "LID" & i+1 & "_1"
'   refpoint = InStr(refpointl,tvar, acode)                    ' finds position of LID1_1
'   
'   refpointr = InStrRev(tvar,"<td", refpoint)                ' THIS IS BRUTISH, refpointr is now really a good refpoint r
'   '// Debug  check on the question
'   'if i = 3 then msgbox question(3)
'   question(i) = mid(tvar,refpointl, refpointr-refpointl) & "<br>"          'BUG refpointr and refpointl were equal !!
   
'   for x = 0 to UBound(repquest)                                                  'kekekeke, replaces the bolds and the underlines back in
'      question(i) = Replace(question(i),repquest(x),repquestwith(x))
'   next



   '// THIS IS THE CORRECT WAY TO DO IT!
   widehtmlleft = instr(1,tvar,"<td id=""quest" & i+1)        'refpoint of start of HTML for current question 
                                                                  
                                                  
   narrowhtmlleft = instr(widehtmlleft,tvar,"<td valign")
   
   acode = "LID" & i+1 & "_1"
   widehtmlright = InStr(narrowhtmlleft,tvar, acode)                    ' finds position of LID1_1   WiderHTMLRight...
   narrowhtmlright = InStrRev(tvar,"<td", widehtmlright)                  'I once called THIS brutish, lol
   

   question(i) = mid(tvar,narrowhtmlleft, narrowhtmlright-narrowhtmlleft) & "<br>" 
   

   for x = 0 to UBound(repquest)                                                  'kekekeke, replaces the bolds and the underlines back in
      question(i) = Replace(question(i),repquest(x),repquestwith(x))
   next
   

next


   

qcount = 0               'reset qcount




'for i = 0 to 1
'   msgbox question(i)
'Next

for i=0 to numba-1  ' delete the first <br> present in each question
   question(i) = Replace(question(i),"<br>", "",1,1)
Next

parseqpost




for qcount = 0 to numbq-1       'loop for each question
   Set ts = fso.CreateTextFile(fso.GetAbsolutePathName(".") & "\Page " & (qcount+1)*3 -2 & ".htm",2)
   Dim qpage  'question page data (to be written to a .htm)   it's not used... wasn't thinking though...
   Dim cpage  'correct page
   Dim ipage  'incorrect page
   'Dim feedbkgood(numbq)  'feed back marked as correct
   'Dim feedbkbad(210)
   
   'ReDim feedbkbad(numbq)    ' could be converted to numbq*numba size, but feedback is binary anyway... unary I think, lol
   'ts.writeline SHIThtm
   ts.writeline "<body bgcolor=""Silver"">" & qcount+1 & ".  " & question(qcount)                  'write down the question number
   'ts.writeline "<br><br> links"

   Dim letter
   letter = 65
   for i = 0 to numba-1     'do for each answer
     
     ts.writeline vbCrLf & "<br>" & chr(letter) & ") <a href=""Page " 

     if correct(qcount) = i then
        ts.writeline (qcount+1)*3 -1          '  qcount+1 = "question number"  ...   "question number" * 3 = "incorrect answer address for said question number"  ...  incorrect answer -1 = "correct answer address"
                ' feedbkgood(i) = feedBk(qcount*numba+i)    'we don't need this now, it isn't necesary since we have correct(qcount)
     else
        ts.writeline (qcount+1)*3             '  link to proper incorect page           feedbkgood = feedBk((qcount*numba)+correct(qcount))
        'feedbkbad(qcount) = feedBk(qcount*numba+i)        'for now, we only have uniary feedback.  SO this little hack is all we need.  it gets overwritten 3 times or so, heh...
     end if

     ts.writeline ".htm"">" & answer(qcount*numba+i) & "</a>"                  'write out the M/C answers     ' qcount*numba+i = (puts it) in terms of  Zero to numbq*numba   sized arrays

     letter = letter + 1
   Next
   ts.writeline vbCrLf & vbCrLf & "<br><br>" & "<a href=""Title Page.htm"">Question Menu</a>"
   ts.close      'end of question page
   set ts = nothing
   
   'write correct page. 
   cpage = "<body bgcolor=""Silver"">"
   cpage = cpage & "<font color=""#088A08""><b>Correct!</b></font>" & vbCrLf & "<br><br>" & vbCrLf & "Feedback:  " & feedBk((qcount*numba)+correct(qcount)) & vbCrLf & "<br><br>" & vbCrLf & "<a href="""    ' feedBk((qcount*numba)+correct(qcount)) = correct answer feedback
   if qcount = numbq-1 then
      cpage = cpage & "Title Page.htm"">Click To return to Title Page</a>"   ' go to title page if this is the last itteration of cpate
   else
      cpage = cpage & "Page " & (1+qcount+1)*3-2 & ".htm"">Click for Question " & 2+qcount & "</a>"   '  Or go to next page    
   end if
   
   Set ts = fso.CreateTextFile(fso.GetAbsolutePathName(".") & "\Page " & (qcount+1)*3 -1 & ".htm",2)
   ts.writeline cpage
   ts.close
   set ts = nothing
   
   'feedbkbad(qcount) = feedBk((qcount*numba)+correct(qcount))         '  Take this out if you ever come across a test that has multiple feedbacks per question
   
   'write icorrect page.  
   ipage = "<body bgcolor=""Silver"">"
   ipage = ipage & "<font color=""#FF0000""><b>Incorrect!</b></font>" & vbCrLf & "<br><br>" & vbcrlf & "Feedback:  " & feedBk((qcount*numba)+correct(qcount)) & vbcrlf & "<br><br>" & vbcrlf & "<a href=""Page " & (1+qcount)*3-2 & ".htm"">Click to try again.</a>"
   Set ts = fso.CreateTextFile(fso.GetAbsolutePathName(".") & "\Page " & (qcount+1)*3 & ".htm",2)                       'see up above?  that should be bad feedback link...
   ts.writeline ipage
   ts.close
   set ts = nothing
   
   
   'if correct(i) = 0 then                    '!!!!!!!this needs to get converted into a loop that incriments "A)" and rolls through till it clicks with the "-1" 
     'ts.writeline "<br><a href=""Page " & (i+1)*3 -1 & ".htm""> A)  <\a>"  & answer(i*numba)

     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> B)/>  <\a>"  & answer(i*numba+1)
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> C)  <\a>"  & answer(i*numba+2)
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> D)  <\a>"  & answer(i*numba+3)
   'else if correct(i) = 1 then
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> A)  <\a>"  & answer(i*numba)

     'ts.writeline "<br><a href=""Page " & (i+1)*3 -1 & ".htm""> B)/>  <\a>"  & answer(i*numba+1)
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> C)  <\a>"  & answer(i*numba+2)
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> D)  <\a>"  & answer(i*numba+3)

     'else if correct(i) = 2 then
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> A)  <\a>"  & answer(i*numba)

     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> B)/>  <\a>"  & answer(i*numba+1)
     'ts.writeline "<br><a href=""Page " & (i+1)*3-1 & ".htm""> C)  <\a>"  & answer(i*numba+2)
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> D)  <\a>"  & answer(i*numba+3)

     'else if correct(i) = 3 then
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> A)  <\a>"  & answer(i*numba)

     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> B)/>  <\a>"  & answer(i*numba+1)
     'ts.writeline "<br><a href=""Page " & (i+1)*3 & ".htm""> C)  <\a>"  & answer(i*numba+2)
     'ts.writeline "<br><a href=""Page " & (i+1)*3-1 & ".htm""> D)  <\a>"  & answer(i*numba+3)   
     'end if
     
     'qcount = qcount + 1
next
   dim tpage
   
   tpage = "<body bgcolor=""Silver""><title>Begin Quiz</title><br>" & vbcrlf & chaptern & vbcrlf & "<br>Multiple Choice Quiz<br>" & vbcrlf & "<br>" & vbcrlf & vbcrlf & "<br>" & vbcrlf
   for i = 1 to numbq
      tpage = tpage & "<a href=""Page " & i*3-2 & ".htm"">Question " & i & "</a><br>" 
   next


   Set ts = fso.CreateTextFile(fso.GetAbsolutePathName(".") & "\Title Page.htm",2)
   ts.writeline tpage
   ts.close
   set ts = nothing
   

   
   
'next
  






' RENAME TO Ch XX Audit quiz


if asc(decrypt(correctsymbol)) <> asc("C") And Len(feedBk(0)) > 0 then 
   msgbox "looks like you didn't save testz.txt as an ANSI file.  Your feedback won't decrypt properly =/" & vbcrlf & "unless..." & vbcrlf  & "You open the file, and then choose ""Save as...""  and choose ""ANSI"" as the type."
'this presents itself as a rather creative way to encrypt a document in the commercial environment
else
   msgbox "DONE!"
end if

end if    'this traces back to the first if, lol



Holy cow that's a long script! Lol, well, at the time, I was apparently procrastinating quite a bit... To work it, goto http://highered.mcgr...hoice_quiz.html and copy and paste the source of that html page into a text file named testz.txt. Then, with that file in the same directory as "Quiz parser (online to instant).vbs", double click the VBS file. It will create a ton of html files that you can use differently from the way you use the online's quiz (the source that you copied into testz.txt). I think it's brilliant, other than the fact that it doesn't use function encapsulation, and it doesn't use regex (I kept thinking it would just be 1 more line, 1 more line, lol, so naive back then). I actually wrote that whole thing with out any code highlighting what soever!



Anyway, you need to think of everything in the world as a string (as you already seem to). A text file.. well that's a string. How about a first and last name? String, easy. An .exe? String (but you gotta be careful about encoding). Everything and everything is a string, get into that mind set. Now, what's an html page? Certainly just a string. There's very little more to it (although you might need to be careful with encoding here too, a change in encoding can make some characters behave unexpectedly, etc.)

Ok, so since a website is just a string, it can be parsed, lickity split, right? So how do we get a string representing our website? You could goto the website, right click somewhere on the page, and choose "view source" and then copy that into a text file and have your vbs script parse it.

http://www.jonasjohn...oad-webpage.htm
string webPage = DownloadWebPage("http://example.com")



Then, how do we parse it? For that, you have two options, regex, or what I did in that vb script (very buggy, and unpleasant to write and maintain...)
Function parset(theText)     'parse feedback   (I thought question too, but nope...)
   


   
   possitionz = InStr(1, theText, ": ")
   if possitionz <> 0 And 0 = InStr(1,strLine, "(1)") then 
      for i = 0 to UBound(newliner)
         theText = Replace(theText, newliner(i), newliner(i) & "<br>" & vbCrLf) 
      next
   End if
   
   For i = 0 to UBound(newliner2)
         theText = Replace(theText, newliner2(i), vbCrLf & "<br>" & newliner2(i) ) 
   Next

      'Cycle through the Replayce variables...  there's a set number, do loop for that set number...  set all the replace variables into an array and cycle up the array.  
   For i = 0 to UBound(Replayce)                                 
       theText = Replace(theText, Replayce(i), withthis(i))         ' replace all the stuff in the buffered file line appropriately
   Next 
   

   parset = theText   
End function




C# approximation

        string[] newliner = new string[] {"A.", "B.", "C.", "D.", "E.",":",";" };  // answers are prefixed with these types of characters...
        string[] newliner2= new string[] {"(1)", "(2)", "(3)","(4)","(5)","(6)"};

        string[] Replayce = new string[] { "*", "<", "..." };  // if these characters appear in our source text, they need to be replaced
        string[] withthis = new string[] { ";Safestar", ";SafeBracket", "you get the jist" }; // we can safely replace Replayce[i] with withthis[i]  Clever naming, huh?  =P


        private string parset(string theText)   // this function seems to read the text and format it to look pretty in my html interface... I think
        {
            // this returns -1 if ": " doesn't occur in theText
            // else it returns as the number representing the index of the occurance of ": "
            // This is an important one for parsing
            int possitionz = theText.IndexOf(": ", 1);  //  possitionz will contain the index of the first occurance of ": "

            if (possitionz != 0 && theText.IndexOf("(1)", 1) == -1)   // if the line has a "(1)" it's not the line we're looking for... I forget why...
            {
                for (int i = 0; i < newliner.Length; i++)
                {
                    theText = theText.Replace(newliner[i], newliner[i] + "<br>\n"); // this replaces what's in newliner[i] with newliner[i] + "<br>\n"  Due to poor naming... I'm not sure what this function actually does.  Sometimes I invent verbs such as 'parset' when I get into projects like these, but I forget to define them in my haste
                }

            }

            for (int i = 0; i < newliner2.Length; i++)
            {
                theText = theText.Replace(newliner2[i], newliner2[i] + "<br>\n"); // Replace(theText, newliner(i), newliner(i) & "<br>" & vbCrLf);
            }

            //'Cycle through the Replayce variables...  there's a set number, do loop for that set number...  set all the replace variables into an array and cycle up the array.  
            for (int i = 0; i < Replayce.Length; i++) //For i = 0 to UBound(Replayce)    
            {
                theText = theText.Replace(Replayce[i], withthis[i]);         // replace all the stuff in the buffered file line appropriately
            }

            return theText;
        }





Sadly, regex is a little slow, so if you're parsing something big like facebook, you might need to forgo regex and get gritty with things. But if you're don't need time critical responsiveness, then using regex is recommended (although I've been having a lot of difficulty learning it so far).

I think I might be running out of room and attention span so I'll through another c# translation in a following post.
Was This Post Helpful? 0
  • +
  • -

#5 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Making a Desktop App for Facebook

Posted 04 June 2011 - 07:30 PM


        int acount;     // answer count...
        int numba;      // number of answers?
        string[] answer;

        int qcount = 0;  // question count
        string[] question;

        private void theParseRoutine()
        {
            StreamReader ts = new StreamReader("c:\\bla.txt");

            //Do While Not ts.AtEndOfStream                                'this is the big loop that reads a line at a time, replaces the contents of the line with reasonable text, and stores the relevent text into  question(), answer(), feedBk(), and... yeah...
            while (!ts.EndOfStream)  // I read line by line from a text file...
            {
                string tvar = ts.ReadLine();   // read the next line

                for (int i = 0; i < Replayce.Length; i++)           // replace trouble characters --first thing!
                    tvar = tvar.Replace(Replayce[i], withthis[i]);


                if (tvar.IndexOf("'", tvar.Length - 3) != -1)           // checks to see if there's a ' mark in tvar, but it starts looking for it at that offset passed as a parameter.  It will return -1 if it isn't there.
                {
                    qcount = qcount + 1;
                }

                if (tvar.IndexOf("new makeQuestionObject") != -1)
                {
                    qcount = qcount + 1;
                    int refpoint = tvar.LastIndexOf("'", tvar.Length - 3); //  This might not work right... =/

                    question[qcount] = tvar.Substring(refpoint + 1, tvar.Length - refpoint - 3);
                    // might want to put msg box here to debug certain things... I did in my example anyway
                }

                if (tvar.IndexOf("new makeAnswerObject") != -1)
                {
                    if (qcount > 0)
                        if (acount == numba)
                            acount = 0;

                    int refpoint = tvar.LastIndexOf("'", tvar.Length - 3);

                    answer[qcount * numba + acount] = tvar.Substring(refpoint + 1, tvar.Length - refpoint - 3);
                    acount++;

                }
            }
        }




I couldn't find it just by skimming, but somewhere in there, you'll find some parsing where I'm looking for "<htmltag" and reading from there till "otherHTMLElement>". It's pretty badass, and surprisingly, this application is still functional... although with facebook, you'll probably have to update your routine monthly or so, or get the desired data in your first shot if it's not a live data project.

Let me know if you think I missed anything important.

Oh, and out of curiosity, what data are you parsing from the face?
Was This Post Helpful? 0
  • +
  • -

#6 The Architect 2.0  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 351
  • Joined: 22-May 08

Re: Making a Desktop App for Facebook

Posted 06 June 2011 - 04:17 AM

ya.....i just gave up and just used the standard dialog. I will try to do it in the background when i am much wiser. i honestly just couldn't understand what some of the POST arguments were(and some of them looked dynamically generated).

i would hope that c# has some library to parse HTML DOM.

thanks anyways :)
Was This Post Helpful? 0
  • +
  • -

#7 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4437
  • View blog
  • Posts: 7,709
  • Joined: 08-June 10

Re: Making a Desktop App for Facebook

Posted 06 June 2011 - 07:04 AM

Quote

i would hope that c# has some library to parse HTML DOM.


It does. It's called the Html Agility Pack.
Was This Post Helpful? 1
  • +
  • -

#8 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Making a Desktop App for Facebook

Posted 06 June 2011 - 01:20 PM

Oh yeah I've used that before in a different kind of project, lol. But it's likely to run into the same types of performance problems as the regex method if it's a time critical app.

This post has been edited by Curtis Rutland: 06 June 2011 - 01:30 PM
Reason for edit:: removed quote

Was This Post Helpful? 0
  • +
  • -

#9 Curtis Rutland  Icon User is online

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4437
  • View blog
  • Posts: 7,709
  • Joined: 08-June 10

Re: Making a Desktop App for Facebook

Posted 06 June 2011 - 01:31 PM

Possibly. It looks to be using both Regex and XPath. But I find it unlikely that time is going to be a critical factor in a Facebook application.
Was This Post Helpful? 0
  • +
  • -

#10 NotarySojac  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 53
  • View blog
  • Posts: 428
  • Joined: 30-September 10

Re: Making a Desktop App for Facebook

Posted 06 June 2011 - 06:13 PM

Probably for this guys case, unless he's polling thousands of user's status updates, tags, pokes, etc and generating a realtime picture of "public awareness" of some political/social issue which you could reference against a media/events timeline. I think there'd be bandwidth bottle neck that would get in the way anyway so even then optimization would be of less concern =/
Was This Post Helpful? 0
  • +
  • -

#11 The Architect 2.0  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 351
  • Joined: 22-May 08

Re: Making a Desktop App for Facebook

Posted 06 June 2011 - 07:18 PM

lol, for the record, i'm not caring too much about performance
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1