Exemple #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.
Exemple #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"))
Exemple #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"), \
Exemple #4
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):
Exemple #5
0
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"), \
                                      cnf.get_values("PROPERTIES", "city"), \
                                      cnf.get_values("PROPERTIES", "text"), \
Exemple #6
0
import xml.dom.minidom
from xml.parsers.expat import ExpatError

from modules.combine import Combine
from modules.dates import Dates
from modules.file import Files
from modules.input import DateInput
from exec_utils.configloader import Config
from fromjson import FromJson

# instantiate classes
cnf = Config()
f = Files()
dte = Dates()
di = DateInput(cnf.get_values("ERRORS", "past_date"),
               cnf.get_values("PATTERNS", "date_format"),
               dte.get_current_date())

# declare variables
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")
label, city, txt, date, cal = cnf.get_values("PROPERTIES", "label"), \
                              cnf.get_values("PROPERTIES", "city"), \
                              cnf.get_values("PROPERTIES", "text"), \
                              cnf.get_values("PROPERTIES", "date"), \
                              cnf.get_values("PROPERTIES", "kcal")

Exemple #7
0
                        })
        sorted_list = sorted(my_list, key=lambda k: k['perc'], reverse=True)
        return sorted_list

    def write_csv(self):
        """"Write 2 csvs: from words and from letters. In letters: take dict keys as headers"""
        words_dict = self.words_count()
        list_of_letter_dicts = self.dicts_by_letter_counts()
        words_file_path, letters_file_path = f.get_path(
            self.words_csv), f.get_path(self.letters_csv)
        with open(words_file_path, 'w+', newline='', encoding="utf-8") as words_csv,\
                open(letters_file_path,'w+', newline='', encoding="utf-8") as letters_csv:
            words_writer = csv.writer(words_csv, delimiter='-')
            for word in words_dict:
                words_writer.writerow(word)
            letters_writer = csv.DictWriter(
                letters_csv,
                delimiter=',',
                fieldnames=list_of_letter_dicts[0].keys(
                ))  # column headers = keys from first dict in list
            letters_writer.writeheader()
            for dict in list_of_letter_dicts:
                letters_writer.writerow(dict)


if __name__ == "__main__":
    c = Counts(cnf.get_values("PATHS", "target_file"),
               cnf.get_values("PATHS", "csv_words"),
               cnf.get_values("PATHS", "csv_letters"))
    c.write_csv()