Android Question Download file from GitHub repository

Mike1970

Well-Known Member
Licensed User
Longtime User
Hi everyone.
I never used github but now I need to download a file from a repository.
I have a repository , and I want to download only the latest added file.
It’s possibile to do this in b4x?
Thanks in advance.
 

Lucas Siqueira

Active Member
Licensed User
Longtime User
Hi everyone.
I never used github but now I need to download a file from a repository.
I have a repository , and I want to download only the latest added file.
It’s possibile to do this in b4x?
Thanks in advance.

you can download the file, or you can get the data from the page using okhttp



B4X:
Sub DownloadAndSaveFile (Link As String)
   Dim j As HttpJob
   j.Initialize("", Me)
   j.Download(Link)
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
       Dim out As OutputStream = File.OpenOutput(File.DirInternal, "filename.dat", False)
     File.Copy2(job.GetInputStream, out)
     out.Close '<------ very important
   End If
   j.Release
End Sub


B4X:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.google.com")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
   Log(j.GetString)
End If
j.Release
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
Tha
you can download the file, or you can get the data from the page using okhttp



B4X:
Sub DownloadAndSaveFile (Link As String)
   Dim j As HttpJob
   j.Initialize("", Me)
   j.Download(Link)
   Wait For (j) JobDone(j As HttpJob)
   If j.Success Then
       Dim out As OutputStream = File.OpenOutput(File.DirInternal, "filename.dat", False)
     File.Copy2(job.GetInputStream, out)
     out.Close '<------ very important
   End If
   j.Release
End Sub


B4X:
Dim j As HttpJob
j.Initialize("", Me)
j.Download("https://www.google.com")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
   Log(j.GetString)
End If
j.Release
THanks i will try it out later!
 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
Tha

THanks i will try it out later!

here's the sample source code

remembering that I accessed raw, to get the file link.

1582982037483.png
 

Attachments

  • download_github.zip
    12.4 KB · Views: 308
Last edited:
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
It works beautifully.
but it works only to ONE file.

unfortunately the repository I have to use updates once a day with a NEW file, not updating the previous.

so I need to get the last file and then read it

can you send which is the github directory you want to get the files from?
 
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
can you send which is the github directory you want to get the files from?
Oh i noticed that for the same datas there is the time-series version (that I can use with your example), and daily-report (that is what I was talking about):

 
Upvote 0

Lucas Siqueira

Active Member
Licensed User
Longtime User
Oh i noticed that for the same datas there is the time-series version (that I can use with your example), and daily-report (that is what I was talking about):


apparently it is simple to solve your case, the published file always has the same name ... month-day-year ...
so I got the base of the link: https://raw.githubusercontent.com/C...se_covid_19_data/csse_covid_19_daily_reports/

and add in it the name of the file formed by the month-day-year.csv
that way you will always download the file of the day, updated!

I try to download the file of the current date, if it does not exist, the app tries to download the one from the previous day, if it does not exist the app will try until the previous 5 days.
 

Attachments

  • download_github.zip
    12.7 KB · Views: 332
Upvote 0

Mike1970

Well-Known Member
Licensed User
Longtime User
apparently it is simple to solve your case, the published file always has the same name ... month-day-year ...
so I got the base of the link: https://raw.githubusercontent.com/C...se_covid_19_data/csse_covid_19_daily_reports/

and add in it the name of the file formed by the month-day-year.csv
that way you will always download the file of the day, updated!

I try to download the file of the current date, if it does not exist, the app tries to download the one from the previous day, if it does not exist the app will try until the previous 5 days.
OOOOOO OK! thanks i didn't thought to have a variable link!! Thanks for you help and precious tips!!
 
Upvote 0
Top