Exemplo n.º 1
0
import sqlite3 as sql

from pyinputplus import inputMenu

from exec_utils.configloader import Config
from counts import Counts
from modules.input import Proceed
from modules.run import Execute
from modules.exceptions import Duplicate
from fromfile import WriteFromFile
from fromjson import FromJson
from fromxml import FromXML

cnf = Config()
p = Proceed(cnf.get_values("INPUTS", "proceed_msg"),
            cnf.get_values("MESSAGES", "goodbye"))
e = Execute()
wff = WriteFromFile(cnf.get_values("PATHS", "source_file"),
                    cnf.get_values("PATHS", "target_file"))
fj = FromJson(cnf.get_values("PATHS", "json_source"),
              cnf.get_values("PATHS", "target_file"))
fx = FromXML(cnf.get_values("PATHS", "xml_source"),
             cnf.get_values("PATHS", "target_file"))
cnt = Counts(cnf.get_values("PATHS", "target_file"),
             cnf.get_values("PATHS", "csv_words"),
             cnf.get_values("PATHS", "csv_letters"))


def manual_input():
    """Run end-to-end manual input flow (ask for input, write to file),
    ask if user wants to proceed - if yes, run again, if no - print goodbye message.
Exemplo n.º 2
0
import sqlite3 as sql

from exec_utils.configloader import Config
from modules.file import Files

cnf = Config()
f = Files()

label1, label2, label3 = cnf.get_values("LABELS", "news_label"), \
                         cnf.get_values("LABELS", "ad_label"), \
                         cnf.get_values("LABELS", "recipe_label")


class DBconnection:
    def __init__(self, db_name):
        with sql.connect(f.get_path(db_name)) as self.con:
            self.curs = self.con.cursor()

    def go(self, statement, predicates=''):
        """Execute sql statement"""
        self.curs.execute(statement, predicates)
        self.con.commit()

    def create_table(self, table_name):
        if table_name == label1:  # News
            self.go(cnf.get_values("SQL", "create_table_news"))
        elif table_name == label2:  # Private ad
            self.go(cnf.get_values("SQL", "create_table_ad"))
        elif table_name == label3:  # Recipe
            self.go(cnf.get_values("SQL", "create_table_recipe"))
Exemplo n.º 3
0
import argparse
from jsonschema import validate, ValidationError, SchemaError
from json import load, JSONDecodeError

from counts import Counts
from exec_utils.configloader import Config
from fromfile import WriteFromFile
from modules.combine import Combine
from modules.dates import Dates
from modules.exceptions import PastDate, NoValue
from modules.file import Files
from modules.input import DateInput
from modules.run import Execute

cnf = Config()
cnt = Counts(cnf.get_values("PATHS", "target_file"), cnf.get_values("PATHS", "csv_words"), cnf.get_values("PATHS", "csv_letters"))
dte = Dates()
di = DateInput(cnf.get_values("ERRORS", "past_date"),
               cnf.get_values("PATTERNS", "date_format"),
               dte.get_current_date())
e = Execute()
f = Files()

label1, label2, label3 = cnf.get_values("LABELS", "news_label"), \
                         cnf.get_values("LABELS", "ad_label"), \
                         cnf.get_values("LABELS", "recipe_label")
decor, decor_length = cnf.get_values("RESTRICTIONS", "n"), \
                      cnf.get_values("RESTRICTIONS", "count_n")
city, txt, date, cal = cnf.get_values("PROPERTIES", "city"), \
                       cnf.get_values("PROPERTIES", "text"), \
                       cnf.get_values("PROPERTIES", "date"), \
Exemplo n.º 4
0
from exec_utils.configloader import Config

cnf = Config()


class NoSectionsError(Exception):
    """Raised when no elements with tag = sectionLabel can be found in the source file"""
    def __init__(self, section_label):
        self.section = section_label
        self.message = cnf.get_values(
            "ERRORS", "no_sections").format(s=self.section) + "\n"
        super().__init__(self.message)


class PastDate(Exception):
    """Raised when provided date is before the current date"""
    def __init__(self, my_date):
        self.my_date = my_date
        self.message = cnf.get_values("ERRORS",
                                      "past_date").format(date=my_date) + "\n"
        super().__init__(self.message)


class NoValue(Exception):
    """Raised when provided value is Falsy"""
    def __init__(self, section_label, element):
        self.section = section_label
        self.element = element
        self.message = cnf.get_values(
            "ERRORS", "no_value") % (self.element, self.section) + "\n"
        super().__init__(self.message)
Exemplo n.º 5
0
import sqlite3 as sql

from exec_utils.configloader import Config
from modules.input import Selection, TextInput, DateInput, IntInput
from modules.dates import Dates
from modules.file import Files
from modules.combine import Combine
from modules.dbconnect import DBconnection
from modules.exceptions import Duplicate, PastDate, InvalidNumber
from modules.logging import Log

cnf = Config()
s = Selection()
f = Files()
d = Dates()
t = TextInput(cnf.get_values("ERRORS", "long_text"),
              cnf.get_values("RESTRICTIONS", "max_size"))
di = DateInput(cnf.get_values("ERRORS", "past_date"),
               cnf.get_values("PATTERNS", "date_format"), d.get_current_date())
ii = IntInput(cnf.get_values("RESTRICTIONS", "cal_min"))
lg = Log(cnf.get_values("PATHS", "log_file"))

label1, label2, label3 = cnf.get_values("LABELS", "news_label"), \
                         cnf.get_values("LABELS", "ad_label"), \
                         cnf.get_values("LABELS", "recipe_label")
decor, decor_length = cnf.get_values("RESTRICTIONS", "n"), \
                      cnf.get_values("RESTRICTIONS", "count_n")


class Execute:
    def news_values(self):
Exemplo n.º 6
0
import pyinputplus as pyip

from counts import Counts
from exec_utils.configloader import Config
from modules.combine import Combine
from modules.dates import Dates
from modules.dbconnect import DBconnection
from modules.exceptions import NoSectionsError, NoValue, PastDate, Duplicate, InvalidNumber
import modules.Functions_Strings_Homework4 as s
from modules.file import Files
from modules.input import DateInput
from modules.logging import Log
from modules.run import Execute

cnf = Config()
f = Files()
cnt = Counts(cnf.get_values("PATHS", "target_file"),
             cnf.get_values("PATHS", "csv_words"),
             cnf.get_values("PATHS", "csv_letters"))
d = Dates()
e = Execute()
di = DateInput(cnf.get_values("ERRORS", "past_date"),
               cnf.get_values("PATTERNS", "date_format"), d.get_current_date())
db = DBconnection(cnf.get_values("PATHS", "db_name"))
lg = Log(cnf.get_values("PATHS", "log_file"))

decor, decor_length = cnf.get_values("RESTRICTIONS", "n"), \
                      cnf.get_values("RESTRICTIONS", "count_n")
# property names (the same as in JSON)
section, city, text, date, calories = cnf.get_values("PROPERTIES", "label"), \
Exemplo n.º 7
0
import csv
from re import findall
from collections import Counter

from exec_utils.configloader import Config
from modules.file import Files

cnf = Config()
f = Files()


class Counts:
    def __init__(self, count_in_file, words_csv, letters_csv):
        self.source = count_in_file  # use this file as source for counts
        self.words_csv = words_csv
        self.letters_csv = letters_csv

    def get_text(self):
        """Open and read file"""
        path = f.get_path(self.source)
        with open(path, "r", encoding="utf-8") as file:
            my_text = file.read()
        return my_text

    def words(self):
        """Split text into words"""
        text = self.get_text()
        words_list = findall(r'\b[\w\']+\b', text.lower())
        return words_list

    def words_count(self):