Skip to content

Commit 7711077

Browse files
committed
Upgrade to python3
1 parent cc3f244 commit 7711077

6 files changed

Lines changed: 14 additions & 15 deletions

File tree

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,13 +232,13 @@ Lists available routes.
232232

233233
## Running the server
234234

235-
MTAPI is a Flask app designed to run under Python 2.7.
235+
MTAPI is a Flask app designed to run under Python 3.3+.
236236

237237
1. Create a `settings.cfg` file. A sample is provided as `settings.cfg.sample`.
238238
2. Set up your environment and install dependencies.
239-
`$ virtualenv .venv`
239+
`$ python3 -m venv .venv`
240240
`$ source .venv/bin/activate`
241-
`$ pip install -r requirements.txt`
241+
`$ python3 -m pip install -r requirements.txt`
242242
3. Run the server
243243
`$ python app.py`
244244

app.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
:license: BSD, see LICENSE for more details.
1010
"""
1111

12-
from mtapi import Mtapi
12+
from mtapi.mtapi import Mtapi
1313
from flask import Flask, request, jsonify, render_template, abort
1414
from flask.json import JSONEncoder
1515
from datetime import datetime
16-
from functools import wraps
16+
from functools import wraps, reduce
1717
import logging
1818
import os
1919

@@ -89,7 +89,7 @@ def by_location():
8989
try:
9090
location = (float(request.args['lat']), float(request.args['lon']))
9191
except KeyError as e:
92-
print e
92+
print(e)
9393
response = jsonify({
9494
'error': 'Missing lat/lon parameter'
9595
})

mtapi/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +0,0 @@
1-
from mtapi import Mtapi

mtapi/mtapi.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
import urllib2, contextlib, datetime, copy
1+
import urllib, contextlib, datetime, copy
22
from collections import defaultdict
33
from operator import itemgetter
44
import csv, math, json
55
import threading
66
import logging
77
import google.protobuf.message
88
from mtaproto.feedresponse import FeedResponse, Trip, TripStop, TZ
9-
from _mtapithreader import _MtapiThreader
9+
from mtapi._mtapithreader import _MtapiThreader
1010

1111
logger = logging.getLogger(__name__)
1212

@@ -86,7 +86,7 @@ def __init__(self, key, stations_file, expires_seconds=60, max_trains=10, max_mi
8686
self._stops_to_stations = self._build_stops_index(self._stations)
8787

8888
except IOError as e:
89-
print 'Couldn\'t load stations file '+stations_file
89+
print('Couldn\'t load stations file '+stations_file)
9090
exit()
9191

9292
self._update()
@@ -106,13 +106,13 @@ def _build_stops_index(stations):
106106

107107
def _load_mta_feed(self, feed_url):
108108
try:
109-
request = urllib2.Request(feed_url)
109+
request = urllib.request.Request(feed_url)
110110
request.add_header('x-api-key', self._KEY)
111-
with contextlib.closing(urllib2.urlopen(request)) as r:
111+
with contextlib.closing(urllib.request.urlopen(request)) as r:
112112
data = r.read()
113113
return FeedResponse(data)
114114

115-
except (urllib2.URLError, google.protobuf.message.DecodeError) as e:
115+
except (urllib.error.URLError, google.protobuf.message.DecodeError) as e:
116116
logger.error('Couldn\'t connect to MTA server: ' + str(e))
117117
return False
118118

mtaproto/nyct_subway_pb2.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pluggy==0.13.0
1616
protobuf==3.9.1
1717
py==1.8.0
1818
pyparsing==2.4.2
19-
pytest==4.6.5
19+
pytest==5.1.2
2020
pytz==2019.2
2121
scandir==1.10.0
2222
six==1.12.0

0 commit comments

Comments
 (0)