import datetime import logging import re import sqlite3 import threading from dataclasses import dataclass, field from typing import List, Union, Iterable from bs4 import BeautifulSoup as Soup from rpi.custom_logging import configure_logging from rpi.dns import RpiDns from rpi.downloader import Downloader from rpi.exceptions import InvalidMonthError, InvalidDayError, DownloaderError configure_logging(called_from=__file__, use_logs_folder=True) MONTHS = ("enero", "febrero", "marzo", "abril", "mayo", "junio", "julio", "agosto", "septiembre", "octubre", "noviembre", "diciembre") DAYS = ("lunes", "martes", "miercoles", "jueves", "viernes", "sabado", "domingo") ACCENT_DAYS = ("lunes", "martes", "miércoles", "jueves", "viernes", "sábado", "domingo") ENGLISH_DAYS = ('MONDAY', 'TUESDAY', 'WEDNESDAY', 'THURSDAY', 'FRIDAY', 'SATURDAY', 'SUNDAY') def extend_date(anything: Union[Iterable[str], str]): """Extends a date or a set of dates of 01/01/2018 type into DIA: 01 de Enero de 2018 (Lunes).""" output = [] if isinstance(anything, str):
import argparse import logging import platform from datetime import datetime, timedelta from rpi.connections import Connections from rpi.custom_logging import configure_logging from rpi.managers.users_manager import UsersManager from busdatagenerator import analyse_stop CHOICES = ('GAMAZO', 'CLINICO') if platform.system() == 'Linux': LINUX = True configure_logging(filename='/home/pi/busstats/busstats.log') else: LINUX = False configure_logging(name='busstats', filename='D:/.scripts/busstats/busstats.log') if __name__ == '__main__': logger = logging.getLogger(__name__) parser = argparse.ArgumentParser('BusWarner') parser.add_argument('choice', choices=CHOICES) parser.add_argument('notify', nargs='+', choices=UsersManager().usernames) opt = parser.parse_args() logger.debug('Options: %r', opt)
""" import datetime import logging import os import re import time from typing import Iterable, Dict, Callable from bs4 import BeautifulSoup as Soup from dataclasses import dataclass, field from rpi.custom_logging import configure_logging from rpi.downloader import Downloader from busdatagenerator import DataBase, Register configure_logging(name='analyser') logger = logging.getLogger(__name__) class InvalidStopIdError(Exception): """Provided an invalid stop id.""" @dataclass class UltimateRegister(Register): # noinspection PyUnresolvedReferences """Representation of a busstats register with more information. Notes: This class only works for registers with delay_minutes=0.
import logging import os import platform import socketserver import time from datetime import datetime from http.server import BaseHTTPRequestHandler, HTTPServer from urllib.parse import unquote from cryptography.fernet import InvalidToken from rpi.custom_logging import configure_logging from rpi.encryption import decrypt configure_logging(name='rest_server') if platform.system() == 'Linux': LOG_PATH = '/home/pi/busstats/rest_server.log' SOURCE_CSV = '/home/pi/busstats/busstats.csv' OUTPUT_CSV = '/home/pi/busstats/busstats.test.csv' SERVER_ADDRESS = 'http://sralloza.sytes.net:5415' else: LOG_PATH = 'rest_server.log' SOURCE_CSV = 'D:/Sistema/Downloads/busstats.csv' OUTPUT_CSV = 'D:/Sistema/Downloads/busstats.test.csv' SERVER_ADDRESS = 'http://localhost:5415' def get_bus_data(get=False, delete=False): logger = logging.getLogger(__name__) if get and delete:
import datetime import logging import time from rpi.custom_logging import configure_logging from busdataanalysis import DataManager from busdatagenerator import DataBase configure_logging(name='converter') logger = logging.getLogger('converter') def convert(): today = datetime.datetime.today() output_db = DataBase() output_db.use(database_path=f'{today}.sqlite') logger.debug('Loading data') dm = DataManager.load() logger.debug('Data loaded') logger.debug('Filtering data') dm.filter_times(datetime.time(8, 0), datetime.time(9, 0)) logger.debug('Data filtered') logger.debug('Inserting data') output_db.insert_multiple_registers(dm) logger.debug('Data inserted')