Hi all,
I present to you, in one Large-messy-code production:
Strong Bad Email Collector. Does what it says in the box, and (hopefully) stays in the background and lets you know when a new one comes out :P
Now, I wrote it in B3D, then got a hand converting it to Blitz+. Since I don't Own Blitz+, i cant help with any B+ related issues with the source.
Lemme know if there are any problems!
-------------------------
BLITZ+ Code
-------------------------
--------------------
Blitz2D/3D code
--------------------
I present to you, in one Large-messy-code production:
Strong Bad Email Collector. Does what it says in the box, and (hopefully) stays in the background and lets you know when a new one comes out :P
Now, I wrote it in B3D, then got a hand converting it to Blitz+. Since I don't Own Blitz+, i cant help with any B+ related issues with the source.
Lemme know if there are any problems!
-------------------------
BLITZ+ Code
-------------------------
Global http$="http:"+Chr$(47)+Chr$(47) AppTitle "New StrongBad Email" Global wc TCPTimeouts 2000,2000 Global website$="www.homestarrunner.com" Global bnksize=8*1024 Global bank1=CreateBank(bnksize) updated$="" Global minfilesize=1024*1 Global downloadroot$="emails" If FileType("emails")<>2 Then CreateDir("emails") If FileType("getsbad.ini")=0 Then fs=WriteFile("getsbad.ini"):WriteLine fs,"1":CloseFile fs fs=ReadFile("getsbad.ini") counter=ReadLine(fs) CloseFile fs For oo=1 To 1024 file$="sbemail"+Str$(oo)+".swf" If FileType(downloadroot$+file$)=1 Then If FileSize(downloadroot$+file$)<minfilesize Then DeleteFile downloadroot$+file$ EndIf Next .again For oo=counter To 1024 counter=oo gfile$="sbemail"+Str$(oo)+".html" file$=getfilename(gfile$) If file$="404error.swf" Then file$="" If file$<>"" Then OUTPUT "found filename; "+file$ If FileType(downloadroot$+file$)=1 Then DeleteFile downloadroot$+file$ If FileType(downloadroot$+file$)=0 Then tcp = HttpGet(website$,"/"+file$) If tcp = False RuntimeError "unable to connect to address" OUTPUT "Getting "+file$ fs=WriteFile(downloadroot$+file$) found=0 Repeat n$=ReadLine$(tcp) If Left$(n$,16)="Content-Length: " Then size=Mid$(n$,17) OUTPUT n$ If Len(n$)<3 Then found=1 wait:Until Eof(tcp)=True Or found=1 Or KeyDown(1) If found=0 Then OUTPUT "not found":CloseFile fs:DeleteFile downloadroot$+file$ If KeyDown(1) Then found=0 If found=0 Or size=0 Then Goto Endbit count=0 done=0 Repeat ms=MilliSecs():Repeat:av=ReadAvail(tcp):wait:Until av>0 Or (MilliSecs()-ms)>1000;:av=av-1 ;If av>bnksize Then av=bnksize ;av=1 ;If av=0 And MilliSecs()-lc>500 Then done=1;If count>=size-bnksize Then done=1 If count>=size Then done=1 If av<>0 Then count=count+av ReadBytes (bank1,tcp,0,av) WriteBytes(bank1, fs,0,av) EndIf If KeyHit(1) Then found=0 wait:Until done=1 Or Eof(tcp) Or KeyDown(1) If KeyDown(1) Then found=0 .Endbit OUTPUT "Ending" CloseFile fs If FileSize(downloadroot$+file$)>minfilesize And found=1 Then fcnt=0:counter=counter+1:If updated="" Then updated=file$ If FileSize(downloadroot$+file$)<minfilesize Or found=0 Then DeleteFile downloadroot$+file$:fcnt=fcnt+1:OUTPUT "Invalid file" EndIf Else fcnt=fcnt+1 EndIf If fcnt>4 Then oo=99999: If found=1 And fcnt=0 Then updatecounter(counter) Next CloseTCPStream(tcp) If updated<>"" Then result=Confirm("There is a new Strong Bad Email available."+Chr$(13)+Chr$(10)+"Would you like to view it?") If result=1 Then ExecFile "iexplore.exe "+CurrentDir$()+downloadroot$+updated EndIf For nmt=0 To 1000 Delay 60*60 Next Goto again Function getfilename$(webfile$) Local tcp = HttpGet(website$,"/"+webfile$) Local found,n$,ret$ Local find$=" <PARAM NAME=movie VALUE="+Chr$(34) If tcp = False RuntimeError "unable To connect To address" found=0 ms=MilliSecs() Repeat n$=ReadLine$(tcp) If Instr(n$,find$) Then ret$=Mid$(n$,Instr(n$,find$)+Len(find$)) ret$=Mid$(ret$,1,Instr(ret$,Chr$(34))-1) found=1 EndIf If Left$(n$,16)="Content-Length: " Then size=Mid$(n$,17) wait:Until Eof(tcp)=True Or found=1 Or KeyDown(1) Or (MilliSecs()-ms)>1000 If KeyDown(1) Then End Return ret$ End Function ;example of using a proxy server tcp = HttpGet("www.blitzbasic.com","/Home/_index_.php",80,"planet1.scs.cs.nyu.edu",3128) If tcp = False RuntimeError "unable to connect to address" While Eof(tcp) = False If KeyDown(1) Then End DebugLog ReadLine$(tcp) Wend CloseTCPStream(tcp) ;function Function HttpGet(server$,path$,port=80,proxy$="",proxyport=0) Local www If Len(proxy$) = 0 proxy$ = server$ If proxyport = 0 proxyport = port www = OpenTCPStream(proxy$,proxyport) If www = False Return False WriteLine www,"GET "+http$+ server$ + ":" + port + path$ + " HTTP/1.1" + Chr$(13)+Chr$(10) + "Host: " + server$ + Chr$(13)+Chr$(10) + "User-Agent: blitzbasic" + Chr$(13)+Chr$(10) + "Accept: */*" + Chr$(13)+Chr$(10) Return www CloseTCPStream(tcp) End Function Function wait() wc=(wc+1) Mod 20:If wc=0 Then Delay 2 End Function Function OUTPUT(N$) DebugLog n$ End Function Function updatecounter(counter) Local fs=WriteFile("getsbad.ini") WriteLine fs,Str$(counter) CloseFile fs End Function
--------------------
Blitz2D/3D code
--------------------
Global http$="http:"+Chr$(47)+Chr$(47) AppTitle "New StrongBad Email" Global wc TCPTimeouts 2000,2000 Global website$="www.homestarrunner.com" Global bnksize=8*1024 Global bank1=CreateBank(bnksize) updated$="" Global minfilesize=1024*1 Global downloadroot$="emails" If FileType("emails")<>2 Then CreateDir("emails") If FileType("getsbad.ini")=0 Then fs=WriteFile("getsbad.ini"):WriteLine fs,"1":CloseFile fs fs=ReadFile("getsbad.ini") counter=ReadLine(fs) CloseFile fs For oo=1 To 1024 file$="sbemail"+Str$(oo)+".swf" If FileType(downloadroot$+file$)=1 Then If FileSize(downloadroot$+file$)<minfilesize Then DeleteFile downloadroot$+file$ EndIf Next .again For oo=counter To 1024 counter=oo gfile$="sbemail"+Str$(oo)+".html" file$=getfilename(gfile$) If file$="404error.swf" Then file$="" If file$<>"" Then OUTPUT "found filename; "+file$ If FileType(downloadroot$+file$)=1 Then DeleteFile downloadroot$+file$ If FileType(downloadroot$+file$)=0 Then tcp = HttpGet(website$,"/"+file$) If tcp = False RuntimeError "unable to connect to address" OUTPUT "Getting "+file$ fs=WriteFile(downloadroot$+file$) found=0 Repeat n$=ReadLine$(tcp) If Left$(n$,16)="Content-Length: " Then size=Mid$(n$,17) OUTPUT n$ If Len(n$)<3 Then found=1 wait:Until Eof(tcp)=True Or found=1 Or KeyDown(1) If found=0 Then OUTPUT "not found":CloseFile fs:DeleteFile downloadroot$+file$ If KeyDown(1) Then found=0 If found=0 Or size=0 Then Goto Endbit count=0 done=0 Repeat ms=MilliSecs():Repeat:av=ReadAvail(tcp):wait:Until av>0 Or (MilliSecs()-ms)>1000;:av=av-1 ;If av>bnksize Then av=bnksize ;av=1 ;If av=0 And MilliSecs()-lc>500 Then done=1;If count>=size-bnksize Then done=1 If count>=size Then done=1 If av<>0 Then count=count+av ReadBytes (bank1,tcp,0,av) WriteBytes(bank1, fs,0,av) EndIf If KeyHit(1) Then found=0 wait:Until done=1 Or Eof(tcp) Or KeyDown(1) If KeyDown(1) Then found=0 .Endbit OUTPUT "Ending" CloseFile fs If FileSize(downloadroot$+file$)>minfilesize And found=1 Then fcnt=0:counter=counter+1:If updated="" Then updated=file$ If FileSize(downloadroot$+file$)<minfilesize Or found=0 Then DeleteFile downloadroot$+file$:fcnt=fcnt+1:OUTPUT "Invalid file" EndIf Else fcnt=fcnt+1 EndIf If fcnt>4 Then oo=99999: If found=1 And fcnt=0 Then updatecounter(counter) Next CloseTCPStream(tcp) If updated<>"" Then result=1;Confirm("There is a new Strong Bad Email available."+Chr$(13)+Chr$(10)+"Would you like to view it?") If result=1 Then ExecFile "iexplore.exe "+CurrentDir$()+downloadroot$+updated EndIf For nmt=0 To 1000 Delay 60*60 Next Goto again Function getfilename$(webfile$) Local tcp = HttpGet(website$,"/"+webfile$) Local found,n$,ret$ Local find$=" <PARAM NAME=movie VALUE="+Chr$(34) If tcp = False RuntimeError "unable To connect To address" found=0 ms=MilliSecs() Repeat n$=ReadLine$(tcp) If Instr(n$,find$) Then ret$=Mid$(n$,Instr(n$,find$)+Len(find$)) ret$=Mid$(ret$,1,Instr(ret$,Chr$(34))-1) found=1 EndIf If Left$(n$,16)="Content-Length: " Then size=Mid$(n$,17) wait:Until Eof(tcp)=True Or found=1 Or KeyDown(1) Or (MilliSecs()-ms)>1000 If KeyDown(1) Then End Return ret$ End Function ;example of using a proxy server tcp = HttpGet("www.blitzbasic.com","/Home/_index_.php",80,"planet1.scs.cs.nyu.edu",3128) If tcp = False RuntimeError "unable to connect to address" While Eof(tcp) = False If KeyDown(1) Then End DebugLog ReadLine$(tcp) Wend CloseTCPStream(tcp) ;function Function HttpGet(server$,path$,port=80,proxy$="",proxyport=0) Local www If Len(proxy$) = 0 proxy$ = server$ If proxyport = 0 proxyport = port www = OpenTCPStream(proxy$,proxyport) If www = False Return False WriteLine www,"GET "+http$+ server$ + ":" + port + path$ + " HTTP/1.1" + Chr$(13)+Chr$(10) + "Host: " + server$ + Chr$(13)+Chr$(10) + "User-Agent: blitzbasic" + Chr$(13)+Chr$(10) + "Accept: */*" + Chr$(13)+Chr$(10) Return www CloseTCPStream(tcp) End Function Function wait() wc=(wc+1) Mod 20:If wc=0 Then Delay 2 End Function Function OUTPUT(N$) DebugLog n$ Print n$ End Function Function updatecounter(counter) Local fs=WriteFile("getsbad.ini") WriteLine fs,Str$(counter) CloseFile fs End Function