Skip to content

Commit

Permalink
performance optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
onuratakan authored May 29, 2024
1 parent 461c032 commit 2bf743e
Show file tree
Hide file tree
Showing 22 changed files with 93 additions and 68 deletions.
3 changes: 2 additions & 1 deletion tiger/tools/browser/open_url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import webbrowser


def open_url(url) -> bool:
Expand All @@ -7,6 +6,8 @@ def open_url(url) -> bool:
:param url: str:
"""
import webbrowser

try:
webbrowser.open(url)
return True
Expand Down
9 changes: 5 additions & 4 deletions tiger/tools/communication/telegram/as_user/delete_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import asyncio
import time

from telethon.sync import TelegramClient


def delete_message(id: int, message: str):
Expand All @@ -11,6 +7,11 @@ def delete_message(id: int, message: str):
:param message: str:
"""
import asyncio
import time

from telethon.sync import TelegramClient

id = int(id)
import nest_asyncio

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
import asyncio
import time

from telethon.sync import TelegramClient


def get_last_dialogs(limit=100):
Expand All @@ -10,6 +6,11 @@ def get_last_dialogs(limit=100):
:param limit: (Default value = 100)
"""
import asyncio
import time

from telethon.sync import TelegramClient

import nest_asyncio

nest_asyncio.apply()
Expand Down
11 changes: 6 additions & 5 deletions tiger/tools/communication/telegram/as_user/get_last_messages.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import asyncio
import time

from telethon.sync import TelegramClient


def get_last_messages(id: int, limit=100):
"""
Expand All @@ -11,6 +6,12 @@ def get_last_messages(id: int, limit=100):
:param limit: (Default value = 100)
"""
import asyncio
import time

from telethon.sync import TelegramClient


id = int(id)
import nest_asyncio

Expand Down
11 changes: 6 additions & 5 deletions tiger/tools/communication/telegram/as_user/send_message.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
import asyncio
import time

from telethon.sync import TelegramClient


def send_message(id: int, message: str) -> str:
"""
Expand All @@ -11,6 +6,12 @@ def send_message(id: int, message: str) -> str:
:param message: str:
"""
import asyncio
import time

from telethon.sync import TelegramClient


id = int(id)
import nest_asyncio

Expand Down
11 changes: 6 additions & 5 deletions tiger/tools/communication/telegram/as_user/signin.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
import time

from telethon.sync import TelegramClient


def signin():
""" """
import asyncio
import time

from telethon.sync import TelegramClient


import nest_asyncio

nest_asyncio.apply()
Expand Down
3 changes: 2 additions & 1 deletion tiger/tools/interpreter/python/check_package.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from importlib_metadata import distribution, PackageNotFoundError

def check_package(package:str) -> bool:
from importlib_metadata import distribution, PackageNotFoundError

try:
distribution(package)
print(f"'{package}' is installed.")
Expand Down
3 changes: 2 additions & 1 deletion tiger/tools/interpreter/python/execute.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from IPython import get_ipython


def execute(cell:str) -> str:
from IPython import get_ipython

ipython = get_ipython()
result = ipython.run_cell(cell)
log = str(result.result)
Expand Down
7 changes: 4 additions & 3 deletions tiger/tools/interpreter/python/install_package.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from subprocess import check_call
from importlib_metadata import distribution


def install_package(package:str) -> bool:
from subprocess import check_call
from importlib_metadata import distribution


try:
check_call(["pip", "install", package])
distribution(package)
Expand Down
3 changes: 2 additions & 1 deletion tiger/tools/interpreter/sh/execute.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from subprocess import Popen, PIPE


def execute(script:str) -> str:
from subprocess import Popen, PIPE

process = Popen(script, stdout=PIPE, shell=True, stderr=PIPE, universal_newlines=True)
stdout, stderr = process.communicate()
log = stdout
Expand Down
12 changes: 7 additions & 5 deletions tiger/tools/knowledge/delete.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB


def delete(knowledge_name: str) -> bool:
Expand All @@ -12,6 +7,13 @@ def delete(knowledge_name: str) -> bool:
:param knowledge_name: str:
"""
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB

folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)),
"upsonic_tiger_knowledge.json")
db = TinyDB(folder)
Expand Down
14 changes: 8 additions & 6 deletions tiger/tools/knowledge/index.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB


def index() -> list:
""" """
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB


folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)),
"upsonic_tiger_knowledge.json")
db = TinyDB(folder)
Expand Down
14 changes: 8 additions & 6 deletions tiger/tools/knowledge/pull.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB


def pull(knowledge_name: str) -> str:
Expand All @@ -12,6 +6,14 @@ def pull(knowledge_name: str) -> str:
:param knowledge_name: str:
"""
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB


folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)),
"upsonic_tiger_knowledge.json")
db = TinyDB(folder)
Expand Down
11 changes: 6 additions & 5 deletions tiger/tools/knowledge/put.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB


def put(knowledge_name: str, description: str) -> bool:
Expand All @@ -13,6 +8,12 @@ def put(knowledge_name: str, description: str) -> bool:
:param description: str:
"""
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB
folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)),
"upsonic_tiger_knowledge.json")
db = TinyDB(folder)
Expand Down
11 changes: 6 additions & 5 deletions tiger/tools/knowledge/reset.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB


def reset() -> None:
""" """
import inspect
import os

import upsonic
from tinydb import Query
from tinydb import TinyDB
folder = os.path.join(os.path.dirname(inspect.getfile(upsonic)),
"upsonic_tiger_knowledge.json")
db = TinyDB(folder)
Expand Down
5 changes: 3 additions & 2 deletions tiger/tools/search/duckduckgo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from duckduckgo_search import DDGS


def search(query:str, max_number:int=20) -> list:
from duckduckgo_search import DDGS


return [result["href"] for result in DDGS().text(query, max_results=max_number)]


Expand Down
3 changes: 2 additions & 1 deletion tiger/tools/search/google.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from googlesearch import search as gsearch


def google(query:str, max_number:int=20) -> list:
from googlesearch import search as gsearch
return list(gsearch(query, stop=max_number))


Expand Down
9 changes: 5 additions & 4 deletions tiger/tools/search/read_website.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import requests

from bs4 import BeautifulSoup
import re


def read_website(url: str, max_content_lenght: int = 5000) -> dict:
import requests

from bs4 import BeautifulSoup
import re

html = requests.get(url).text
soup = BeautifulSoup(html)
meta_properties = [
Expand Down
3 changes: 2 additions & 1 deletion tiger/tools/system/architecture.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import platform


def architecture():
import platform

return platform.architecture()[0]


Expand Down
3 changes: 2 additions & 1 deletion tiger/tools/system/clipboard.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import pyperclip



def copy(text):
import pyperclip
pyperclip.copy(text)


Expand Down
3 changes: 2 additions & 1 deletion tiger/tools/system/os_name.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import platform

def os_name():
import platform

system_name = platform.system()
if system_name == 'Windows':
return 'Windows'
Expand Down
3 changes: 2 additions & 1 deletion tiger/tools/system/python_version.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import platform


def python_version():
import platform

return platform.python_version()


Expand Down

0 comments on commit 2bf743e

Please sign in to comment.