Beispiel #1
0
def insertBinaries(filePath):
    INSERT = "INSERT INTO BINDATA(`title`, `original`, `datatype`, `data`, `info`, `size`) VALUES('{0}', '{1}', '{2}', {3}, '', {4})"
    ext = fs.getExtension(filePath)
    size = fs.getFileSize(filePath)
    fileName = fs.getFileName(filePath)
    filePath = filePath.replace("\\", "/")
    filePath = filePath.replace("'", "''")
    hexa = bin2hex(filePath)
    sql = Text.format(INSERT, fileName, filePath, ext, hexa, size)
    client = MySQL.MySQL()
    client.execute(sql)
    return
Beispiel #2
0
def api_quick_age(convert, year) :
  mysql = MySQL.MySQL()
  if convert == "age" :
    # 年齢から誕生年
    rows = mysql.query("SELECT year, gengo FROM QuickAge WHERE age = {0}".format(year))
    if len(rows) == 0 :
      result = "エラー: 年齢が不正"
    else :
      row = rows[0]
      result = str(row[0]) + "," + row[1]
  elif convert == "born" :
    # 誕生年から年齢
    if Text.isdigit(year) :
      # age は西暦
      rows = mysql.query("SELECT age FROM QuickAge WHERE year={0}".format(year))
      if len(rows) == 0 :
        result = "エラー: 西暦が不正"
      else :
        result = rows[0]
    else :
      # year は和暦
      if year.startswith('T') :
        year = "大正" + Text.substring(year, 1) + "年";
      elif year.startswith('S') :
        if Text.substring(year, 1) == '1' :
          year = "昭和元年";
        else :
          year = "昭和" + Text.substring(year, 1) + "年";
      elif year.startswith('H') :
        if Text.substring(year, 1) == '1' :
          year = "平成元年";
        else :
          year = "平成" + Text.substring(year, 1) + "年";
      elif year.startswith('R') :
        if Text.substring(year, 1) == '1' :
          year = "令和元年"
        else :
          year = "令和" + Text.substring(year, 1) + "年";
      else :
        result = "エラー: 和暦文字が不正"
        return result
      print(year)
      rows = mysql.query("SELECT age FROM QuickAge WHERE gengo='{0}'".format(year))
      if len(rows) == 0 :
        result = "エラー: 和暦が不正"
      else :
        result = rows[0]     
  else :
    # エラー
    result = "エラー: 不正な変換"
  return result
Beispiel #3
0
def api_video_modify(data) :
  result = "Error"
  mysql = MySQL.MySQL()
  if "id" in data.keys() :
    print("api newstring = " + str(data['newstring']))
    sql = "CALL VideoSetTitle({0}, '{1}')".format(data['id'], data['newstring'])
    mysql.execute(sql)
    result = "OK"
  elif "oldstring" in data.keys() :
    sql = "CALL VideoModifyTitle('{0}', '{1}')".format(data['oldstring'], data['newstring'])
    mysql.execute(sql)
    result = "OK"
  else :
    pass
  return result
Beispiel #4
0
def api_bindata_extract(id) :
  mysql = MySQL.MySQL()
  sql = f"SELECT datatype, hex(data) as hex FROM BINDATA WHERE id={id}"
  rows = mysql.query(sql)
  row = rows[0]
  datatype = row[0]
  data = row[1]
  if datatype == ".jpg" :
    mime = b"image/jpeg"
  elif datatype == ".png" :
    mime = b"image/png"
  elif datatype == ".gif" :
    mime = b"image/gif"
  else :
    return None
  imgbinary = hex2bin(data)
  response = make_response(imgbinary)
  response.headers.set('Content-Type', mime)
  return response
Beispiel #5
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
Beispiel #6
0
def doChangeCreator():
    sql = Text.format(
        "SELECT id, creator, path FROM Pictures WHERE id BETWEEN {0} AND {1}",
        id_start, id_end)
    Common.esc_print("cyan", sql)
    UPDATE = "UPDATE Pictures SET creator='{0}' WHERE id={1}"
    client = mysql.MySQL()
    rows = client.query(sql)
    for row in rows:
        id = row[0]
        creator = row[1]
        path = row[2]
        if creator == "作者":
            ppath = Text.split('/', path)
            lenpath = len(ppath)
            new_creator = ppath[lenpath - 2]
            sql = Text.format(UPDATE, new_creator, id)
            print(sql)
            client.execute(sql)
            print(sql)
        else:
            pass
    return
Beispiel #7
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.")
Beispiel #8
0
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.")
Beispiel #9
0
def api_videos() :
  mysql = MySQL.MySQL()
  sql = "SELECT * FROM Videos"
  rows = mysql.query(sql)
  return rows
Beispiel #10
0
def api_pictures_view(view) :
  mysql = MySQL.MySQL()
  rows = mysql.query("SELECT * FROM {0} ORDER BY id".format(view))
  return rows
Beispiel #11
0
  ret = False
  if Common.is_windows() :
    ret = path.endswith(".exe") or path.endswith(".bat") or or path.endswith(".ps1") or or path.endswith(".vbs")
  else :
    stinfo = os.stat(path)
    ret = stinfo.st_mode & S_IXUSR
  return ret

# path を テーブル Apps に挿入する。
def insertToApps(path) :
  title = fs.getFileName(path)
  platform = "linux"
  if Common.is_windows() :
    platform = "windows"
  sql = f"INSERT INTO Apps VALUES(NULL, '{title}', '{path}', '', '{platform}', '', '', CURRENT_DATE())"
  mysql.execute(sql)
  return

# START Program
settings = fs.readJson(fs.getCurrentDirectory() + '/InsApps.json')
binfolder = settings["binfolder"]

mysql = my.MySQL()

files = fs.listFiles2(binfolder)
for f in files :
  if isExecutable(f) :
    print(f)
    insertToApps(f)

print("終わり。")