├── .gitignore ├── requirements.txt ├── crontab.txt ├── sql └── schema.sql ├── Makefile ├── README.md ├── src └── scrape.py └── LICENSE /.gitignore: -------------------------------------------------------------------------------- 1 | gtfs 2 | *.json 3 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | psycopg2 >=2.7.4, <2.8 2 | requests>=2.20.0 3 | -------------------------------------------------------------------------------- /crontab.txt: -------------------------------------------------------------------------------- 1 | PATH=/bin:/usr/bin:/usr/local/bin 2 | SHELL=/bin/bash 3 | CTA_API_KEY="" 4 | PGDATABASE="" 5 | 6 | */3 4-22 * * * make -e -C $HOME/cta-bus-archive scrape 2>/dev/null > /dev/null 7 | */5 23,0-3 * * * make -e -C $HOME/cta-bus-archive scrape 2>/dev/null > /dev/null 8 | -------------------------------------------------------------------------------- /sql/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE SCHEMA IF NOT EXISTS cta; 2 | 3 | CREATE TABLE IF NOT EXISTS cta.positions ( 4 | "timestamp" timestamp with time zone NOT NULL, 5 | "vehicle_id" text NOT NULL, 6 | "latitude" numeric(9,6), 7 | "longitude" numeric(9,6), 8 | "bearing" numeric(5,2), 9 | "pattern_id" int, 10 | "route_id" text, 11 | "destination" text, 12 | "dist_along_route" numeric, 13 | "delayed" boolean, 14 | "trip_id" text, 15 | "tablockid" text, 16 | "zone" text, 17 | CONSTRAINT cta_position_pk PRIMARY KEY ("timestamp", "vehicle_id") 18 | ); 19 | 20 | CREATE TABLE IF NOT EXISTS cta.pattern_stops ( 21 | "pid" int, 22 | "stop_sequence" int, 23 | "stop_id" int default 0, 24 | "stop_name" text, 25 | "pdist" numeric, 26 | "latitude" numeric(9,6), 27 | "longitude" numeric(9,6), 28 | "type" text, 29 | CONSTRAINT cta_pattern_stops_pk PRIMARY KEY ("pid", "stop_sequence") 30 | ); 31 | 32 | CREATE TABLE IF NOT EXISTS cta.patterns ( 33 | "pid" int PRIMARY KEY, 34 | "length" numeric, 35 | "route_direction" text, 36 | "timestamp" timestamp default current_timestamp 37 | ); 38 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2018 Active Transportation Alliance 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | shell = bash 16 | 17 | PYTHON = python 18 | 19 | PGUSER ?= $(USER) 20 | PGDATABASE ?= $(PGUSER) 21 | PSQLFLAGS = $(PGDATABASE) 22 | PSQL = psql $(PSQLFLAGS) 23 | 24 | export PGDATABASE PGUSER 25 | 26 | BUCKET = chibus 27 | DATE = 2018-01-01 28 | YEAR = $(shell echo $(DATE) | sed 's/\(.\{4\}\)-.*/\1/') 29 | MONTH = $(shell echo $(DATE) | sed 's/.\{4\}-\(.\{2\}\)-.*/\1/') 30 | 31 | .PHONY: gcloud s3 s3-positions s3-patterns s3-pattern_stops 32 | 33 | # Relies on environment variables being set 34 | scrape: ; $(PYTHON) src/scrape.py --patterns --positions 35 | 36 | s3: s3-positions s3-patterns s3-pattern_stops 37 | 38 | s3-positions s3-patterns s3-pattern_stops: s3-%: $(YEAR)/$(MONTH)/$(DATE)-%.csv.xz 39 | aws s3 cp --quiet --acl public-read $< s3://$(BUCKET)/$< 40 | 41 | gcloud: $(YEAR)/$(MONTH)/$(DATE)-positions.csv.xz 42 | gsutil cp -rna public-read $< gs://$(BUCKET)/$< 43 | 44 | $(YEAR)/$(MONTH)/$(DATE)-patterns.csv.xz $(YEAR)/$(MONTH)/$(DATE)-positions.csv.xz: $(YEAR)/$(MONTH)/$(DATE)-%.csv.xz: | $(YEAR)/$(MONTH) 45 | $(PSQL) -c "COPY (\ 46 | SELECT * FROM cta.$* WHERE timestamp::date = '$(DATE)'::date \ 47 | ) TO STDOUT WITH (FORMAT CSV, HEADER true)" | \ 48 | xz -z - > $@ 49 | 50 | $(YEAR)/$(MONTH)/$(DATE)-pattern_stops.csv.xz: | $(YEAR)/$(MONTH) 51 | $(PSQL) -c "COPY (\ 52 | SELECT a.* FROM cta.pattern_stops a INNER JOIN cta.patterns USING (pid) \ 53 | WHERE timestamp::date = '$(DATE)'::date \ 54 | ) TO STDOUT WITH (FORMAT CSV, HEADER true)" | \ 55 | xz -z - > $@ 56 | 57 | $(YEAR)/$(MONTH): 58 | mkdir -p $@ 59 | 60 | clean-date: 61 | $(PSQL) -c "DELETE FROM cta.positions where timestamp::date = '$(DATE)'::date" 62 | $(PSQL) -c "DELETE FROM cta.pattern_stops using cta.patterns p \ 63 | where pattern_stops.pid = p.pid and timestamp::date = '$(DATE)'::date" 64 | $(PSQL) -c "DELETE FROM cta.patterns where timestamp::date = '$(DATE)'::date" 65 | rm -f $(YEAR)/$(MONTH)/$(DATE)-bus-positions.csv{.xz,} 66 | 67 | init: sql/schema.sql requirements.txt 68 | $(PYTHON) -m pip install -r $(filter %.txt,$^) 69 | $(PSQL) -f $< 70 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # cta bus archiver 2 | 3 | Archives bus positions served by the [CTA Bus Tracker](https://www.transitchicago.com/developers/bustracker/) API. 4 | 5 | ## Active Transportation Alliance archive 6 | 7 | The Active Transportation Alliance maintains a daily archive of Bus Tracker data. The data is in `.xz` compressed CSV format. There are three files for each day, following this pattern: 8 | ``` 9 | https://s3.us-east-2.amazonaws.com/chibus/yyyy/mm/yyyy-mm-dd-pattern_stops.csv.xz 10 | https://s3.us-east-2.amazonaws.com/chibus/yyyy/mm/yyyy-mm-dd-patterns.csv.xz 11 | https://s3.us-east-2.amazonaws.com/chibus/yyyy/mm/yyyy-mm-dd-positions.csv.xz 12 | ``` 13 | 14 | For example: `https://s3.us-east-2.amazonaws.com/chibus/2018/03/2018-03-22-pattern_stops.csv.xz`. 15 | 16 | The archive begins in October, 2018. Some data is also available for selected days starting in March, 2018. 17 | 18 | ## Requirements 19 | 20 | * Make in a bash environment 21 | * Python (2.7+ or 3.5+) 22 | * PostGreSQL (9.5+) 23 | 24 | ## Install 25 | 26 | Get a CTA [Bus Tracker](https://www.transitchicago.com/developers/bustracker/) API key. 27 | 28 | Install PostgreSQL on your system and create a database. 29 | 30 | Create environment variables to track how you log into the db (which could be remote). 31 | 32 | ````bash 33 | export CTA_API_KEY= 34 | ```` 35 | Optionally, add these variables for connection to a Postgres database. This isn't necessary if you're using an eponymous postgres user to connect to an eponymous database over the socket. 36 | ````bash 37 | export PGUSER= 38 | export PGDATABASE= 39 | export PGHOST= 40 | export PGPORT= 41 | ```` 42 | 43 | Use a [`.pgpass`](https://www.postgresql.org/docs/current/static/libpq-pgpass.html) file to save a password, if one is needed. 44 | 45 | Run the following will set up the database and install Python dependencies 46 | ``` 47 | make init 48 | ``` 49 | 50 | ## Scrape 51 | 52 | To save the current snapshot of bus positions: 53 | ``` 54 | python src/scrape.py --positions 55 | ``` 56 | 57 | or, for short: 58 | ``` 59 | make scrape 60 | ``` 61 | 62 | This will update the Postgres database with current positions as well as new bus patterns. 63 | 64 | ## Scheduling 65 | 66 | See `crontab.txt` for a sample cron job that schedules regular fetches from the API. 67 | 68 | ### Details about CTA standards 69 | 70 | * CTA service standards define AM peak as 6-9 am and PM peak as 3-7 pm. 71 | 72 | * CTA defines on-time performance as trips leaving the terminal no more than 1 minute ahead of schedule and no more than 5 minutes later than schedule. 73 | 74 | * Bus bunching is defined as buses that depart the same timepoint within 60 seconds of each other. This is calculated as percentage of all buses that passed through the timepoint. 75 | 76 | 77 | ## License 78 | 79 | Copyright 2018 Active Transportation Alliance. Licensed under the Apache License, Version 2.0. -------------------------------------------------------------------------------- /src/scrape.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | """ 4 | Scraping utility for the CTA Bus Tracker API. 5 | For usage information, run "python scrape.py" on your command line. 6 | 7 | Copyright 2018 Active Transportation Alliance 8 | 9 | Licensed under the Apache License, Version 2.0 (the "License"); 10 | you may not use this file except in compliance with the License. 11 | You may obtain a copy of the License at 12 | 13 | http://www.apache.org/licenses/LICENSE-2.0 14 | 15 | Unless required by applicable law or agreed to in writing, software 16 | distributed under the License is distributed on an "AS IS" BASIS, 17 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 | See the License for the specific language governing permissions and 19 | limitations under the License. 20 | """ 21 | from __future__ import print_function 22 | import os 23 | import sys 24 | import getpass 25 | try: 26 | from itertools import zip_longest 27 | except ImportError: 28 | from itertools import izip_longest as zip_longest 29 | import argparse 30 | import requests 31 | import psycopg2 32 | from psycopg2.extras import execute_batch 33 | 34 | """ 35 | Scrape current vehicle positions and patterns from 36 | the CTA Bus Tracker API and load into a postgres database. 37 | """ 38 | 39 | API = 'http://www.ctabustracker.com/bustime/api/v2/{}' 40 | 41 | """ 42 | "vid": "7934", vehicle_id 43 | "tmstmp": "20180321 17:27", timestamp with time zone 44 | "lat": "41.878145", latitude 45 | "lon": "-87.63962666666667", longitude 46 | "hdg": "88", bearing 47 | "pid": 6351, pattern_id 48 | "rt": "1", route_id 49 | "des": "35th/Michigan", destination text 50 | "pdist": 103, pattern_dist 51 | "dly": false, delayed boolean 52 | "tatripid": "66", trip_id 53 | "tablockid": "1 -751", tablockid text 54 | "zone": "" zone text 55 | """ 56 | 57 | INSERT_POSITIONS = """ 58 | INSERT INTO cta.positions ( 59 | timestamp, vehicle_id, latitude, longitude, bearing, pattern_id, route_id, 60 | destination, dist_along_route, delayed, trip_id, tablockid, zone 61 | ) VALUES ( 62 | %(tmstmp)s::timestamp without time zone at time zone 'US/Central', 63 | %(vid)s, %(lat)s::numeric, %(lon)s::numeric, %(hdg)s::integer, %(pid)s, %(rt)s, 64 | %(des)s, %(pdist)s, %(dly)s::boolean, %(tatripid)s, %(tablockid)s, %(zone)s 65 | ) ON CONFLICT DO NOTHING 66 | """ 67 | 68 | INSERT_PATTERNS = """ 69 | INSERT INTO cta.patterns ("pid", "length", "route_id", "route_direction") 70 | VALUES (%(pid)s::integer, %(ln)s, %(rt)s, %(rtdir)s) 71 | ON CONFLICT DO NOTHING 72 | """ 73 | 74 | INSERT_PATTERN_STOPS = """ 75 | INSERT INTO cta.pattern_stops ( 76 | pid, stop_id, stop_name, stop_sequence, pdist, latitude, longitude, type 77 | ) VALUES ( 78 | %(pid)s::int, %(stpid)s, %(stpnm)s, %(seq)s, %(pdist)s, 79 | %(lat)s::numeric, %(lon)s::numeric, %(typ)s 80 | ) ON CONFLICT DO NOTHING 81 | """ 82 | 83 | 84 | def grouper(n, iterable, fillvalue=None): 85 | """grouper(3, 'ABCDEFG', 'x') --> ABC DEF Gxx""" 86 | args = [iter(iterable)] * n 87 | return zip_longest(fillvalue=fillvalue, *args) 88 | 89 | 90 | def fetch_routeids(session): 91 | """Request current route IDs from the API.""" 92 | r = session.get(API.format('getroutes')) 93 | routes = r.json().get('bustime-response').get('routes') 94 | return [r['rt'] for r in routes] 95 | 96 | 97 | def fetch_positions(api_key): 98 | """Request positions from the API.""" 99 | positions = [] 100 | with requests.Session() as session: 101 | session.params = {'key': api_key, 'format': 'json'} 102 | 103 | # get routes 104 | routeids = fetch_routeids(session) 105 | 106 | # Loop through routes getting vehicles 10 at a time 107 | for grp in grouper(10, routeids, ','): 108 | params = { 109 | 'rt': ','.join(grp).strip(',') 110 | } 111 | raw = session.get(API.format('getvehicles'), params=params) 112 | vehicles = raw.json().get('bustime-response').get('vehicle') 113 | try: 114 | positions.extend(vehicles) 115 | except TypeError: 116 | pass 117 | 118 | return positions 119 | 120 | 121 | def fetch_patterns(api_key, pids): 122 | """Request patterns from the API.""" 123 | patterns = [] 124 | with requests.Session() as session: 125 | session.params = {'key': api_key, 'format': 'json'} 126 | 127 | # Loop through routes getting vehicles 10 at a time 128 | for grp in grouper(10, (str(p) for p in pids), ','): 129 | params = { 130 | 'pid': ','.join(grp).strip(',') 131 | } 132 | raw = session.get(API.format('getpatterns'), params=params) 133 | pattern = raw.json().get('bustime-response').get('ptr') 134 | try: 135 | patterns.extend(pattern) 136 | except TypeError: 137 | pass 138 | 139 | return patterns 140 | 141 | 142 | def get_current_pids(cursor): 143 | """ 144 | Get extant pattern IDs from the the DB, 145 | to be compared against new ones in the feed. 146 | """ 147 | cursor.execute('select pid from cta.patterns') 148 | return set(row[0] for row in cursor.fetchall()) 149 | 150 | 151 | def connection_params(): 152 | pg = { 153 | 'PGUSER': 'user', 154 | 'PGHOST': 'host', 155 | 'PGPORT': 'port', 156 | 'PGPASSWORD': 'password', 157 | 'PGPASSFILE': 'passfile', 158 | } 159 | params = {'dbname': os.environ.get('PGDATABASE', getpass.getuser())} 160 | params.update({v: os.environ[k] for k, v in pg.items() if k in os.environ}) 161 | return params 162 | 163 | 164 | def main(): 165 | """Scrape positions.""" 166 | desc = """ 167 | Scrape CTA bus positions into a PostgreSQL database. 168 | By default, a local connection to your user's database will be created. 169 | To specify other connection parameters, use the standard PG* environment variables. 170 | """ 171 | parser = argparse.ArgumentParser(description=desc) 172 | parser.add_argument('--key', default=os.environ.get('CTA_API_KEY')) 173 | parser.add_argument('--positions', action='store_true', help='fetch positions') 174 | parser.add_argument('--patterns', action='store_true', help='fetch patterns') 175 | args = parser.parse_args() 176 | 177 | with psycopg2.connect(**connection_params()) as conn: 178 | cursor = conn.cursor() 179 | 180 | if args.positions: 181 | positions = fetch_positions(args.key) 182 | execute_batch(cursor, INSERT_POSITIONS, positions) 183 | print('inserted', len(positions), 'positions', file=sys.stderr) 184 | conn.commit() 185 | 186 | if args.positions and args.patterns: 187 | current_pids = get_current_pids(cursor) 188 | pids = set(x['pid'] for x in positions).difference(current_pids) 189 | 190 | if not pids: 191 | print('No new patterns', file=sys.stderr) 192 | 193 | else: 194 | patterns = fetch_patterns(args.key, pids) 195 | execute_batch(cursor, INSERT_PATTERNS, patterns) 196 | print('inserted', len(patterns), 'patterns', file=sys.stderr) 197 | conn.commit() 198 | 199 | patternstops = [ 200 | dict(pid=x['pid'], **stop) 201 | for x in patterns 202 | for stop in x['pt'] 203 | ] 204 | for patternstop in patternstops: 205 | patternstop.setdefault('stpid') 206 | patternstop.setdefault('stpnm') 207 | 208 | execute_batch(cursor, INSERT_PATTERN_STOPS, patternstops) 209 | print('inserted', len(patternstops), 'patternstops', file=sys.stderr) 210 | conn.commit() 211 | 212 | 213 | if __name__ == '__main__': 214 | main() 215 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 10 | 11 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 12 | 13 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 14 | 15 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 16 | 17 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 18 | 19 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 20 | 21 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 22 | 23 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 24 | 25 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 26 | 27 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 28 | 29 | 2. Grant of Copyright License. 30 | 31 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 32 | 33 | 3. Grant of Patent License. 34 | 35 | Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 36 | 37 | 4. Redistribution. 38 | 39 | You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 40 | 41 | You must give any other recipients of the Work or Derivative Works a copy of this License; and 42 | You must cause any modified files to carry prominent notices stating that You changed the files; and 43 | You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 44 | If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 45 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 46 | 47 | 5. Submission of Contributions. 48 | 49 | Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 50 | 51 | 6. Trademarks. 52 | 53 | This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 54 | 55 | 7. Disclaimer of Warranty. 56 | 57 | Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 58 | 59 | 8. Limitation of Liability. 60 | 61 | In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 62 | 63 | 9. Accepting Warranty or Additional Liability. 64 | 65 | While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 66 | 67 | END OF TERMS AND CONDITIONS 68 | 69 | APPENDIX: How to apply the Apache License to your work 70 | 71 | --------------------------------------------------------------------------------