emirthab / weatherAPI

An API that returns weather data in json format based on the geolocation information entered

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Weather API

Weather API

Introduction:

🔵 An API that returns weather data in json format based on the geolocation information entered.

Important Note:

❗️In this application, it is not possible to sell, rent or use the data commercially. This application was made for testing purposes. Since it works as a bot, it works slower than apis that sell data. You can use the api in your projects from the following link (see usage section):

"https://weatherapi.emirthab.repl.co/"

example: "https://weatherapi.emirthab.repl.co/current?lat=40&lon=35&lang=en"

Usage :

  • Install requirements:

python -m pip install -r requirements.txt
  • Run Application:

python listener.py
  • Example Request:

127.0.0.1:8080/current?lat=40.12345&lon=35.12345&lang=en

lat = latitude
lon = longitude
lang = language

How It Works:

🔵 First, geolocation information is sent to the API via https://bigdatacloud.net, then the location data corresponding to this information is returned in json format.

On listener.py/line 11:

def getLocationFromGeo(latitude,longitude,lang):
    urlGeoApi = "https://api.bigdatacloud.net/data/reverse-geocode-client?latitude="+latitude+"&longitude="+longitude+"&localityLanguage="+lang
    r = requests.get(urlGeoApi)

Example Json Data:

Json Example

🔵 The full address name is created in the following data. For example:

city: "Mountain View"
locality: "Googleplex"
countryName: "USA"

for this data: 'Mountain View Googleplex USA'

the full address name is obtained.

🔵 Then the word "weather" is added to the end of this address and only "weather widget" is displayed in the Google search engine.

Example Google Search:

Google Search Example

🔵 As seen in the image above, a special search was made on Google to show only the weather widget. After this search is done, all the data obtained by taking the html data according to "xpath" is returned in a json format.

NOTE: The extraction of html data with Xpath took place between lines 55 and 62.

🔵 The resulting json data will look like this:

Result Json Data

About

An API that returns weather data in json format based on the geolocation information entered

License:GNU General Public License v3.0


Languages

Language:Python 100.0%