Worldometer: Scraping & API¶
Get current metrics in the world with the python worldometer module
Index¶
Worldometer Docs:
- worldometer.core
Worldometer
- worldometer.api
abortions_this_year()
bicycles_produced_this_year()
births_this_year()
births_today()
blog_posts_written_today()
cars_produced_this_year()
cellular_phones_sold_today()
cigarettes_smoked_today()
co2_emissions_this_year()
coal_left()
communicable_disease_deaths_this_year()
computers_produced_this_year()
current_world_population()
days_to_the_end_of_coal()
days_to_the_end_of_natural_gas()
days_to_the_end_of_oil()
deaths_caused_by_alcohol_this_year()
deaths_caused_by_cancer_this_year()
deaths_caused_by_hiv_aids_this_year()
deaths_caused_by_malaria_this_year()
deaths_caused_by_smoking_this_year()
deaths_caused_by_water_related_diseases_this_year()
deaths_of_children_under_5_this_year()
deaths_of_mothers_during_birth_this_year()
deaths_this_year()
deaths_today()
desertification_this_year()
emails_sent_today()
energy_used_today()
forest_loss_this_year()
get_metric_of()
google_searches_today()
hiv_aids_infected_people()
internet_users_in_the_world_today()
land_lost_to_soil_erosion_this_year()
money_spent_for_obesity_related_diseases_in_the_usa_today()
money_spent_on_illegal_drugs_this_year()
money_spent_on_videogames_today()
money_spent_on_weight_loss_programs_in_the_usa_today()
natural_gas_left()
net_population_growth_this_year()
net_population_growth_today()
new_book_titles_published_this_year()
newspapers_circulated_today()
non_renewable_sources()
obese_people_in_the_world()
oil_left()
oil_pumped_today()
overweight_people_in_the_world()
people_who_died_of_hunger_today()
people_with_no_access_to_a_safe_drinking_water_source()
public_education_expenditure_today()
public_healthcare_expenditure_today()
public_military_expenditure_today()
renewable_sources()
road_traffic_accident_fatalities_this_year()
seasonal_flu_deaths_this_year()
solar_energy_striking_earth_today()
suicides_this_year()
toxic_chemicals_released_in_the_environment_this_year()
tv_sets_sold_worldwide_today()
tweets_sent_today()
undernourished_people_in_the_world()
update_metrics()
water_used_this_year()
About¶
Worldometer is a python module that collects data from worldometers.info and provides a simple and self-explanatory interface for using the data.
worldometers.info¶
“Worldometer is run by an international team of developers, researchers, and volunteers with the goal of making world statistics available in a thought-provoking and time relevant format to a wide audience around the world. It is published by a small and independent digital media company based in the United States. We have no political, governmental, or corporate affiliation. Furthermore, we have no investors, donors, grants, or backers of any type. We are completely independent and self-financed through automated programmatic advertising sold in real time on multiple ad exchanges.”
More info: worldometers.info/about
How it works?¶
[Adapted]: “For the data, is elaborate instead a real-time estimate through a proprietary algorithm which processes the latest data and projections provided by the most reputable organizations and statistical offices in the world.”
More info about data source: worldometers.info/sources
Install¶
First, create a directory and enter it:
$ mkdir my_project && cd my_project
Create a virtual environment to avoid breaking dependence on other projects.
This project uses pipenv, it already does it alone 😆:
$ pipenv install worldometer
But you can use virtualenv
+ pip
if you prefer:
$ virtualenv venv && source venv/Scripts/activate
Now install:
$ pip install worldometer
Demo¶
Note
The first time you run any function/method or class, it will download Chromium to its home directory (for example, ~/.pyppeteer/
). It only happens once.
After, it will only open the chromium to render the contents of worldometers.
Simple API usage:
See all function in: worldometer.api
Get metrics using simplified functions:
>>> import worldometer
>>> worldometer.current_world_population()
{'current_world_population': 7845085923}
>>> worldometer.tweets_sent_today()
{'tweets_sent_today': 4539558}
Get metrics by passing the corresponding label:
>>> worldometer.get_metric_of(label='computers_produced_this_year')
{'computers_produced_this_year': 27760858}
Or complete use with Worldometer Class:
See all methods in: worldometer.core
>>> from worldometer import Worldometer
>>> w = Worldometer()
Get the number of categories, labels and metrics in w
object:
>>> w.what_is_here()
{'categories': 8, 'labels': 63, 'metrics': 63}
Get all categories used:
>>> w.categories()
[
'world_population',
'government_and_economics',
'society_and_media',
... # compressed
]
Get all labels used:
>>> w.metrics_labels()
[
'current_world_population',
'births_this_year',
'births_today',
'deaths_this_year',
'deaths_today',
'net_population_growth_this_year',
... # compressed
]
Get all metrics used:
>>> w.metrics()
[
7845087963,
15741371,
5676,
6608605,
2383,
9132766,
... # compressed
]
Get all metrics with labels in dict format:
>>> w.metrics_with_labels()
{
'abortions_this_year': 4785492,
'bicycles_produced_this_year': 17070566,
'births_this_year': 15741371,
'births_today': 5676,
'blog_posts_written_today': 110171,
'cars_produced_this_year': 8999185,
'cellular_phones_sold_today': 98846,
...: ... # compressed
}
Contributions¶
All contributions are welcome!
Found a problem, want to give a tip? open an issue
Do you have a solution to the problem? Send me a PR
Did you like this project? Click on the star ⭐
License¶
This project is using the MIT license, see in MIT LICENSE