Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Download URL overriding cache

Status
Not open for further replies.

jumpjack

Programmer
Jul 28, 2006
79
IT
I need to periodically download a file from internet, but I don't want to see the cached one, I need the file to be always the updated version.
How can I accomplish this task?

I'm trying several methods, none works. This is a RapidQ source (a VB-clone, quite similar in syntax to VB):
Code:
$DEFINE DOWNLOAD DOWNLOAD

 '$APPTYPE GUI
 $TYPECHECK ON
 $INCLUDE "RAPIDQ.INC"

' const FILENAME = "temperature.txt"
 const LOC1 = "GUIDONIA"
 const LOC2 = "ROME"
 const OFFSET1 = 40
 const OFFSET2 = 36

 declare sub buttonclick
 declare sub TimerOver

'DEFSTR URL = "[URL unfurl="true"]http://mobile.wunderground.com/auto/mobile_metric/global/IY.html"[/URL]
DEFSTR URL = "[URL unfurl="true"]http://toi.iriti.cnr.it/it/rightime.shtml"[/URL]

dim timer1 as qtimer
Timer1.Interval = 3000
Timer1.Enabled = 1          
Timer1.OnTimer = TimerOver

Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" (ByVal lpszUrlName As String) As Long

declare Function DownloadFile(URL As String) As String

declare Function DownloadFile2(URL As String, LocalFilename As String) As integer

declare FUNCTION GetFileHTTP (URL AS STRING, toFile AS STRING) AS LONG

DECLARE FUNCTION FGetFileHTTP_URLDownloadToFile LIB "urlmon" ALIAS "URLDownloadToFileA" _
      (BYVAL pCaller AS LONG, ByRef szURL AS STRING, ByRef szFileName AS STRING, _
      BYVAL dwReserved AS LONG, BYVAL lpfnCB AS LONG) AS LONG

Declare Function URLDownloadToCacheFile Lib "urlmon" Alias "URLDownloadToCacheFileA" _
	( lpUnkcaller As Long, _
	szURL As String, _
	byref szFileName As String, _
	dwBufLength As Long, _
	dwReserved As Long, _
	IBindStatusCallback As Long) As Long

Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" ( _
	ByVal pCaller As Long, _
	ByVal szURL As String, _
	ByVal szFileName As String, _
	ByVal dwReserved As Long, _
	ByVal lpfnCB As Long _
	) As Long

CREATE Font1 AS QFONT
  Name = "Courier New"
  Size = 30
END CREATE
    
create ClockForm as qform
  	width = 600
  	height = 400
  	center
  	borderstyle = bsNone
  	create timelab as qlabel
 		top = 0
  		left = 0
  		width = 160
  		caption = "Downloading data..."
  	end create
  	create richedit1 as qrichedit
  	       top = 20
  	       left = 10
  	       width = 550
  	       height = 350
   end create
end create
timelab.caption = "Downloading data..."

clockform.showmodal

 SUB ButtonClick
     dim inputfile as qfilestream
     dim filecontent as string
     dim temp1 as string
     dim temp2 as string
	 defint inizio, fine, lung
	dim FileName as string
	dim OutFileName as string


$IFDEF DOWNLOAD
'	FileName = DownloadFile(URL)
'	kill FileName
 '	outFileName = FileName
FileName = "c:\documenti\download2.txt"
kill FileName
DownloadFile2 URL, FileName
$ELSE
		FileName = "c:\documenti\test.txt"
		kill FileName
	 	outFileName = FileName

	     IF GetFileHTTP (URL, outFileName) THEN
	      'PRINT "Download Error : " & URL
	     ELSE
	      'PRINT "Download Finished & OK : " & URL & " stored in " & outFileName
	     END IF
$endif

	inputfile.open(outFileName,fmOpenRead)
	filecontent = inputfile.readstr(inputfile.size)
	inputfile.close
'	inizio = instr(ucase$(filecontent),ucase$(LOC1))+OFFSET1
'	temp1 =  mid$(filecontent,inizio,10) ' Prende temperatura e simboli ">" e "<" circostanti
'	fine = inizio + instr(temp1,"<")-1
'	inizio = inizio + instr(temp1,">")+1
'	lung = fine-inizio+1
'	temp1 = mid$(filecontent,inizio-1,lung)

'	inizio = instr(ucase$(filecontent),ucase$(LOC2))+OFFSET2
'	temp2 =  mid$(filecontent,inizio,10) ' Prende temperatura e simboli ">" e "<" circostanti
'	fine = inizio + instr(temp2,"<")-1
'	inizio = inizio + instr(temp2,">")+1
'	lung = fine-inizio+1
'	temp2 = mid$(filecontent,inizio-1,lung)
'	timelab.caption = LOC2 & ":" &temp2 & ", " & LOC1 & ":" & temp1 & " (" & left$(time$,8) & ")"
	richedit1.text= filecontent
 end sub


sub TimerOver
	timer1.interval = 3000
	call buttonclick
end sub

Function DownloadFile(URL As String) As String
	Dim szFileName As String
	dim zz as long
	szFileName = Space$(300)
	szFileName ="DownloadFile.txt"
    print "DEL:" & str$(DeleteUrlCacheEntry(URL))
    kill szFileName
	zz=URLDownloadToCacheFile(0, URL, szFileName, Len(szFileName), 0, 0)
	print "DownloadFile: saved to " & szFileName
	DownloadFile = szFileName
End Function

FUNCTION GetFileHTTP (URL AS STRING, toFile AS STRING) AS LONG
	DEFSTR sURL, sToFile
	sURL = URL
	sToFile = toFile
	kill toFile
    print "DEL:" & str$(DeleteUrlCacheEntry(URL))
	GetFileHTTP = FgetFileHTTP_URLDownloadToFile (0, sURL, sToFile, 0, 0)
	print "GetFileHTTP: saved to " & toFile
END FUNCTION

Public Function DownloadFile2(URL As String, LocalFilename As String) As integer
    Dim lngRetVal As Long
    print "DEL: " & str$(DeleteUrlCacheEntry(URL))
    kill LocalFileName
    lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
    If lngRetVal = 0 Then DownloadFile = True
End Function


-- Jumpjack --
 
Wow. Port this.

Brian

oHTTP = CreateObject("MSXML2.XMLHTTP")
oHTTP.Open("GET", " .f.)
oHTTP.Send
cResult=(oHTTP.ResponseText)

nStart = 4+ATC("<H1>", cResult)
nEnd = ATC("</H1>", cResult)

cDateTme = ALLTRIM(SUBSTR(cResult, nStart, nEnd-nStart))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top