This repository has been archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
135 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ | |
cache = Cache(app, config={'CACHE_TYPE': 'simple'}) | ||
|
||
# create a Flask-RESTPlus API | ||
api = Api(app, version='0.0.5', catch_all_404s=True, prefix='/api', | ||
api = Api(app, version='0.0.6', catch_all_404s=True, prefix='/api', validate=True, | ||
title='Deutsche Bahn Reiseplan', description=u'API for the itineraries of the Deutsche Bahn', | ||
terms_url='https://www.bahn.de/p/view/home/agb/nutzungsbedingungen.shtml', | ||
contact='Niels Lohmann', contact_email='[email protected]', | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
# coding=utf-8 | ||
|
||
import requests | ||
from bs4 import BeautifulSoup | ||
import datetime | ||
|
||
|
||
class Buchungseintrag(object): | ||
def __init__(self): | ||
self.type = None | ||
self.travel_date = None | ||
self.description = None | ||
self.voucher_number = None | ||
self.price = None | ||
|
||
|
||
class Buchung(object): | ||
def __init__(self, auftragsnummer, nachname): | ||
self.auftragsnummer = auftragsnummer | ||
self.nachname = nachname | ||
|
||
self.reference_number = None | ||
self.booking_date = None | ||
self.booker = None | ||
self.traveler = None | ||
self.state = None | ||
self.entries = [] | ||
|
||
self.__download() | ||
|
||
@property | ||
def valid(self): | ||
return self.reference_number is not None | ||
|
||
def __download(self): | ||
url = 'https://fahrkarten.bahn.de/privatkunde/start/start.post' | ||
params = { | ||
'dbkanal_007': 'L01_S01_D001_KIN0014_qf-buchungenauftrag_LZ08' | ||
} | ||
payload = { | ||
'scope': 'bahnatsuche', | ||
'search': 1, | ||
'country': 'DEU', | ||
'lang': 'de', | ||
'auftragsnr': self.auftragsnummer, | ||
'reisenderNachname': self.nachname | ||
} | ||
|
||
page = requests.post(url, params=params, data=payload) | ||
soup = BeautifulSoup(page.content, 'html.parser') | ||
|
||
headers = soup.find_all('table', {'class': 'form brsDetailsTable brsDetailsKopfzeileTable bottommargin-big spanall'}) | ||
try: | ||
header_entries = headers[0].find_all('td') | ||
except IndexError: | ||
return | ||
|
||
self.reference_number = header_entries[0].text.strip() | ||
self.booking_date = datetime.datetime.strptime(header_entries[1].text.strip(), '%d.%m.%Y').date() | ||
self.booker = header_entries[2].text.strip() | ||
self.traveler = header_entries[3].text.strip() | ||
self.state = header_entries[5].text.strip() | ||
|
||
details = soup.find_all('table', {'class': 'form brsDetailsTable spanall'}) | ||
for tr in details[0].find_all('tr'): | ||
try: | ||
detail_entries = tr.find_all('td') | ||
entry = Buchungseintrag() | ||
entry.type = detail_entries[0].text.strip() | ||
entry.travel_date = datetime.datetime.strptime(detail_entries[1].text.strip(), '%d.%m.%Y').date() | ||
entry.description = detail_entries[2].text.strip() | ||
entry.voucher_number = int(detail_entries[3].text.strip()) | ||
entry.price = float(detail_entries[5].text.strip().replace(' EUR', '').replace(',', '.')) | ||
self.entries.append(entry) | ||
except IndexError: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters