Skip to content

Commit 7ed7490

Browse files
committed
adding documentation to functions and classes
1 parent 8375b0c commit 7ed7490

File tree

10 files changed

+65
-25
lines changed

10 files changed

+65
-25
lines changed

doc/source/classdoc/station.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,3 @@ Station
44
.. autoclass:: vbbpy.station.Station
55
:members:
66
:undoc-members:
7-

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
setup(
44
name='vbbpy',
55
version='1.1.5',
6+
python_requires='>3.6',
67
description='A python wrapper for the VBB REST-API by derhuerst',
78
url="https://github.com/Colum31/vbb-pythonWrapper",
89
author='colum31',

vbbpy/connections.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import requests
12
from vbbpy import line, modes, station, leg, vbbHelper, journey, location
23

34

@@ -54,15 +55,21 @@ def __str__(self):
5455

5556
return stationStr + allRoutesStr
5657

57-
def getConnections(self):
58-
response = self.makeJourneyRequest(modes.Modes.JOURNEY_BY_ID)
58+
def getConnections(self) -> None:
59+
"""
60+
Gets routes between origin and destination that are stored in calling object.
61+
62+
:return: None
63+
"""
64+
65+
response = self.makeJourneyRequest()
5966

6067
if response.status_code == 200:
6168
self.parseJourneyResponse(response.json(), modes.Modes.JOURNEY_BY_ID)
6269
else:
6370
print("Got invalid response\nstatus={}\n".format(response.status_code))
6471

65-
def makeJourneyRequest(self, mode):
72+
def makeJourneyRequest(self) -> requests.Response:
6673
"""
6774
Makes a request string and parameters in order to fetch information from journey API endpoint. Makes the
6875
request via fetchRequest().
@@ -90,7 +97,7 @@ def makeJourneyRequest(self, mode):
9097

9198
return vbbHelper.VbbHelper.fetchRequest(requestString, data)
9299

93-
def parseJourneyResponse(self, response, mode):
100+
def parseJourneyResponse(self, response: dict, mode: modes.Modes) -> None:
94101
# TODO: split this function into journey and leg class member functions
95102
"""
96103
Parses a journey request.

vbbpy/departure.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from vbbpy import vbbHelper
1+
from vbbpy import vbbHelper, line
22

33
class Departure:
44
"""
@@ -8,19 +8,19 @@ class Departure:
88
tripId = ""
99
plannedWhen = ""
1010
delay = 0
11-
line = None
11+
depLine = None
1212
direction = ""
1313
cancelled = False
1414

15-
def __init__(self, tripId, plannedWhen, delay, line, direction):
15+
def __init__(self, tripId: str, plannedWhen: str, delay: int, depLine: line.Line, direction: str):
1616
self.plannedWhen = plannedWhen
1717
self.tripId = tripId
1818
self.delay = delay
19-
self.line = line
19+
self.depLine = depLine
2020
self.direction = direction
2121

2222
def __str__(self):
23-
info = "{} {} {}".format(self.line.name, self.direction, vbbHelper.VbbHelper.getMinutesToDepartures(self.plannedWhen, self.delay))
23+
info = "{} {} {}".format(self.depLine.name, self.direction, vbbHelper.VbbHelper.getMinutesToDepartures(self.plannedWhen, self.delay))
2424

2525
if self.cancelled:
2626
info = info + " CANCELLED"

vbbpy/journey.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,21 @@ def __str__(self):
3838

3939
return stationStr + journeyString
4040

41-
def getTransfers(self):
41+
def getTransfers(self) -> None:
42+
"""
43+
Gets the amount of transfers and stores them in the calling object.
44+
45+
:return:
46+
"""
4247
self.numberTransfers = len(self.legs) - 1
4348

44-
def getTimeInfo(self):
49+
def getTimeInfo(self) -> None:
50+
"""
51+
Gets the length of the journey in minutes and stores it into calling object.
52+
53+
:return: None
54+
"""
55+
4556
firstLeg = self.legs[0]
4657
lastLeg = self.legs[-1]
4758

vbbpy/leg.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import datetime
22

3-
from vbbpy import vbbHelper
3+
from vbbpy import vbbHelper, line
44

55
class Leg:
66
"""
@@ -26,7 +26,7 @@ class Leg:
2626
walking = False
2727
walkingDistance = 0
2828

29-
def __init__(self, origin, destination, transportLine, plannedDeparture, plannedArrival, lineDirection, walking):
29+
def __init__(self, origin: str, destination: str, transportLine: line.Line, plannedDeparture, plannedArrival, lineDirection: str, walking: bool):
3030

3131
self.origin = origin
3232
self.destination = destination
@@ -52,7 +52,12 @@ def __str__(self):
5252
lineStr = "{} {}".format(self.transportLine.name, self.lineDirection)
5353
return depStr + lineStr + arrStr
5454

55-
def setTimeDuration(self):
55+
def setTimeDuration(self) -> None:
56+
"""
57+
Calculates and sets time required for the leg.
58+
59+
:return: None
60+
"""
5661

5762
diff = datetime.datetime.fromisoformat(self.plannedArrival) - datetime.datetime.fromisoformat(self.plannedDeparture)
5863
diff_seconds = diff.total_seconds()

vbbpy/line.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Line:
77
name = ""
88
product = ""
99

10-
def __init__(self, lineId, name, product):
10+
def __init__(self, lineId: str, name: str, product: str):
1111
self.lineId = lineId
1212
self.name = name
1313
self.product = product

vbbpy/location.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from geopy.geocoders import Nominatim
22

33
class Address:
4+
"""
5+
The Address class contains information about a physical address or place.
6+
"""
47

58
name = ""
69
streetName = ""
@@ -10,8 +13,16 @@ class Address:
1013

1114
cords = None
1215

13-
def getCords(self, inputStr):
14-
geolocator = Nominatim(user_agent="vbbpy: address lookup")
16+
def getCords(self, inputStr: str, userAgent: str) -> None:
17+
"""
18+
Gets the coordinates and address information for a address encoded in a string.
19+
20+
:param inputStr: a string containing the address or place
21+
:param userAgent: a user agent to use when requesting address information
22+
:return: None
23+
"""
24+
25+
geolocator = Nominatim(user_agent=userAgent)
1526
loc = geolocator.geocode(inputStr, addressdetails=True)
1627

1728
self.name = loc.address
@@ -24,14 +35,17 @@ def getCords(self, inputStr):
2435
self.postalCode = addressData.get("postcode", "")
2536
self.city = addressData.get("city", "")
2637

27-
def __init__(self, inputStr):
28-
self.getCords(inputStr)
38+
def __init__(self, inputStr: str, geopyUserAgent: str = "vbbpy: address lookup"):
39+
self.getCords(inputStr, geopyUserAgent)
2940

3041
def __str__(self):
3142
return self.streetName + " " + self.number + '\n' + self.postalCode + " " + self.city + '\n' + str(self.cords)
3243

3344

3445
class Coordinates:
46+
"""
47+
The Coordinates class contains floats encoding coordinates.
48+
"""
3549

3650
longitude = 0
3751
latitude = 0

vbbpy/station.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ def getDepartures(self, span=10) -> None:
111111
"""
112112
Requests the next departures from the station and stores them into calling object.
113113
114-
:param span Optional time limit for the departures to fetch.
114+
:param span: Optional time limit for the departures to fetch.
115115
:return: None
116116
"""
117117

@@ -275,7 +275,7 @@ def parseStopsResponse(self, response: dict, mode: modes.Modes, station) -> int:
275275

276276
for dep in response:
277277

278-
lineResponse = dep["line"]
278+
lineResponse = dep["depLine"]
279279
newLine = line.Line(lineResponse["id"], lineResponse["name"], lineResponse["product"])
280280

281281
newDeparture = departure.Departure(dep["tripId"], dep["plannedWhen"], dep["delay"], newLine,

vbbpy/vbbHelper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010

1111

1212
class VbbHelper:
13+
"""
14+
A helper class for the library.
15+
"""
1316

1417
@staticmethod
15-
def fetchRequest(requestString, queryParams):
18+
def fetchRequest(requestString: str, queryParams: dict) -> requests.Response:
1619
"""
1720
Sends the request.
1821
@@ -35,7 +38,7 @@ def fetchRequest(requestString, queryParams):
3538
return response
3639

3740
@staticmethod
38-
def getMinutesToDepartures(depTime, delay):
41+
def getMinutesToDepartures(depTime: str, delay: int) -> int:
3942
"""
4043
Calculates approximate minutes to a departure.
4144
:param depTime: ISO datetime string of the planned departure
@@ -54,7 +57,7 @@ def getMinutesToDepartures(depTime, delay):
5457
return int(diff_seconds / 60)
5558

5659
@staticmethod
57-
def getDateTimeHourMinuteString(dt, delay=0):
60+
def getDateTimeHourMinuteString(dt: str, delay: int = 0) -> str:
5861
"""
5962
Makes a string containing hour and minute of a given datetime.
6063
:param dt: datetime string to calculate string for

0 commit comments

Comments
 (0)