Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ganxeta system #643

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions pybikes/data/ganxeta.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"instances": [
{
"tag": "ganxeta-reus",
"meta": {
"city": "Reus",
"name": "Ganxeta",
"country": "ES",
"latitude": 41.1589,
"longitude": 1.10623,
"company": [
"Ajuntament de Reus"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Ajuntament de Reus"
"REUS MOBILITAT I SERVEIS, S.A. (RMS)"

]
}
}
],
"system": "ganxeta",
"class": "Ganxeta"
}
76 changes: 76 additions & 0 deletions pybikes/ganxeta.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
# Copyright (C) 2023, Martín González Gómez <m@martingonzalez.net>

import json

from pybikes import BikeShareSystem, BikeShareStation, PyBikesScraper

ENDPOINT = "https://bks-api.ganxeta.cat/rms-bike-sharing-real-time/graphql"


class Ganxeta(BikeShareSystem):
headers = {
"Content-Type": "application/json; charset=utf-8",
}

payload = {
"operationName": "StationsRealtime",
"query": """query StationsRealtime {
get_data_real_time {
station_id
station_state_id
station_name
station_address
latitude
longitude
bikes_total
bikes_available
bikes_reserved
bikes_maintenance
bikes_occupancy_status
bikes_occupancy_color
racks_total
racks_available
racks_broken
racks_occupancy_status
racks_occupancy_color
station_external_id
}
}""",
}

def __init__(self, tag, meta):
super(Ganxeta, self).__init__(tag, meta)

def update(self, scraper=None):
scraper = scraper or PyBikesScraper()
data = scraper.request(
ENDPOINT,
data=json.dumps(Ganxeta.payload),
headers=Ganxeta.headers,
method="POST",
)
data = json.loads(data)

stations = []

for station in data["data"]["get_data_real_time"]:
stations.append(GanxetaStation(station))

self.stations = stations


class GanxetaStation(BikeShareStation):
def __init__(self, data):
self.name = data["station_name"]
self.latitude = float(data["latitude"])
self.longitude = float(data["longitude"])

self.bikes = int(data["bikes_available"])
self.free = int(data["racks_available"])

self.extra = {
"uid": data["station_id"],
"address": data["station_address"],
"slots": int(data["racks_total"]),
}
Loading