pradeeps01 / yahoo-finance-managed

Automatically exported from code.google.com/p/yahoo-finance-managed
0 stars 0 forks source link

Add Sync Download to NonApi.IDSearchDownload #16

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What is the main issue of your suggestion?
I thing it's useful addiction (I needed it ...)

I've aleady modified the source code, and it works well, this is my 
implementation (add this to your base file, I've fixed german server for ISIN):

        'Modified for Sync Download
        Private mTextEncoding As System.Text.Encoding = System.Text.Encoding.UTF8

        ''' <summary>
        ''' Downloads the specified text.
        ''' </summary>
        ''' <param name="text">The text.</param>
        ''' <param name="userArgs">The user args.</param><returns></returns>
        Public Function Download(ByVal text As String, Optional ByVal userArgs As Object = Nothing) As API.IDSearchResponse
            If text.Trim = String.Empty Then Throw New ArgumentNullException("text", "The text is empty.")
            mFinished = False

            Dim dlArgs As AsyncDownloadRecursiveArgs = New AsyncDownloadRecursiveArgs(userArgs)
            dlArgs.PagesStarted += 1
            dlArgs.Text = text.Trim
            dlArgs.Options = New IDSearchOptions(mOptions)

            Dim url As String = Me.DownloadURLGer(dlArgs.Text, dlArgs.Options, dlArgs.PagesStarted)
            MyBase.DownloadStream(url)

            Return Me.ToResponse(MyBase.DownloadStream(url))

        End Function

        ''' <summary>
        ''' the response.
        ''' </summary>
        ''' <param name="resp">The resp.</param><returns></returns>
        Private Function ToResponse(ByVal resp As Base.StreamResponse) As API.IDSearchResponse
            Dim text As String = mHelper.StreamToString(resp.Result, mTextEncoding)
            Return New API.IDSearchResponse(resp.Connection, ToSearchResults(text))
        End Function
        'end modification

hope it helps
Regards /// Angelo

Original issue reported on code.google.com by i...@advancedcomputing.ch on 1 Jun 2011 at 12:31

GoogleCodeExporter commented 8 years ago
I implemented that function so:

        ''' <summary>
        ''' Downloads search results for Yahoo IDs by keyword and other options
        ''' </summary>
        ''' <param name="text">The used search text</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function Download(ByVal text As String) As API.IDSearchResponse
            If text.Trim = String.Empty Then Throw New ArgumentNullException("text", "The text is empty.")
            Dim url As String = Me.DownloadURL(text, mOptions, 0)
            Dim resp = MyBase.DownloadString(url)
            Return New API.IDSearchResponse(resp.Connection, Me.ToSearchResults(resp.Result, mOptions.Server))
        End Function

(--> ToSearchResults and DownloadURL functions changed; in next version 
different servers will be supported; different server = different priority for 
loacalized search results; i.e. Server=Germany --> more results for german 
stock exchanges in NoRanking-mode (new value in RankedBy option); supported 
servers at the moment: Canada, France, Germany, Spain, UK, USA)

NonAPI.IDSearch inherits from Base.StringDownload so you don't need an extra 
Encoding (MyBase.DownloadString). Also, because of being a sync download 
Download function doesn't need userArgs, because you can access the same 
parameters/options after calling the function. There is no possibility in sync 
download to change or lost options configuration while downloading. ([Options] 
property in IDSearchDownloadCompletedEventArgs exists because of that issue; 
it's a clone from the options when downloading started)

A problem is the [Count] option. It suggests a possibility of getting more than 
20 results, but it's not the case in sync downloading. You can just download 
maximum 20 results per request. 
I didn't implement a limiting function for a [Count] less than 20. That would 
be possible by deleting received reults from the array. You'll always get 20 
results or the rest count depending to the [Start] option (i.e. Start=20; 
MaxResults=22; ResultCount=2).

greetz

Maas

Original comment by Maas...@gmail.com on 2 Jul 2011 at 2:54

GoogleCodeExporter commented 8 years ago
fixed/done

Original comment by Maas...@gmail.com on 14 Jul 2011 at 10:01