tempディレクトリ削除
This commit is contained in:
parent
8ade781d4b
commit
8658955998
8 changed files with 0 additions and 302 deletions
|
@ -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")
|
|
@ -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)
|
22
temp/kill.py
22
temp/kill.py
|
@ -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())
|
|
@ -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")
|
|
@ -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")
|
41
temp/test.py
41
temp/test.py
|
@ -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')
|
97
temp/xcel.py
97
temp/xcel.py
|
@ -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)
|
Loading…
Reference in a new issue