electricitymaps / bloom-contrib

Making carbon footprint data available to everyone.
https://www.bloomclimate.com
MIT License
436 stars 104 forks source link

🇩🇪 Deutsche Bahn #5

Closed ovbm closed 4 years ago

ovbm commented 6 years ago

DB provides start and endpoint of travel. We'd have to compute the duration or distance ourselves.

corradio commented 5 years ago

Do they have an API?

ovbm commented 5 years ago

They have API‘s for timetables and journeys, but with a free limit of 10 calls per minute. nothing for user accounts as far as i can tell: https://developer.deutschebahn.com/store/apis/list

jarek commented 5 years ago

I have a DB "Meine Bahn" account if you would like to try scraping it. The table with trip record looks like this, and data is available up to 14 months in the past.

<table class="form brsoverviewtable rowlines spanall">
  <!-- Kopfzeile mit entsprechender Hintergundfarbe -->
    <thead>
      <tr>
        <th class="localcol1">Auftrag</th>
        <th class="localcol2">Buchungsdatum</th>
        <th class="localcol3">Reisedatum</th>
        <th class="localcol4">Kurzbeschreibung</th>
        <th class="localcol5">Von - nach</th>
        <th class="localcol8">Bearbeiten</th>

    </tr>       
</thead>                
<!-- "Inhalt" mit entsprechender Hintergrundfarbe -->
<tbody>

<tr>
    <td>[redacted 6 character alphanumeric order code]</td>
    <td>16.09.2018 </td>

    <td>24.10.2018</td>

     <td>Bahnleistung

    </td>
    <td>
        Berlin Hbf - Frankfurt(Main)Hbf
    </td>           

    <td><a class="withicon editieren"
           title="Detailansicht zu diesem Auftrag" 
           href="https://fahrkarten.bahn.de/privatkunde/buchungsrueckschau/brs_auftrag_details.go?lang=de&country=DEU&auftragsnr=[redacted]"></a></td>

</tr>

<tr>
    <td>[redacted]</td>
    <td>15.09.2018 </td>

    <td>24.10.2018</td>

     <td>Bahnleistung

    </td>
    <td>
        Berlin Hbf - Frankfurt(Main)Hbf
    </td>           

    <td><a class="withicon editieren"
           title="Detailansicht zu diesem Auftrag" 
           href="https://fahrkarten.bahn.de/privatkunde/buchungsrueckschau/brs_auftrag_details.go?lang=de&country=DEU&auftragsnr=[redacted]"></a></td>

</tr>

<tr>
    <td>[redacted]</td>
    <td>30.12.2017 </td>

    <td>02.02.2018</td>

     <td>Bahnleistung

    </td>
    <td>
        F-Flughafen Fernbf. - Berlin Hbf
    </td>           

    <td><a class="withicon editieren"
           title="Detailansicht zu diesem Auftrag" 
           href="https://fahrkarten.bahn.de/privatkunde/buchungsrueckschau/brs_auftrag_details.go?lang=de&country=DEU&auftragsnr=[redacted]"></a></td>

</tr>

<tr>
    <td>[redacted]</td>
    <td>30.12.2017 </td>

    <td>13.01.2018</td>

     <td>Bahnleistung

    </td>
    <td>
        Berlin Ostbahnhof - Frankfurt(Main)Süd
    </td>           

    <td><a class="withicon editieren"
           title="Detailansicht zu diesem Auftrag" 
           href="https://fahrkarten.bahn.de/privatkunde/buchungsrueckschau/brs_auftrag_details.go?lang=de&country=DEU&auftragsnr=[redacted]"></a></td>

</tr>

</tbody>
</table>

Sometimes the more details pages ("Detailansicht zu diesem Auftrag") have slightly more information, like for instance "InterCityExpress 996, F-Flughafen Fernbf. (ab 10:09) - Berlin Hbf, 2. Kl., 2 Sitzplätze, Wagen 22, Plätze 41 43, Großraumwagen, Ruhebereich, Nichtraucher, 1 Fenster, 1 Gang, Res.Nr. [redacted]" - where ICE 996 is a specific train with a defined route and stopping points. However this is only for tickets bound to a specific train or with seat reservation.

corradio commented 5 years ago

That's really awesome! I think first we need to build a small playground so people can easily code the integrations themselves (see #14).

ovbm commented 5 years ago

I already started an integration that is not quite working yet. Will make a PR with what I have so far.

monsieurhannes commented 4 years ago

Any news on that? I figured that Deutsche Bahn could be used for/instead of quite a lot of train providers, as they support a lot of european connections.

Is there a possibility to link ones Tomorrow account directly to the Meine Bahn so that it fetches the booked trains directly?

Wishlist [ ] compare with some train db on the web if the train numer is an electric or diesel train and apply the different CO2-equivalents/km. This might be useful: http://www.grahnert.de/fernbahn/datenbank/

ovbm commented 4 years ago

Haven't had time to work on it unfortunately. I did so a year ago but there were some tokens that I couldn't figure out how to get around. If anyone has time to do it, would be great. I use DB all the time.

martincollignon commented 4 years ago

closing due to inactivity. Let's reopen if someone finds an API to fetch trips.