kopia lustrzana https://github.com/glidernet/ogn-python
Reduce flake8 errors
rodzic
fc608cd6c8
commit
1b22897da8
|
@ -9,8 +9,10 @@ from app.flask_celery import make_celery
|
|||
|
||||
bootstrap = Bootstrap()
|
||||
db = SQLAlchemy()
|
||||
migrate = Migrate()
|
||||
cache = Cache()
|
||||
|
||||
|
||||
def create_app(config_name='development'):
|
||||
# Initialize Flask
|
||||
app = Flask(__name__)
|
||||
|
@ -25,14 +27,12 @@ def create_app(config_name='development'):
|
|||
# Initialize other things
|
||||
bootstrap.init_app(app)
|
||||
db.init_app(app)
|
||||
migrate.init_app(app, db)
|
||||
cache.init_app(app)
|
||||
|
||||
#migrate = Migrate(app, db)
|
||||
# celery = make_celery(app)
|
||||
|
||||
from app.main import bp as bp_main
|
||||
app.register_blueprint(bp_main)
|
||||
|
||||
#from app import commands
|
||||
|
||||
return app
|
||||
|
|
|
@ -1,9 +1,7 @@
|
|||
from datetime import datetime, timedelta, timezone, date
|
||||
|
||||
from app.model import AircraftBeacon, Device, Receiver
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from app.model import AircraftBeacon, ReceiverBeacon
|
||||
from app import db
|
||||
from app.model import ReceiverBeacon
|
||||
|
||||
|
||||
def utc_to_local(utc_dt):
|
||||
|
@ -28,7 +26,7 @@ def rec(min_timestamp, min_online_timestamp):
|
|||
lines.append("<markers>")
|
||||
lines.append('<m e="0"/>')
|
||||
for receiver_beacon in last_seen_query:
|
||||
if receiver_beacon.location == None or receiver_beacon.name.startswith("FNB"):
|
||||
if receiver_beacon.location is None or receiver_beacon.name.startswith("FNB"):
|
||||
continue
|
||||
lines.append(
|
||||
'<m a="{0}" b="{1:.7f}" c="{2:.7f}" d="{3:1d}"/>'.format(
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
from sqlalchemy import distinct
|
||||
from sqlalchemy.sql import null, and_, func, not_, case
|
||||
from sqlalchemy.dialects import postgresql
|
||||
from sqlalchemy.sql import null, and_, func, case
|
||||
from sqlalchemy.dialects.postgresql import insert
|
||||
from flask import current_app
|
||||
|
||||
from app.model import Country, DeviceInfo, DeviceInfoOrigin, AircraftBeacon, ReceiverBeacon, Device, Receiver
|
||||
from app.model import Country, DeviceInfo, DeviceInfoOrigin, Receiver
|
||||
from app.utils import get_ddb, get_flarmnet
|
||||
|
||||
|
||||
|
|
|
@ -171,7 +171,7 @@ def update_max_altitudes(session, date, logger=None):
|
|||
logger.info("Update logbook max altitude.")
|
||||
|
||||
if session is None:
|
||||
session = app.session
|
||||
session = current_app.session
|
||||
|
||||
(start, end) = date_to_timestamps(date)
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ from .gateway import user_cli as gateway_cli
|
|||
from .logbook import user_cli as logbook_cli
|
||||
from .stats import user_cli as stats_cli
|
||||
|
||||
|
||||
def register(app):
|
||||
app.cli.add_command(database_cli)
|
||||
app.cli.add_command(export_cli)
|
||||
|
|
|
@ -2,11 +2,11 @@ from flask import current_app
|
|||
from flask.cli import AppGroup
|
||||
import click
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import datetime
|
||||
from sqlalchemy.sql import func
|
||||
|
||||
from app.collect.database import update_device_infos, update_country_code
|
||||
from app.model import *
|
||||
from app.model import AircraftBeacon, DeviceInfoOrigin
|
||||
from app.utils import get_airports, get_days
|
||||
|
||||
from app import db
|
||||
|
|
|
@ -6,7 +6,7 @@ import re
|
|||
import csv
|
||||
|
||||
from aerofiles.igc import Writer
|
||||
from app.model import *
|
||||
from app.model import AircraftBeacon, Device
|
||||
from app import db
|
||||
|
||||
user_cli = AppGroup("export")
|
||||
|
@ -64,7 +64,7 @@ def igc(address, date):
|
|||
print("Address {} not valid.".format(address))
|
||||
return
|
||||
|
||||
if not re.match("\d{4}-\d{2}-\d{2}", date):
|
||||
if not re.match(r"\d{4}-\d{2}-\d{2}", date):
|
||||
print("Date {} not valid.".format(date))
|
||||
return
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
from flask import current_app
|
||||
from flask.cli import AppGroup
|
||||
import click
|
||||
|
||||
from ogn.client import AprsClient
|
||||
from app.gateway.bulkimport import ContinuousDbFeeder
|
||||
|
|
|
@ -18,6 +18,7 @@ from app.collect.stats import (
|
|||
)
|
||||
|
||||
from app.collect.ognrange import update_entries as update_receiver_coverages
|
||||
from app.model import Device
|
||||
|
||||
from app import db
|
||||
|
||||
|
@ -58,9 +59,6 @@ def create_country(start, end):
|
|||
result = create_country_stats(session=db.session, date=single_date)
|
||||
|
||||
|
||||
from app.model import *
|
||||
|
||||
|
||||
@user_cli.command("update_devices_name")
|
||||
def update_devices_name():
|
||||
"""Update Devices name."""
|
||||
|
|
|
@ -11,7 +11,7 @@ from ogn.parser import parse, ParseError
|
|||
|
||||
from app.model import AircraftBeacon, ReceiverBeacon, Location
|
||||
from app.utils import open_file
|
||||
from app.gateway.process_tools import *
|
||||
from app.gateway.process_tools import create_indices, add_missing_devices, add_missing_receivers, update_aircraft_beacons, update_receiver_beacons, update_receiver_location, transfer_aircraft_beacons, transfer_receiver_beacons, delete_aircraft_beacons, delete_receiver_beacons, update_aircraft_beacons_bigdata, update_receiver_beacons_bigdata, create_tables
|
||||
|
||||
from app import db
|
||||
|
||||
|
@ -264,7 +264,7 @@ def get_aircraft_beacons_postfixes():
|
|||
"""Get the postfixes from imported aircraft_beacons logs."""
|
||||
|
||||
postfixes = db.session.execute(
|
||||
"""
|
||||
r"""
|
||||
SELECT DISTINCT(RIGHT(tablename, 8))
|
||||
FROM pg_catalog.pg_tables
|
||||
WHERE schemaname = 'public' AND tablename LIKE 'aircraft\_beacons\_20______'
|
||||
|
@ -276,14 +276,16 @@ def get_aircraft_beacons_postfixes():
|
|||
|
||||
|
||||
def export_to_path(postfix):
|
||||
import os, gzip
|
||||
import os
|
||||
import gzip
|
||||
|
||||
aircraft_beacons_file = os.path.join(path, "aircraft_beacons_{0}.csv.gz".format(postfix))
|
||||
with gzip.open(aircraft_beacons_file, "wt", encoding="utf-8") as gzip_file:
|
||||
self.cur.copy_expert("COPY ({}) TO STDOUT WITH (DELIMITER ',', FORMAT CSV, HEADER, ENCODING 'UTF-8');".format(self.get_merged_aircraft_beacons_subquery()), gzip_file)
|
||||
receiver_beacons_file = os.path.join(path, "receiver_beacons_{0}.csv.gz".format(postfix))
|
||||
with gzip.open(receiver_beacons_file, "wt") as gzip_file:
|
||||
self.cur.copy_expert("COPY ({}) TO STDOUT WITH (DELIMITER ',', FORMAT CSV, HEADER, ENCODING 'UTF-8');".format(self.get_merged_receiver_beacons_subquery()), gzip_file)
|
||||
pass # wtf is this?
|
||||
# aircraft_beacons_file = os.path.join(path, "aircraft_beacons_{0}.csv.gz".format(postfix))
|
||||
# with gzip.open(aircraft_beacons_file, "wt", encoding="utf-8") as gzip_file:
|
||||
# self.cur.copy_expert("COPY ({}) TO STDOUT WITH (DELIMITER ',', FORMAT CSV, HEADER, ENCODING 'UTF-8');".format(self.get_merged_aircraft_beacons_subquery()), gzip_file)
|
||||
# receiver_beacons_file = os.path.join(path, "receiver_beacons_{0}.csv.gz".format(postfix))
|
||||
# with gzip.open(receiver_beacons_file, "wt") as gzip_file:
|
||||
# self.cur.copy_expert("COPY ({}) TO STDOUT WITH (DELIMITER ',', FORMAT CSV, HEADER, ENCODING 'UTF-8');".format(self.get_merged_receiver_beacons_subquery()), gzip_file)
|
||||
|
||||
|
||||
def convert(sourcefile, datestr, saver):
|
||||
|
@ -315,7 +317,8 @@ def convert(sourcefile, datestr, saver):
|
|||
if message is None:
|
||||
continue
|
||||
|
||||
dictfilt = lambda x, y: dict([(i, x[i]) for i in x if i in set(y)])
|
||||
def dictfilt(x, y):
|
||||
return dict([(i, x[i]) for i in x if i in set(y)])
|
||||
|
||||
try:
|
||||
if message["beacon_type"] in AIRCRAFT_BEACON_TYPES:
|
||||
|
@ -385,11 +388,11 @@ def file_import(path):
|
|||
results = list()
|
||||
for (root, dirs, files) in os.walk(path):
|
||||
for file in sorted(files):
|
||||
match = re.match("OGN_log\.txt_([0-9]{4}\-[0-9]{2}\-[0-9]{2})\.gz$", file)
|
||||
match = re.match(r"OGN_log\.txt_([0-9]{4}\-[0-9]{2}\-[0-9]{2})\.gz$", file)
|
||||
if match:
|
||||
results.append({"filepath": os.path.join(root, file), "datestr": match.group(1)})
|
||||
|
||||
with LogfileDbSaver() as saver:
|
||||
with LogfileDbSaver() as saver: # noqa: F821
|
||||
already_imported = saver.get_datestrs()
|
||||
|
||||
results = list(filter(lambda x: x["datestr"] not in already_imported, results))
|
||||
|
|
|
@ -1,12 +1,10 @@
|
|||
from flask import request, render_template, make_response, send_file, current_app
|
||||
from flask import request, render_template, current_app
|
||||
from flask_cors import cross_origin
|
||||
|
||||
from app.backend.liveglidernet import rec, lxml
|
||||
from app import db
|
||||
from app import cache
|
||||
|
||||
from app.main import bp
|
||||
|
||||
|
||||
@bp.route("/live.html")
|
||||
@cross_origin()
|
||||
def live():
|
||||
|
|
|
@ -4,7 +4,7 @@ from flask import request, render_template, send_file
|
|||
|
||||
from app import db
|
||||
from app import cache
|
||||
from app.model import *
|
||||
from app.model import Airport, Country, Device, Logbook, Receiver, ReceiverStats
|
||||
|
||||
from app.main import bp
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
|
||||
from sqlalchemy.sql import null, case
|
||||
from app import db
|
||||
|
||||
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
import os
|
||||
|
||||
from flask_migrate import Migrate
|
||||
from app import create_app, db
|
||||
from app.commands import register
|
||||
from app import create_app, db, commands
|
||||
|
||||
app = create_app(os.getenv('FLASK_CONFIG') or 'default')
|
||||
migrate = Migrate(app, db)
|
||||
register(app)
|
||||
commands.register(app)
|
||||
|
||||
@app.shell_context_processor
|
||||
def make_shell_context():
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
[flake8]
|
||||
ignore = E501, E126
|
||||
ignore = F401, F841, E402, E501, E126
|
||||
|
|
Ładowanie…
Reference in New Issue