Skip to content

Commit

Permalink
Minor edits to make Pylint happy
Browse files Browse the repository at this point in the history
  • Loading branch information
zzkW35 committed Feb 17, 2023
1 parent ec0b571 commit e85f8c9
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
geopy==2.2.0
requests~=2.25.1
Unidecode~=1.2.0
5 changes: 3 additions & 2 deletions src/bikemi_unofficial_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
"""Bikemi Unofficial API."""
import sys

if sys.version_info[:2] >= (3, 8):
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.8`
# TODO: Import directly (no need for conditional) when `python_requires = >= 3.8` # pylint: disable=fixme
from importlib.metadata import PackageNotFoundError, version # pragma: no cover
else:
from importlib_metadata import PackageNotFoundError, version # pragma: no cover

try:
# Change here if project is renamed and does not equal the package name
dist_name = "BikeMi-unofficial-API"
dist_name = "BikeMi-unofficial-API" # pylint: disable=invalid-name
__version__ = version(dist_name)
except PackageNotFoundError: # pragma: no cover
__version__ = "unknown"
Expand Down
10 changes: 7 additions & 3 deletions src/bikemi_unofficial_api/bikemi.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
"""Main API file."""
from operator import itemgetter

import json
import re
import requests
import unidecode

from geopy import distance
from operator import itemgetter


class BikeMiApi:
"""Scrape and parse the BikeMi website."""

def json_decoder(self, info_url):
"""Generate a list of stations, stored as dictionaries, by using the
json files provided by BikeMi at https://bikemi.com/dati-aperti/"""
resp = requests.get(info_url)
resp = requests.get(info_url, timeout=10)
raw = resp.json()
# Pick the "stations" values inside the "data" key of the "raw" dict
stations = raw["data"]["stations"]
Expand All @@ -22,7 +26,7 @@ def json_decoder(self, info_url):

def get_station_extra_info_json(self):
"""Get further info (bike availability) by scraping the bikemi.com source"""
raw = requests.get("https://bikemi.com/stazioni").text
raw = requests.get("https://bikemi.com/stazioni", timeout=10).text
placeholder = '"stationMapPage","slug":null},'
start = raw.find(placeholder) + len(placeholder)
end = raw.find('},"baseUrl":"https://bikemi.com"')
Expand Down

0 comments on commit e85f8c9

Please sign in to comment.