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 = 1600
#SIZE = 1920
#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, "処理を中断しました。")
Esempio n. 3
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. 4
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. 5
0
    # 1件もない場合はサブディレクトリを見てみる。
    if count == 0 :
        for dir1 in dirs :
            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 :
Esempio n. 6
0
#  json ファイルの例
'''
{
  "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
# 元号の生年から年齢を求める。
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. 10
0
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:
        print(f)
        ext = fs.getExtension(f)
        if ext == ".cgi":
            apply(f, interpreter)
        else:
            print("Skipped")
        # end if
    # end for
Esempio n. 11
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. 12
0
                        sf = "r" + Text.substring(ff[1], 2)
                        newname = folder + "/" + ff[0] + "_" + sf
                        fs.move(fpath, newname)
                        print("Renamed: " + newname)
                    else:
                        # 連続番号が3桁かつ300番台以上の場合はサポートしない(スキップする)
                        pass
                else:
                    # 連続番号が2桁の場合
                    #print("Passed: " + fpath)
                    pass
        else:
            #fs.move(fpath, fpath + ".jpg")
            print("Non image passed: " + fpath)
    return


#  スタート
if Common.count_args() == 0:
    folder = Common.readline("対象の画像フォルダを入力します。")
else:
    folder = Common.args(0)

if not fs.isDirectory(folder):
    Common.stop(1, folder + " は正しいディレクトリではありません。")

# 指定されたフォルダの画像ファイルを同じ長さにリネームする。
rename_files(folder)

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

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

# START
# パラメータ確認
if Common.count_args() < 2:
    Common.stop("Usage : ins_videos.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("'", "''").replace('\\', '/')
    parts = path.split("/")
    n = len(parts)
    if n > 3:
        title = parts[n - 2]
    else:
        title = "title"
    sql = f"INSERT INTO Videos VALUES(NULL,{album_no},'{title}','{path}','medias','series', 'mark', 'info', 0, 0, 0, NULL)"
    print(sql)
    mysql.execute(sql)
print("Done.")
Esempio n. 14
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. 15
0
    time1 = fs.getLastWrite(path + "/" + f.decode('utf-8'))
    if time1 < time0 :
      time0 = time1
  date0 = time0[0:10]
  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) :
Esempio n. 16
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. 17
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. 18
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. 19
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. 20
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, "番号が不正です。")

# "~" をホームディレクトリに変換する。
filePath = fs.tilder(filePath)

if fs.exists(filePath):
    Common.stop(1, filePath + " はすでに存在します。")

with open(filePath, "w", encoding="utf-8") as f:
    if pagen == 1:
        f.write(HTML_Simple)
    elif pagen == 2:
        f.write(HTML_Highlight)
    elif pagen == 3:
        f.write(HTML_Bootstrap4)
    elif pagen == 4:
Esempio n. 21
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. 22
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. 23
0
            sql = Text.format(UPDATE, new_creator, id)
            print(sql)
            client.execute(sql)
            print(sql)
        else:
            pass
    return


#
#  メイン
# ID の範囲を決める。
id_start = 1
id_end = 1000000
id_range = Common.readline("id の範囲 (nnnn-nnnn) を入力してください。(省略時はすべて)")
if id_range == "":
    Common.esc_print("yellow", "すべての id に対して実行します。(y/n)")
    a = Common.readline(">")
    if y != "y":
        Common.stop(9, "実行を中止しました。")
else:
    nn = Text.split('-', id_range)
    if len(nn) == 2:
        id_start = int(nn[0])
        id_end = int(nn[1])
    else:
        Common.stop(9, "範囲が正しくありません。実行を中止しました。")
    # Pictures テーブルからクエリーを行って対象のデータを得る。
    doChangeCreator()
    print("完了")
Esempio n. 24
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="")
Esempio n. 25
0
  n = len(parts)
  if n > 2 :
    title = parts[n-1]
    creator = parts[n-2]
  else :
    title = "title"
    creator = "creator"
  sql = f"INSERT INTO Pictures(TITLE, CREATOR, PATH, MARK, INFO, FAV, COUNT, BINDATA) VALUES('{title}', '{creator}', '{path}', '', '', 0, 0, 0)"
  print(sql)
  mysql.execute(sql)
  return

# START
# パラメータ確認
if Common.count_args() < 1 :
  Common.stop("Usage : InsPictures.py directory")
dir_parent = Common.args(0)
# MySQL に接続
mysql = MySQL.MySQL()
#  画像ファイルを含むサブディレクトリ一覧を得る。
dirlist = fs.listDirectories(dir_parent, True)
for dir in dirlist :
  dirlist2 = fs.listDirectories(dir, True)
  if len(dirlist2) == 0 :
    InsertData(dir)
  else :
    for path in dirlist2 :
      InsertData(path)
print("Done.")
 
Esempio n. 26
0
#!/usr/bin/env python3

# ディレクトリに ^\[.+\]$ が含まれる場合、\[,\] を取る。
# サブディレクトリが ^\[.+\] .+ なら \[.+\] を取る。

from Py365Lib import Common, FileSystem as fs, Text

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

# ディレクトリ一覧を得る。
parent = Common.args(0)
dirs = fs.listDirectories(parent, True)

# ディレクトリ名 [.+] を見つける。
for d in dirs:
    if Text.re_contain(r".+\[.+\]$", d):
        d2 = Text.replace("[", "", d)
        d2 = Text.replace("]", "", d2)
        fs.move(d, d2)
        print(d2)
print("**************")
# サブディレクトリに ^\[.+\] .+ を見つける。
dirs = fs.listDirectories(parent, True)
for d in dirs:
    dirs2 = fs.listDirectories(d, True)
    for d2 in dirs2:
        d3 = Text.re_replace(r"\[.+\]\s+", "", d2)
        fs.move(d2, d3)
Esempio n. 27
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. 28
0
    tableName = "Pictures"
else:
    if Common.args(2) == "V":
        tableName = "Videos"
    elif Common.args(2) == 'P':
        tableName = "Pictures"
    elif Common.args(2) == 'A':
        tableName = "Album"
    elif Common.args(2) == 'M':
        tableName = "Music"
    else:
        tableName = "Pictures"

print("> InsBINDATA3.py " + filePath + ", " + pid + ", " + tableName)
if not fs.exists(filePath):
    Common.stop(9, "画像ファイルが見つかりません。")

# MySQL クライアントを構築
mysql_client = MySQL.MySQL()

# サムネール画像を作成する。
newPath = saveThumb(filePath)

# サムネール画像を BINDATA テーブルに挿入する。
bid = insertBinaries(newPath, filePath)

# Pictures テーブルを更新する。
updateTable(tableName, bid, pid)

# 終わり
print(tableName + " and BINDATA Updated.")