From a6c856cf489e5c9fc424bac081070ad4057093bd Mon Sep 17 00:00:00 2001 From: suti7yk5032 Date: Thu, 5 Sep 2024 21:03:39 +0900 Subject: [PATCH] =?UTF-8?q?temp=E3=81=AE=E4=B8=AD=E3=82=92=E5=89=8A?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- temp/client_playground.py | 40 ---------------- temp/csv_test.py | 77 ------------------------------- temp/kill.py | 22 --------- temp/password.py | 16 ------- temp/password.txt | 0 temp/powershell.py | 9 ---- temp/test.py | 41 ----------------- temp/xcel.py | 97 --------------------------------------- 9 files changed, 1 insertion(+), 304 deletions(-) delete mode 100644 temp/client_playground.py delete mode 100644 temp/csv_test.py delete mode 100644 temp/kill.py delete mode 100644 temp/password.py delete mode 100644 temp/password.txt delete mode 100644 temp/powershell.py delete mode 100644 temp/test.py delete mode 100644 temp/xcel.py diff --git a/.gitignore b/.gitignore index 541d26b..f5c0150 100644 --- a/.gitignore +++ b/.gitignore @@ -164,5 +164,4 @@ config/ db/ test.py data/ -export/ -temp/ \ No newline at end of file +export/ \ No newline at end of file diff --git a/temp/client_playground.py b/temp/client_playground.py deleted file mode 100644 index f0a4879..0000000 --- a/temp/client_playground.py +++ /dev/null @@ -1,40 +0,0 @@ -import os -import subprocess -import shutil - -def delete_appdata(**kwargs): - process_name = kwargs["process_name"] - dir_path = kwargs["dir_path"] - - if not os.path.exists(dir_path): - print(f"エラー: 指定されたディレクトリ {dir_path} が存在しません。") - return 1 - - try: - # プロセスの終了 - subprocess.run(['taskkill', '/f', '/t', '/im', process_name]) - print(f"{process_name} を終了しました。") - - # ディレクトリの削除 - shutil.rmtree(dir_path) - print(f"{dir_path} を削除しました。") - - return 0 - except subprocess.CalledProcessError as e: - print(f"プロセス終了エラー: {e}") - return 1 - except PermissionError as e: - print(f"権限エラー: {e}") - return 1 - except Exception as error: - print("エラーが発生しました。\nエラー内容:") - print(f"エラータイプ: {error.__class__.__name__}") - print(f"エラー引数: {error.args}") - print(f"エラーメッセージ: {str(error)}") - return 1 - -appdata_local = os.path.expandvars("%LOCALAPPDATA%") -appdata_roaming = os.path.expandvars("%APPDATA%") -print(appdata_local, appdata_roaming) -print(f"{appdata_local}\\Steam") -steam_del = delete_appdata(process_name="steam.exe", dir_path=f"{appdata_local}\\Steam") \ No newline at end of file diff --git a/temp/csv_test.py b/temp/csv_test.py deleted file mode 100644 index 9b30aa8..0000000 --- a/temp/csv_test.py +++ /dev/null @@ -1,77 +0,0 @@ -import psycopg2 -import csv -from psycopg2 import sql -from datetime import datetime - -def format_datetime(value): - if isinstance(value, datetime): - return value.strftime('%Y-%m-%d %H:%M:%S') - return value - -def export_table_to_csv(host, port, database, user, password, main_table, related_table, related_column, csv_file_path): - try: - # データベースに接続 - conn = psycopg2.connect( - host=host, - port=port, - database=database, - user=user, - password=password - ) - - cur = conn.cursor() - - # メインテーブルの列情報を取得(user_idを除く) - cur.execute(sql.SQL("SELECT * FROM {} LIMIT 0").format(sql.Identifier(main_table))) - main_columns = [desc[0] for desc in cur.description if desc[0] != 'member_id'] - - # クエリを作成(列名を明確に指定) - query = sql.SQL(""" - SELECT {main_columns}, {related_table}.name - FROM {main_table} - LEFT JOIN {related_table} ON {main_table}.member_id = {related_table}.id - """).format( - main_columns=sql.SQL(', ').join([sql.SQL("{}.{}").format(sql.Identifier(main_table), sql.Identifier(col)) for col in main_columns]), - main_table=sql.Identifier(main_table), - related_table=sql.Identifier(related_table) - ) - - cur.execute(query) - - # 列名を再構成(nameを2番目に配置) - column_names = [main_columns[0], 'name'] + main_columns[1:] - - rows = cur.fetchall() - - with open(csv_file_path, 'w', newline='', encoding='utf-8-sig') as csvfile: - csvwriter = csv.writer(csvfile) - csvwriter.writerow(column_names) - - for row in rows: - # nameを2番目に移動 - formatted_row = [format_datetime(row[0])] + [row[-1]] + [format_datetime(field) if field is not None else '' for field in row[1:-1]] - csvwriter.writerow(formatted_row) - - print(f"テーブル '{main_table}' の内容を '{csv_file_path}' に出力しました。") - - except (Exception, psycopg2.Error) as error: - print("エラーが発生しました:", error) - - finally: - if conn: - cur.close() - conn.close() - print("データベース接続を閉じました。") - -# 使用例 -host = "192.168.1.220" -port = "12245" -database = "dislocker" -user = "suti7" -password = "Testing1234" -main_table = "pc_usage_history" -related_table = "club_member" -related_column = "name" # 例: 登録者の名前を表示したい場合 -csv_file_path = "output.csv" - -export_table_to_csv(host, port, database, user, password, main_table, related_table, related_column, csv_file_path) diff --git a/temp/kill.py b/temp/kill.py deleted file mode 100644 index 2c68cbf..0000000 --- a/temp/kill.py +++ /dev/null @@ -1,22 +0,0 @@ -import wmi -import asyncio - -async def watcher(): - c=wmi.WMI() - cre_process_watcher=c.Win32_Process.watch_for("creation") - del_process_watcher=c.Win32_Process.watch_for("deletion") - - while True: - new_cre_process=cre_process_watcher() - new_del_process=del_process_watcher() - print(new_cre_process.Caption+" has been created") - print(new_del_process.Caption+" has been deleted ") - -async def main(): - kill_task = asyncio.TaskGroup(watcher()) - print('hello world') - await asyncio.sleep(1) - print('1sec') - await kill_task - -asyncio.run(main()) diff --git a/temp/password.py b/temp/password.py deleted file mode 100644 index 6d1c9d7..0000000 --- a/temp/password.py +++ /dev/null @@ -1,16 +0,0 @@ -import random -import string -# パスワードをファイルから読み込む - -with open('password.txt', 'r') as f: - secret = f.read() - -check=int(input("password :")) - -if check==int(secret): - print("ok") - secret=0 - with open('password.txt', 'w') as file: - file.write('') -else: - print("out") \ No newline at end of file diff --git a/temp/password.txt b/temp/password.txt deleted file mode 100644 index e69de29..0000000 diff --git a/temp/powershell.py b/temp/powershell.py deleted file mode 100644 index 97f65f6..0000000 --- a/temp/powershell.py +++ /dev/null @@ -1,9 +0,0 @@ -import os - -# PowerShellコマンドを実行する関数 -def run_powershell_command(command): - # PowerShellコマンドを実行 - os.system(f"powershell -Command {command}") - -# 例としてGet-Dateコマンドを実行して現在の日時を取得 -run_powershell_command("Get-Date") diff --git a/temp/test.py b/temp/test.py deleted file mode 100644 index 03e0e7b..0000000 --- a/temp/test.py +++ /dev/null @@ -1,41 +0,0 @@ - -import discord -import string -import random - -# Intentsの設定 -intents = discord.Intents.default() -intents.message_content = True - -# 接続に必要なオブジェクトを生成 -client = discord.Client(intents=intents) - -# 起動時に動作する処理 -@client.event -async def on_ready(): - # 起動したらターミナルにログイン通知が表示される - print('ログインしました') - -# メッセージ受信時に動作する処理 -@client.event -async def on_message(message): - # メッセージ送信者がBotだった場合は無視する - if message.author.bot: - return - # 「/neko」と発言したら「にゃーん」が返る処理 - if message.content == "/neko": - await message.channel.send('にゃーん') - - if message.content == '/password': - secret=password_generator_n(4) - await message.channel.send(str(secret)) - with open('password.txt', 'a') as file: - file.write(secret) - -def password_generator_n(length): - numbers = string.digits # (1) - password = ''.join(random.choice(numbers) for _ in range(length)) # (2) - return password - -# Botの起動とDiscordサーバーへの接続 -client.run('MTI0NzA1Mzc1NzUxOTM2NDEyNw.Gh5gIt.kz1acBMxphff9mEZLLWrEdEoVD4RJwgBW5P14o') diff --git a/temp/xcel.py b/temp/xcel.py deleted file mode 100644 index 684cfc7..0000000 --- a/temp/xcel.py +++ /dev/null @@ -1,97 +0,0 @@ -import psycopg2 -import csv -from psycopg2 import sql -from datetime import datetime -from openpyxl import Workbook -from openpyxl.utils import get_column_letter - -def format_datetime(value): - if isinstance(value, datetime): - return value.strftime('%Y-%m-%d %H:%M:%S') - return value - -def export_table_to_excel(host, port, database, user, password, main_table, related_table, excel_file_path): - try: - conn = psycopg2.connect( - host=host, - port=port, - database=database, - user=user, - password=password - ) - - cur = conn.cursor() - - # メインテーブルの列情報を取得(member_idを除く) - cur.execute(sql.SQL("SELECT * FROM {} LIMIT 0").format(sql.Identifier(main_table))) - main_columns = [desc[0] for desc in cur.description if desc[0] != 'member_id'] - - # クエリを作成(列名を明確に指定) - query = sql.SQL(""" - SELECT {main_columns}, {related_table}.name - FROM {main_table} - LEFT JOIN {related_table} ON {main_table}.member_id = {related_table}.id - """).format( - main_columns=sql.SQL(', ').join([sql.SQL("{}.{}").format(sql.Identifier(main_table), sql.Identifier(col)) for col in main_columns]), - main_table=sql.Identifier(main_table), - related_table=sql.Identifier(related_table) - ) - - cur.execute(query) - - # 列名を再構成(nameを2番目に配置) - column_names = [main_columns[0], 'name'] + main_columns[1:] - - rows = cur.fetchall() - - # Excelワークブックを作成 - wb = Workbook() - ws = wb.active - - # 列名を書き込み - ws.append(column_names) - - # データを書き込み - for row in rows: - # nameを2番目に移動 - formatted_row = [format_datetime(row[0])] + [row[-1]] + [format_datetime(field) if field is not None else '' for field in row[1:-1]] - ws.append(formatted_row) - - # 列幅を自動調整 - for col in ws.columns: - max_length = 0 - column = col[0].column_letter - for cell in col: - try: - if len(str(cell.value)) > max_length: - max_length = len(str(cell.value)) - except: - pass - adjusted_width = (max_length + 2) * 1.2 - ws.column_dimensions[column].width = adjusted_width - - # Excelファイルを保存 - wb.save(excel_file_path) - - print(f"テーブル '{main_table}' の内容を '{excel_file_path}' に出力しました。") - - except (Exception, psycopg2.Error) as error: - print("エラーが発生しました:", error) - - finally: - if conn: - cur.close() - conn.close() - print("データベース接続を閉じました。") - -# 使用例 -host = "192.168.1.220" -port = "12245" -database = "dislocker" -user = "suti7" -password = "Testing1234" -main_table = "pc_usage_history" -related_table = "club_member" -excel_file_path = "output.xlsx" - -export_table_to_excel(host, port, database, user, password, main_table, related_table, excel_file_path)