Esempio n. 1
0
def main():
    print("** Videos テーブル用ビデオファイル一覧を作成または挿入する。**")
    # path 取得
    if Common.count_args() == 0:
        Common.stop(1, "使用方法: python3 InsVideos.py path insert")
    path = Common.args(0)
    # print/insert オプション取得
    insoption = False
    if Common.count_args() == 2:
        insoption = True
    # 確認
    if not insoption:
        print(f"Path = {path}, Videos テーブルに挿入 = {insoption}")
        a = Common.readline("Confirm (Y/N) > ")
        if Text.tolower(a) != 'y':
            Common.stop(2, "実行を中止しました。")
    else:
        pass
    # ビデオファイル一覧を取得する。
    vfiles = getVideoFiles(path)
    # INSERT 文を作成する。
    sql = "INSERT INTO Videos VALUES"
    for p in vfiles:
        p = p.replace("'", "''")
        fileName = FileSystem.getFileName(p)
        title = Text.left(fileName, len(fileName) - 4)
        sql += f"(NULL, '0', '{title}', '{p}', '', '', '', '', 0, 0, 0, 0, 0),\n"
        print(p)
    sql = Text.left(sql, len(sql) - 2) + ";"
    if not insoption:
        print(sql)
    if insoption:
        # INSERT 文を実行する。
        try:
            mysql = MySQL.MySQL(UID, PWD, UID)
            mysql.execute(sql)
            # 終了メッセージ
            if not insoption:
                print("正常に終了しました。")
        except Error as e:
            Common.stop("MySQL のエラーにより終了。接続条件やSQL をチェックしてください。" + e.message)
    return
Esempio n. 2
0
#SIZE = 2560
# 縮小画像ファイルのデフォルト保存先
SAVEPATH = 'C:/Temp/small/'
# True なら JPEG で保存
JPEG = True
# *************************************************

# ここから開始
if Common.count_args() == 0:
    print("画像縮小専用 Usage: python smalls.py folder size save_path")
    folder = Common.readline(
        "画像ファイルの存在するフォルダパスを入力します。(Enter のみで中止。ファイルサイズと保存先はデフォルト値)> ")
    if folder == "":
        Common.stop("処理を中止しました。")
else:
    folder = Common.args(0)
    if Common.count_args() >= 2:
        SIZE = int(Common.args(1))
    if Common.count_args() >= 3:
        SAVEPATH = Common.args(2)

# 指定されたフォルダ内の画像ファイル一覧を得る。
files = fs.listFiles(folder)

a = Common.readline(
    f"{len(files)} 個のファイルを {SIZE} x {SIZE} 以内に縮小して {SAVEPATH} に保存します。(y/n)")
if a != 'y':
    Common.stop(9, "処理を中断しました。")

if not fs.exists(SAVEPATH):
    fs.mkdir(SAVEPATH)
Esempio n. 3
0
    return lastId


# Pictures or Videos or Album テーブルを更新する。
def updateTable(tableName, bid, pid):
    sql = UPDATE.format(tableName, bid, pid)
    mysql_client.execute(sql)
    return


#  Start up
# パラメータ確認・取得
if Common.count_args() == 0:
    filePath = Common.readline("画像ファイルのパスを入力します。> ")
else:
    filePath = Common.args(0)

if Common.count_args() == 1:
    pid = Common.readline("Pictures テーブルの対象 id を入力します。> ")
else:
    pid = Common.args(1)

if Common.count_args() == 2:
    tableName = "Pictures"
else:
    if Common.args(2) == "V":
        tableName = "Videos"
    elif Common.args(2) == 'P':
        tableName = "Pictures"
    elif Common.args(2) == 'A':
        tableName = "Album"
Esempio n. 4
0
    fix = args[2]
    cols = args[3]
    i = 1
    files = fs.listFiles(dir, wild)
    sortedFiles = sorted(files)
    for fold in sortedFiles:
        ext = fs.getExtension(fold)
        fmt = "{0:0" + cols + "d}"
        fnew = dir + "/" + fix + Text.format(fmt, i) + ext
        cmd = f"mv -v {fold} {fnew}"
        print(cmd)
        i += 1


# メインプログラム
EXPLAIN = '''#    RenameNumber.py
ディレクトリ内のファイル名を連続番号のあるファイル名にする。
  パラメータ
    ディレクトリ(最後の/は付けない)
    ファイルのワイルドカード(すべての場合は'*.*'。必ず引用符で囲むこと。)
    ファイル名の固定部分(英字のみ)
    数字部分の桁数
'''

if Common.count_args() < 3:
    Common.stop(9, EXPLAIN, Common.ESC_NORMAL)

renameAll(Common.args())

print("正常終了。")
Esempio n. 5
0
#!/usr/bin/env python3

# ディレクトリの名前が [.+] で始まっていたら、その文字列を削除した名前にする。

from Py365Lib import Common, FileSystem as fs, Text


# START
# パラメータ確認
if Common.count_args() < 1 :
  Common.stop("Usage : remove_paren.py directory")

parent = Common.args(0)
print("cd " + parent)
dirs = fs.listDirectories(parent, True)

for d in dirs :
  parts = Text.split("/", d)
  oldname = parts[len(parts)-1]
  if Text.re_contain(r"^\[.+\].+", oldname) :
    d2 = Text.re_replace(r"\[.+\]\s", "", d)
    d2 = Text.trim(d2)
    parts = Text.split("/", d2)
    newname = parts[len(parts)-1]
    print("ren \"{0}\" \"{1}\"".format(oldname, newname))

print("echo Done.")

Esempio n. 6
0
'''
{
  "album":165
  "media":"HD-LLU3",
  "series":"アニソン",
  "mark":"アニメ",
  "info":""
}
'''
from Py365Lib import Common, FileSystem as fs, MySQL

# START
# パラメータ確認
if Common.count_args() < 1 :
  Common.stop("Usage : Ins_VideosSQL.py filelist [json]")
filelist = Common.args(0)
album = 0
media = "media"
series = "series"
mark = "mark"
info = "info"
if Common.count_args() >= 2 :
  json = fs.readJson(Common.args(1))
  album = json["album"]
  media = json["media"]
  series = json["series"]
  mark = json["mark"]
  info = json["info"]
else :
  pass
Esempio n. 7
0
#!/usr/bin/env python3
#  再帰的に中間ファイルを削除する。
from Py365Lib import Common, FileSystem as fs
import os

# 中間ファイルの拡張子
iexts = (".obj", ".res", ".resw", ".pdb", ".pch", ".rc", ".rc2")

# パラメータを得る。
print("== 再帰的に中間ファイルを削除する。==")
# 対象のフォルダを得る。
if Common.count_args() == 0 :
  Common.stop(9, "フォルダを指定してください。")
folder = Common.args(0)
a = Common.readline(folder + "に対して再帰的に中間ファイルを削除します。よろしいですか? (y/n)")
if a != "y" :
  Common.stop(1, "実行を中止しました。")

# 実行する。
files = fs.listFilesRecursively(folder, asstr=True)
for f in files:
  ext = fs.getExtension(f)
  for e in iexts:
    if ext == e :
      print("削除: " + f)
      os.remove(f)
    else :
      pass
print("終了。")
Esempio n. 8
0
#!/usr/bin/python3
from Py365Lib import Common, Text

# 元号を西暦に変換する。
if Common.count_args() == 0:
    Common.stop(
        9,
        "Enter Japanese Gengo year. like s20, h10 where characters must be 3.",
        Common.ESC_FG_YELLOW)

g = Common.args()[0]

if Text.tolower(g[0]) == 's':
    y0 = 1926
elif Text.tolower(g[0]) == 'h':
    y0 = 1989
else:
    y0 = 1912

gengo = Text.Text(g)

if gengo.length == 3:
    y = int(gengo.right(2))
    x = y + y0 - 1
    print(x)
else:
    Common.stop(1, "Error: Inpur length must be 3.")
Esempio n. 9
0
#!/usr/bin/python3
import hashlib
from Py365Lib import Common
#  md5 の計算

print("md5 の計算")
if Common.count_args() == 0:
    instr = Common.readline('入力 > ')
else:
    instr = Common.args(0)
bstr = instr.encode()
m = hashlib.md5(bstr)
print(m.hexdigest())
Esempio n. 10
0
        lines[0] = "#!" + interpreter + "\n"
        fs.writeLines(fileName, lines)
    else:
        print("Skiped: 行の先頭にインタプリタ指定が見当たりません。" + fileName)
    return


# 条件入力
fileName = ""
interpreterNo = 1
if Common.count_args() < 2:
    fileName = Common.readline("対象のファイル・フォルダを指定してください。> ")
    print(INTERPRETERS)
    interpreterNo = int(Common.readline("番号を選択してください。> "))
else:
    fileName = Common.args(0)
    interpreterNo = int(Common.args(1))

interpreterLines = INTERPRETERS.split('\n')
interpreter = Text.substring(interpreterLines[interpreterNo - 1], 3)
print(interpreter + " が " + fileName + " に適用されます。")
a = Common.readline("実行しますか? (y/n)")
if a != 'y':
    Common.stop(9, "実行が取り消されました。")

# インタプリタ適用
if fs.isFile(fileName):
    apply(fileName, interpreter)
else:
    files = fs.listFiles2(fileName)
    for f in files:
Esempio n. 11
0
    return buff


# バイナリーファイル filePath をテーブル BINDATA に挿入する。
def insertBinaries(filePath):
    ext = fs.getExtension(filePath)
    size = fs.getFileSize(filePath)
    name = fs.getFileName(filePath)
    filePath = filePath.replace("\\", "/")
    hexa = bin2hex(filePath)
    sn = mysql_client.getValue("SELECT max(sn) FROM BINDATA") + 1
    sql = Text.format(INSERT, name, filePath, ext, hexa, size, sn)
    mysql_client.execute(sql)
    lastId = mysql_client.getValue("SELECT max(id) FROM BINDATA")
    return lastId


#  Start up
# パラメータ確認・取得
if Common.count_args() == 0:
    filePath = Common.readline("サムネール画像ファイルのパスを入力します。> ")
else:
    filePath = Common.args(0)

# MySQL クライアントを構築
mysql_client = MySQL.MySQL()
# データ挿入
last = insertBinaries(filePath)

print(f"BINDATA テーブルの id = {last} に挿入しました。")
Esempio n. 12
0
#!/usr/bin/env python3
#  指定した m3u ファイルの項目(音楽ファイル) の行を入れ替えてランダム再生できるようにする。
from Py365Lib import Common, FileSystem as fs
import re
import random

if Common.count_args() == 0:
    Common.stop(9, "m3u ファイル(UTF-8)を指定してください。")

m3u = Common.args(0)
new_m3u = m3u
if Common.count_args() >= 2:
    new_m3u = Common.args(1)

# ファイルを読む。
lines = fs.readLines(m3u)

# 乱数の配列を作る。
randarr = []
m = len(lines)
for i in range(m):
    n = int(random.uniform(0, 9999) + 0.5)
    randarr.append(n)

# 乱数:ファイル名の辞書を作る。
dictrand = dict()
for i in range(m):
    dictrand[randarr[i]] = lines[i]

# dictrandをキーでソートする。
arrnew = sorted(dictrand.items())
Esempio n. 13
0
#!/usr/bin/python3

#  Pictures テーブルの date 列を更新する。(最新の画像ファイルの日付にする)
#  パラメータ Pictures テーブルの id または id の範囲
from Py365Lib import Common, FileSystem as fs, MySQL
import os

mysql = MySQL.MySQL()

if Common.count_args() == 0:
    Common.stop(9, "id と日付 yyyy-mm-dd を指定してください。")
else:
    pass

id = Common.args(0)
newdate = Common.args(1)

sql = f"UPDATE Pictures SET `date`='{newdate}' WHERE id={id}"
print(sql)

mysql.execute(sql)

print("Done.")
Esempio n. 14
0
  print(date0)

  # Pictures テーブルの当該レコードの日付(date)を更新する。
  sql = f"UPDATE Pictures SET `date`='{date0}' WHERE id={id}"
  print(sql)
  mysql.execute(sql)
  return

#  Main
# Pictures id をパラメータで指定する。
if Common.count_args() == 0 :
  Common.stop(9, "Usage: update_pictures_date.py <id of Pictures>")
else :
  pass

id0 = int(Common.args(0))
id1 = -1
if Common.count_args() > 1 :
  id1 = int(Common.args(1))
print("id0 = ", id0)
print("id1 = ", id1)

# 指定された id のレコードの日付を更新する。
if id0 > id1 :
  updateDate(mysql, id0)
else :
  for i in range(id0, id1) :
    updateDate(mysql, i)

print("Done.")
Esempio n. 15
0
#!/usr/bin/env python3

#  ファイル一覧を PictureAlbum テーブルへインポートでする。
from Py365Lib import Common, FileSystem as fs, MySQL

# START
# パラメータ確認
if Common.count_args() < 2:
    Common.stop("Usage : ins_flist.py filelist album_no")
filelist = Common.args(0)
album_no = Common.args(1)
# MySQL に接続
mysql = MySQL.MySQL()
#  ファイルリストを読む。
lines = fs.readLines(filelist)
for path in lines:
    path = path.strip().replace("'", "''")
    parts = path.split("/")
    n = len(parts)
    if n > 3:
        title = parts[n - 2]
        creator = parts[n - 3]
    else:
        title = "title"
        creator = "creator"
    sql = f"INSERT INTO PictureAlbum VALUES(NULL,{album_no},'{title}','{path}','{creator}','',0,0)"
    print(sql)
    mysql.execute(sql)
print("Done.")
Esempio n. 16
0
#!/usr/bin/python3
#  指定された id の Pictures テーブルのデータの BINDATA フィールドの値を BINDATA テーブルの録された項目の id で置き換える。
from Py365Lib import MySQL, Common

if Common.count_args() == 0:
    print("Usage: update_pictures_bindata.py Pictures_id")
    Common.stop(1)
id = Common.args(0)
mysql = MySQL.MySQL()
bindata = mysql.getValue("SELECT max(id) FROM BINDATA")
sql = f"UPDATE Pictures SET bindata={bindata} WHERE id={id}"
mysql.execute(sql)
print("Done.")
Esempio n. 17
0
#!/usr/bin/python3
# 元号の生年から年齢を求める。
from Py365Lib import Common

if Common.count_args() == 0:
    Common.stop(9, "Enter birth_year(Showa)", Common.ESC_FG_YELLOW)

showa = int(Common.args()[0])
AGE0 = 92
age = AGE0 - showa + 1
print("s{0}".format(age))
Esempio n. 18
0
#!/usr/bin/python3
# 西暦を元号に変換する。
from Py365Lib import Common

if Common.count_args() == 0:
    Common.stop(9, "Enter year. (yyyy)", Common.ESC_FG_YELLOW)

y = int(Common.args()[0])

if y >= 1926 and y < 1989:
    g = "s"
    x = y - 1926 + 1
else:
    g = "h"
    x = y - 1989 + 1

print("{0}{1}".format(g, x))
Esempio n. 19
0
def bin2hex(filePath):
    buff = "0x"
    b = fs.readBinary(filePath)
    buff += b.hex()
    return buff


# バイナリーファイル filePath の中身でテーブル BINDATA の id の画像データを更新する。
def updateBinaries(filePath, id):
    filePath = filePath.replace("\\", "/")
    hexa = bin2hex(filePath)
    sql = Text.format(UPDATE, hexa, id)
    mysql_client.execute(sql)
    return


#  Start up
# パラメータ確認・取得
if Common.count_args() < 2:
    Common.stop(1, "サムネール画像ファイルのパスと id を入力します。")
else:
    filePath = Common.args(0)
    id = Common.args(1)

# MySQL クライアントを構築
mysql_client = MySQL.MySQL()
# データ更新
updateBinaries(filePath, id)

print(f"BINDATA テーブルの id = {id} の画像データを更新しました。")
Esempio n. 20
0
#!/usr/bin/env python3

# サブディレクトリ内にあるファイルを自ディレクトリに名前を変えてコピーする。
from Py365Lib import Common, FileSystem as fs, Text

# START
# パラメータ確認
if Common.count_args() < 1:
    Common.stop("Usage : copy_subdir_files.py directory")
mydir = Common.args(0)

# サブディレクトリ一覧を得る。
dirs = fs.listDirectories(mydir, True)

# サブディレクトリごとに繰り返す。
for d in dirs:
    print(d)
    files = fs.listFiles(d, "*", True)
    parts = Text.split("/", d)
    h = parts[len(parts) - 1]
    for f in files:
        f1 = Text.replace("/", "\\", mydir + "/" + h + "/" + fs.getFileName(f))
        f2 = Text.replace("/", "\\", mydir + "/" + h + fs.getFileName(f))
        print(f"copy \"{f1}\" \"{f2}\"")

# 終わり
print("Done.")
Esempio n. 21
0
          app.message = data;
        });
      }
    }
  });
</script>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>
'''

if Common.count_args() == 0:
    filePath = Common.readline('HTMLファイルのパス名を入力してください。')
else:
    filePath = Common.args(0)

if Common.count_args() < 2:
    print("1: HTML5 のシンプルなページ")
    print("2: HTML5 のシンプルなページ + jQuery + Highlight.js")
    print("3: Bootstrap4 のページ")
    print("4: Bootstrap4 のページ + Highlight.js ")
    print("5: Vue.js のページ")
    pagen = int(Common.readline("番号入力 > "))
else:
    pagen = int(Common.args(1))

if pagen < 1 or pagen > 4:
    Common.stop(9, "番号が不正です。")

# "~" をホームディレクトリに変換する。
Esempio n. 22
0
            dirs1 = fs.listDirectories(dir1)
            for dp in dirs1 :
                nd = rename(dp)
                dp = "'" + dp + "'"
                nd = "'" + nd + "'"
                if dp != nd :
                    lines += f"mv -v {dp} {nd}\n"
                    count += 1
    return lines

# 対象のディレクトリを得る。
if Common.count_args() < 2 :
    Common.stop(9, "対象のディレクトリとスクリプトファイルの保存先(パス)を指定してください。")

# 対象のディレクトリ
dir0 = Common.args()[0]
if not fs.isDirectory(dir0) :
    Common.stop(9, f"{dir0} はディレクトリとして存在しません。")

# スクリプトファイルのパス
savePath = Common.args()[1]


# ディレクトリの名前変更コマンドを作成する。
lines = renameDirs(dir0)

# スクリプトを作成する。
try :
    fs.writeAllText(savePath, lines)
    print(f"\n終わり。{savePath} が作成されました。")
except Exception as e :
Esempio n. 23
0
      insertData(dir, creator)
    else :
      for subdir in subdirs :
        insertData(subdir, creator)
  return



# データをMySQLに挿入する。
def insertData(dir, creator) :
  global mark
  global cmd
  parts = Text.split('/', dir)
  title = parts[len(parts) - 1]
  cmd = f"INSERT INTO Pictures(TITLE, CREATOR, `PATH`, MARK) VALUES('{title}', '{creator}', '{dir}', '{mark}');"
  print(cmd)
  return


## プログラム開始
if Common.count_args() == 0 :
  Common.stop(1, "親ディレクトリを指定してください。", Common.ESC_FG_YELLOW)

cmd = ""
mark = 'NONE'

parentDir = Common.args()[0]
if Common.count_args() > 1 :
  mark = Common.args()[1]
insertFolders(parentDir)
Esempio n. 24
0
#!/usr/bin/env python3

#  YJFX_Asset テーブルにデータを挿入する。
from Py365Lib import Common, MySQL

# パラメータ確認
if Common.count_args() < 3:
    Common.stop(9, "Usage: InsAsset.py date asset loss", Common.ESC_FG_YELLOW)

date = Common.args(0)
asset = Common.args(1)
loss = Common.args(2)

sql = f"INSERT INTO YJFX_Asset VALUES(null, '{date}', {asset}, {loss}, '')"

mysql = MySQL.MySQL()
mysql.execute(sql)

sql = "SELECT * FROM VW_YJFX_Asset"
result = mysql.query(sql)

for row in result:
    print(row)

print("Done.")
Esempio n. 25
0
#!/usr/bin/env python3
#  tail filePath [lines]
from Py365Lib import Common, FileSystem as fs
from collections import deque

if Common.count_args() < 1:
    Common.stop(9, "Usage: tail filePath [lines] [encoding]")

filePath = Common.args(0)

if Common.count_args() > 1:
    n = int(Common.args(1))
else:
    n = 20

if Common.count_args() > 2:
    code = Common.args(2)
else:
    code = "utf-8"

fifo = deque(maxlen=n)
with open(filePath, mode="r", encoding=code) as f:
    line = f.readline()
    while line:
        fifo.append(line)
        line = f.readline()

while True:
    if len(fifo) > 0:
        l = fifo.popleft()
        print(l, end="")