Skip to content

Commit

Permalink
get_s refac
Browse files Browse the repository at this point in the history
  • Loading branch information
SermetPekin committed Apr 16, 2024
1 parent abe9835 commit 0502cee
Show file tree
Hide file tree
Showing 108 changed files with 7,063 additions and 8,677 deletions.
Binary file modified .github/.DS_Store
Binary file not shown.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@

from evdspy import get_series, default_start_date_fnc, default_end_date_fnc

balance_of_pay1 = "TP.ODEMGZS.BDTTOPLAM", "TP.ODEMGZS.ABD"
balance_of_pay2 = """
index1 = "TP.ODEMGZS.BDTTOPLAM", "TP.ODEMGZS.ABD"
index2 = """
TP.ODEMGZS.BDTTOPLAM #
TP.ODEMGZS.ABD #
"""
cache = True

df = get_series(balance_of_pay2,
df = get_series(index1,
frequency="monthly",
start_date=default_start_date_fnc(),
end_date=default_end_date_fnc(),
Expand Down Expand Up @@ -143,7 +143,7 @@ proxies = {
* get_df_datagroup function was added

```python
from evdspy.main import *
from evdspy.main import *

df = get_df_datagroup(
datagroup="bie_gsyhgycf",
Expand Down
4 changes: 4 additions & 0 deletions evdspy/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,7 @@ cython_debug/
#.idea/
/_version.py
/EVDSlocal/APIKEY_FOLDER/
pickles/
logs/
SeriesData/
*.cfg
2 changes: 1 addition & 1 deletion evdspy/EVDSlocal/__version__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#1.1.17
#1.1.19
660 changes: 308 additions & 352 deletions evdspy/EVDSlocal/common/colors.py

Large diffs are not rendered by default.

44 changes: 21 additions & 23 deletions evdspy/EVDSlocal/common/common_imports.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
from dataclasses import dataclass, field
from collections import namedtuple
import requests
import sys
import pandas as pd
from pathlib import Path
from rich import print, inspect
from typing import List, Dict, Optional
import os
from pathlib import Path
import time
from abc import ABC, abstractmethod
from typing import Optional
from typing import TypeVar
import base64
from datetime import date, datetime
from enum import Enum
import functools

from evdspy.EVDSlocal.helper.print_m import *

from evdspy.EVDSlocal.log_classes.log_template import deb, deb2, debug


from dataclasses import dataclass, field
from collections import namedtuple
import requests
import sys
import pandas as pd
from pathlib import Path
from rich import print, inspect
from typing import List, Dict, Optional
import os
from pathlib import Path
import time
from abc import ABC, abstractmethod
from typing import Optional
from typing import TypeVar
import base64
from datetime import date, datetime
from enum import Enum
import functools
from evdspy.EVDSlocal.helper.print_m import *
from evdspy.EVDSlocal.log_classes.log_template import deb, deb2, debug
291 changes: 126 additions & 165 deletions evdspy/EVDSlocal/common/files.py
Original file line number Diff line number Diff line change
@@ -1,165 +1,126 @@
from .colors import *

filename = 't.txt'
content = 'aaa'
from ..common.common_imports import *
from typing import Union
from pathlib import Path


class WriteContext:
def __init__(self, fname, content, msg, mode="w"):
self.mode = mode
self.fname = fname
self.content = content
self.msg = msg

def __enter__(self):
self.file_ = open(self.fname, self.mode, encoding='utf-8')
self.file_.write(self.content)
return self

def __exit__(self, exc_type, exc_val, exc_tb):
self.file_.close()
if exc_tb:
print_with_failure_style(exc_tb)
print_with_failure_style(self.msg)
return True


def Write(fname="test.txt", content="test", msg="Error"):
info = f"{fname}"

result = False, "File was not created"
with WriteContext(fname, content, msg):
result = True, f"File was created... : {info}"
return result, f"File was created.. : {info}"


def WriteAdd(fname="test.txt", content="test", msg="Error"):
info = f"{fname}"
content = "\n" + content

result = False, "File was not created"
with WriteContext(fname, content, msg, mode="a"):
result = True, f"File was created... : {info}"
return result, f"File was created.. : {info}"


class ReadContext:
def __init__(self, fname, msg):
self.fname = fname
self.msg = msg

def __enter__(self):
# self.file_ = open(self.fname, "r", encoding='utf-8')
self.file_ = open(self.fname, "r", encoding='utf_8_sig')
return self.file_

def __exit__(self, exc_type, exc_val, exc_tb):
self.file_.close()
if exc_tb:
print_with_failure_style(exc_tb)
print_with_failure_style(self.msg)
return False
return True


def Read(file_name: Union[str, Path], msg="Error"):
if isinstance(file_name, str):
file_name = Path(file_name)
content = ""
with ReadContext(file_name, msg) as file_:
content = file_.read()
return content


def create_folder(folder_name: Union[str, Path]):
if isinstance(folder_name, str):
folder_name = Path(folder_name)
try:
os.makedirs(folder_name)
except FileExistsError:
print_with_updating_style("folder {} already exists".format(folder_name))
except Exception as e:
print_with_failure_style(e)


def is_file(path_: str):
d = Path(path_)
return d.is_file()


def is_dir(path_: str):
d = Path(path_)
return d.is_dir()


def WriteBytes(file_name: str, content_bytes: bytes):
with open(file_name, 'wb') as f:
f.write(content_bytes)


def WriteBytesAdd(file_name: str, content_bytes: bytes):
with open(file_name, 'ab') as f:
f.write(content_bytes)


def ReadBytes(file_name: str):
with open(file_name, "rb") as f:
return f.read()


def make_indented(content: str, indent=" " * 10) -> str:
content_tup: tuple = tuple(f"{indent}{x}" for x in content.splitlines())
content = "\n".join(content_tup)
return content


def add_one_line(cont_tuple: tuple, line: str) -> tuple:
cont: list = list(cont_tuple)
new_cont = cont + [line]
return tuple(new_cont)


# def content_continues_line(content: str) -> str:
# content = make_indented(content)
# content = make_it_summary(content, add_continue=True)
# return content
def line_continues_fn(skipped=0):
def cont_fn():
lns = "lines"
if skipped == 1:
lns = "line"
if skipped > 0:
msg = f"{skipped} {lns} more..."
# skipped_msg = "" if skipped > 0 else f"{skipped} line more..."
cont = "." * 15 + f"{msg}" + "." * 15
print_with_style(f"{cont}\n")
...

return cont_fn


def make_it_summary(content: str, max_line_num: int = 10, add_continue: bool = False) -> tuple:
content_tup: tuple = tuple(f"{x}" for x in content.splitlines())
new_content_tup: tuple = content_tup[0:max_line_num]
skipped_lines = len(content_tup) - max_line_num if len(content_tup) - max_line_num > 0 else 0
new_content_tup = add_one_line(new_content_tup, "." * 15)
return "\n".join(new_content_tup), skipped_lines


def file_exists_show_and_return(file_name: Union[str, Path]) -> bool:
if isinstance(file_name, str):
file_name = Path(file_name)
if file_name.is_file():
content_ = Read(file_name)
print_with_updating_style(f"file {file_name} exists, not replacing...\n")
print_with_color("content: \n -------\n", "blue")
cont_msg, skipped = make_it_summary(make_indented(content_), add_continue=False, max_line_num=10)
print(cont_msg)
"""print fn will return """
line_continues_fn(skipped)()
time.sleep(1)
return True
return False

from .colors import *
filename = 't.txt'
content = 'aaa'
from ..common.common_imports import *
from typing import Union
from pathlib import Path
class WriteContext:
def __init__(self, fname, content, msg, mode="w"):
self.mode = mode
self.fname = fname
self.content = content
self.msg = msg
def __enter__(self):
self.file_ = open(self.fname, self.mode, encoding='utf-8')
self.file_.write(self.content)
return self
def __exit__(self, exc_type, exc_val, exc_tb):
self.file_.close()
if exc_tb:
print_with_failure_style(exc_tb)
print_with_failure_style(self.msg)
return True
def Write(fname="test.txt", content="test", msg="Error"):
info = f"{fname}"
result = False, "File was not created"
with WriteContext(fname, content, msg):
result = True, f"File was created... : {info}"
return result, f"File was created.. : {info}"
def WriteAdd(fname="test.txt", content="test", msg="Error"):
info = f"{fname}"
content = "\n" + content
result = False, "File was not created"
with WriteContext(fname, content, msg, mode="a"):
result = True, f"File was created... : {info}"
return result, f"File was created.. : {info}"
class ReadContext:
def __init__(self, fname, msg):
self.fname = fname
self.msg = msg
def __enter__(self):
# self.file_ = open(self.fname, "r", encoding='utf-8')
self.file_ = open(self.fname, "r", encoding='utf_8_sig')
return self.file_
def __exit__(self, exc_type, exc_val, exc_tb):
self.file_.close()
if exc_tb:
print_with_failure_style(exc_tb)
print_with_failure_style(self.msg)
return False
return True
def Read(file_name: Union[str, Path], msg="Error"):
if isinstance(file_name, str):
file_name = Path(file_name)
content = ""
with ReadContext(file_name, msg) as file_:
content = file_.read()
return content
def create_folder(folder_name: Union[str, Path]):
if isinstance(folder_name, str):
folder_name = Path(folder_name)
try:
os.makedirs(folder_name)
except FileExistsError:
print_with_updating_style("folder {} already exists".format(folder_name))
except Exception as e:
print_with_failure_style(e)
def is_file(path_: str):
d = Path(path_)
return d.is_file()
def is_dir(path_: str):
d = Path(path_)
return d.is_dir()
def WriteBytes(file_name: str, content_bytes: bytes):
with open(file_name, 'wb') as f:
f.write(content_bytes)
def WriteBytesAdd(file_name: str, content_bytes: bytes):
with open(file_name, 'ab') as f:
f.write(content_bytes)
def ReadBytes(file_name: str):
with open(file_name, "rb") as f:
return f.read()
def make_indented(content: str, indent=" " * 10) -> str:
content_tup: tuple = tuple(f"{indent}{x}" for x in content.splitlines())
content = "\n".join(content_tup)
return content
def add_one_line(cont_tuple: tuple, line: str) -> tuple:
cont: list = list(cont_tuple)
new_cont = cont + [line]
return tuple(new_cont)
# def content_continues_line(content: str) -> str:
# content = make_indented(content)
# content = make_it_summary(content, add_continue=True)
# return content
def line_continues_fn(skipped=0):
def cont_fn():
lns = "lines"
if skipped == 1:
lns = "line"
if skipped > 0:
msg = f"{skipped} {lns} more..."
# skipped_msg = "" if skipped > 0 else f"{skipped} line more..."
cont = "." * 15 + f"{msg}" + "." * 15
print_with_style(f"{cont}\n")
...
return cont_fn
def make_it_summary(content: str, max_line_num: int = 10, add_continue: bool = False) -> tuple:
content_tup: tuple = tuple(f"{x}" for x in content.splitlines())
new_content_tup: tuple = content_tup[0:max_line_num]
skipped_lines = len(content_tup) - max_line_num if len(content_tup) - max_line_num > 0 else 0
new_content_tup = add_one_line(new_content_tup, "." * 15)
return "\n".join(new_content_tup), skipped_lines
def file_exists_show_and_return(file_name: Union[str, Path]) -> bool:
if isinstance(file_name, str):
file_name = Path(file_name)
if file_name.is_file():
content_ = Read(file_name)
print_with_updating_style(f"file {file_name} exists, not replacing...\n")
print_with_color("content: \n -------\n", "blue")
cont_msg, skipped = make_it_summary(make_indented(content_), add_continue=False, max_line_num=10)
print(cont_msg)
"""print fn will return """
line_continues_fn(skipped)()
time.sleep(1)
return True
return False
Loading

0 comments on commit 0502cee

Please sign in to comment.