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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

population of italy live/real time

Status
Not open for further replies.
Are you sure it is real population data? A selection of page source i Firefox referring to Italy population function:

[pre]function drawItalia() {
//popolazione di partenza al giorno 15 novembre 2022
partenza = 58969856;
//unixtime 15 novembre 2022 = 1668470400;
partenzaSec = 1668470400;
var my_date = new Date();
incAnnuale = -170000;
now = Math.round(my_date.getTime()/1000);
incSecondo = (incAnnuale/(365.25*(86400/2)));
// console.log(incSecondo);
secPassati = (now - partenzaSec)/2;
casualeInMeno = randRange(1,4);
// console.log("casuale in meno:::" + casualeInMeno);
casuale = (Math.round(Math.random(1))*5) - casualeInMeno;
totPop = partenza + (Math.round(secPassati*incSecondo)) + casuale;
totPop = format(0,".",",",totPop);
jQuery('#divItalia').html(totPop);
jQuery('#divItalia_mobile').html(totPop);
}[/pre]



combo
 
In the same way, a selection of chart data:

[pre]{c:[{v:new Date( 2018 ,6,1)},{v: 59877425 }]},
{c:[{v:new Date( 2019 ,6,1)},{v: 59727932 }]},
{c:[{v:new Date( 2020 ,6,1)},{v: 59500579 }]},
{c:[{v:new Date( 2021 ,6,1)},{v: 59240329 }]},
{c:[{v:new Date( 2022 ,6,1)},{v: 59037474 }]},
{c:[{v:new Date( 2023 ,6,1)},{v: 58870762 }]}, {c:[{v:new Date( 2024 ,6,1)},{v: 58697744 }]}
]});[/pre]

Take 58870762 for Jul. 1, 2023, 58697744 for Jul. 1 2024, linear approximation with year = 365.242 days, possible adjustment for time zone.

combo
 
> the real time of population

They are not really realtime. Both pages you link to are using a calculation based on a starting population, and an estimated annual population converted into a per second rate change.

Rather than scrape the page, just do the calculation yourself, an example of which combo shows in his first post above
 
As I said "both pages you link to are using a calculation", based on the population on a starting date starting date and an annual change. The first page you linked, and commented on by combo uses a start date of 15 November 2022, a starting population of 1668470400 and an annual change of -170000 (it is not clear where the data for this came form). The second page appears to be using aa startdate of 1 July 2022, a starting population of , and an annual change of -166712 (data appears to be 'Worldometer elaboration of the latest United Nations data')

The point is that the data is NOT live, and ytou can do the calculations yourself, e.g

Code:
[COLOR=blue]Public Sub doit()
    Dim partenza As Long
    Dim incAnnuale As Long
    Dim incSecondo As Double
    Dim secPassati As Long

    
    partenza = 58969856
    incAnnuale = -170000
    incSecondo = (incAnnuale / (365.25 * (86400)))
    secPassati = DateDiff("s", DateSerial(2022, 11, 15), Now)  [COLOR=green]'22 December 2022[/color]
    Debug.Print partenza + Int(secPassati * incSecondo)
    
    partenza = 58969856
    incAnnuale = -166712
    incSecondo = (incAnnuale / (365.25 * (86400)))
    secPassati = DateDiff("s", DateSerial(2022, 6, 1),Now,)  [COLOR=green]'1 July 2022[/color]
    Debug.Print partenza + Int(secPassati * incSecondo)
    
End Sub[/color]
 
hi strong, tks
but how to run this code to show a label with counter?
peraphs with a timer.time?
 
Hi strong.... found this:

Option Explicit
Sub UpdateItalianPopulation()

Dim http As New MSXML2.XMLHTTP60
Dim url As String
Dim responseText As String
Dim population As Long

url = "
http.Open "GET", url, True
http.setRequestHeader "Content-Type", "application/json"
http.send

While http.readyState <> 4
DoEvents
Wend

If http.Status = 200 Then

responseText = http.responseText
population = CLng(ParseJsonForPopulation(responseText))

'Me.PopulationLabel.Caption = Format(population, "#,##0")

Else
MsgBox "Error fetching population data: " & http.Status & " - " & http.statusText
End If

End Sub
Private Function ParseJsonForPopulation(jsonText As String) As String

Dim json As Object
Set json = CreateObject("Newtonsoft.Json.JsonObject")
json.LoadJSON jsonText
ParseJsonForPopulation = json("population")

End Function
Private Sub UserForm_Initialize()

UpdateTimer.Interval = 60000 ' 60 seconds
UpdateTimer.Enabled = True

End Sub
Private Sub UpdateTimer_Timer()

UpdateItalianPopulation

End Sub
Private Sub Form_Load()

UpdateItalianPopulation

End Sub

but have error 12007!

have an idea?
tks
 
>peraphas with timer.time

Sure

Code:
[COLOR=blue]Option Explicit

Public Sub doit()
    Dim partenza As Long
    Dim incAnnuale As Long
    Dim incSecondo As Double
    Dim secPassati As Long

    
    partenza = 58969856
    incAnnuale = -170000
    incSecondo = (incAnnuale / (365.25 * (86400)))
    secPassati = DateDiff("s", DateSerial(2022, 11, 15), Now)  [COLOR=green]'22 December 2022
[/color]    Label1 = partenza + Int(secPassati * incSecondo)
    
    partenza = 58969856
    incAnnuale = -166712
    incSecondo = (incAnnuale / (365.25 * (86400)))
    secPassati = DateDiff("s", DateSerial(2022, 6, 1), Now) [COLOR=green] '1 July 2022[/color]
    Label2 = partenza + Int(secPassati * incSecondo)
    
End Sub

Private Sub Form_Load()
    Timer1.Enabled = True
    Timer1.Interval = 1000
    doit
End Sub

Private Sub Timer1_Timer()
    doit
End Sub[/color]
 
tks!!!!! bro
but have posted a new resource with rest Api.
but have error 12007
 
> error 12007

Seriously? You can't even be bothered to do a google for an error code? Wow ..

12007 indicates that there is something wrong with your URL (are you sure worldpopulationreview supports a REST api, and if so are you sure that api.worldpopulationreview.com is the REST root?)

But even if you fix that, your attempt to use the Newtonsoft json library won't work, since it is designed for .NET. So, unless you have written a COM wrapper for the assembly, which I feel unlikely, or got someone else to provide one, then

Set json = CreateObject("Newtonsoft.Json.JsonObject")

will fail. There are free json libraries designed to work with VB6 - but we have previously shown you how to extract json data without requiring such a 3rd party library. Perhaps you could refer to those examples.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top