Skip to content

Instantly share code, notes, and snippets.

@zhongql
Last active November 24, 2020 06:00
Show Gist options
  • Select an option

  • Save zhongql/863097e57a813db2dd368c4b1c5deaba to your computer and use it in GitHub Desktop.

Select an option

Save zhongql/863097e57a813db2dd368c4b1c5deaba to your computer and use it in GitHub Desktop.

Revisions

  1. zhongql revised this gist Nov 24, 2020. 1 changed file with 56 additions and 13 deletions.
    69 changes: 56 additions & 13 deletions film_clean.py
    Original file line number Diff line number Diff line change
    @@ -41,6 +41,13 @@ def calculate(params, tm):
    ex_stack.append(p)
    continue

    if (p is '.'):
    # 不符合规则
    if not (mutil and len(mutil) > 1):
    return ''
    mutil.append(p)
    continue

    if (p is ','):
    # 不符合规则
    if not (tmp and len(tmp) > 1):
    @@ -50,7 +57,9 @@ def calculate(params, tm):
    if (not num.isdigit()):
    return ''
    ex = ''.join(tmp[1:])
    rs = multi_num(ex, int(num))
    rs = multi_num(ex, num)
    if not rs:
    return ''
    tmp = []
    ex_stack.append(rs)
    continue
    @@ -64,7 +73,9 @@ def calculate(params, tm):
    if (not num.isdigit()):
    return ''
    ex = ''.join(tmp[1:])
    rs = multi_num(ex, int(num))
    rs = multi_num(ex, num)
    if not rs:
    return ''
    tmp = []
    ex_stack.append(rs)
    if (ex_stack):
    @@ -77,22 +88,25 @@ def calculate(params, tm):
    ex_tmp.insert(0, last)
    rs = add_num(ex_tmp)
    ex_stack.append(rs)

    # 不符合规则
    if not (mutil and len(mutil) > 1):
    return ''

    ex = mutil[0]
    # 必须是60秒
    if (len(ex.replace(',', '').replace('-', '')) != 60):
    return ''

    num = ''.join(mutil[1:])
    # 不符合规则
    if (not num.isdigit()):
    rs = multi_num(ex, num)
    if not rs:
    return ''
    rs = multi_num(ex, int(num))
    ex_stack.append(rs)

    # 表达式的全部的元素
    seri = add_num(ex_stack)
    seri = seri.replace(',', '')
    seri = seri.split(',')

    # 时间换算
    tl = tm.split(':')
    @@ -108,22 +122,51 @@ def calculate(params, tm):
    return ''
    total += int(sec)

    return seri[0:total]
    return ','.join(seri[0:total])

    def multi_num(ex, num_str):
    ex = ex.split(',')
    nums = num_str.split('.')
    min = 0
    sec = 0
    # 不符合规则
    if (len(nums) > 2):
    return ''

    if (len(nums) == 1):
    min = nums[0]
    if (not min.isdigit()):
    return ''
    min = int(min)

    if (len(nums) == 2):
    min = nums[0]
    sec = nums[1]
    if (not (sec.isdigit() and min.isdigit())):
    return ''
    min = int(min)
    sec = int(sec[0])

    def multi_num(ex, num):
    rs = []
    for i in range(num):
    rs.append(str(ex))
    if (min):
    for i in range(min):
    rs.append(','.join(ex))

    if (sec):
    num_len = sec * 6
    if (len(ex) < num_len):
    return ''
    rs.append(','.join(ex[:num_len]))

    return ','.join(rs)

    def add_num(ex_stack):
    return ','.join(ex_stack)


    if __name__ == "__main__":
    params = sys.argv[1]
    tm = sys.argv[2]
    print('start !!!')
    params = params.replace(' ', '').replace('(', '(').replace(',', ',').replace(')', ')')
    tm = tm.replace(' ', '').replace(':', ':')
    rs = calculate(params, tm)
    print(rs)
  2. zhongql revised this gist Nov 23, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion film_clean.py
    Original file line number Diff line number Diff line change
    @@ -73,7 +73,7 @@ def calculate(params, tm):
    last = ex_stack.pop()
    if last is '(':
    break
    elif last is not '(':
    else:
    ex_tmp.insert(0, last)
    rs = add_num(ex_tmp)
    ex_stack.append(rs)
  3. zhongql revised this gist Nov 14, 2020. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions film_clean.py
    Original file line number Diff line number Diff line change
    @@ -123,7 +123,7 @@ def add_num(ex_stack):
    params = sys.argv[1]
    tm = sys.argv[2]
    print('start !!!')
    print(params)
    print(tm)
    params = params.replace(' ', '').replace('(', '(').replace(',', ',').replace(')', ')')
    tm = tm.replace(' ', '').replace(':', ':')
    rs = calculate(params, tm)
    print(rs)
  4. zhongql renamed this gist Nov 14, 2020. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  5. zhongql created this gist Nov 14, 2020.
    129 changes: 129 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,129 @@
    import sys

    def calculate(params, tm):
    ex_stack = []
    tmp = []
    mutil = []
    for p in params:
    if (not p):
    continue

    if (p is '('):
    ex_stack.append(p)
    continue

    if (p is '='):
    # 不符合规则
    if (not ex_stack):
    return ''
    num_tmp = []
    for i in range(len(ex_stack)):
    last = ex_stack[-1]
    if (last.isdigit()):
    num_tmp.insert(0, ex_stack.pop())
    str = ''.join(num_tmp)
    tmp.append(str)
    continue

    if (p is '*' or p is 'x'):
    # 不符合规则
    if (not ex_stack):
    return ''
    mutil.append(ex_stack.pop())
    continue

    if (p.isdigit() or p is '-'):
    if (tmp):
    tmp.append(p)
    elif (mutil):
    mutil.append(p)
    else:
    ex_stack.append(p)
    continue

    if (p is ','):
    # 不符合规则
    if not (tmp and len(tmp) > 1):
    return ''
    num = tmp[0]
    # 不符合规则
    if (not num.isdigit()):
    return ''
    ex = ''.join(tmp[1:])
    rs = multi_num(ex, int(num))
    tmp = []
    ex_stack.append(rs)
    continue

    if (p is ')'):
    # 不符合规则
    if not (tmp and len(tmp) > 1):
    return ''
    num = tmp[0]
    # 不符合规则
    if (not num.isdigit()):
    return ''
    ex = ''.join(tmp[1:])
    rs = multi_num(ex, int(num))
    tmp = []
    ex_stack.append(rs)
    if (ex_stack):
    ex_tmp = []
    for i in range(len(ex_stack)):
    last = ex_stack.pop()
    if last is '(':
    break
    elif last is not '(':
    ex_tmp.insert(0, last)
    rs = add_num(ex_tmp)
    ex_stack.append(rs)

    # 不符合规则
    if not (mutil and len(mutil) > 1):
    return ''

    ex = mutil[0]
    num = ''.join(mutil[1:])
    # 不符合规则
    if (not num.isdigit()):
    return ''
    rs = multi_num(ex, int(num))
    ex_stack.append(rs)

    # 表达式的全部的元素
    seri = add_num(ex_stack)
    seri = seri.replace(',', '')

    # 时间换算
    tl = tm.split(':')
    min = tl[0]
    # 不符合规则
    if (not min.isdigit()):
    return ''
    total = int(min) * 60
    if(len(tl) == 2):
    sec = tl[1]
    # 不符合规则
    if (not sec.isdigit()):
    return ''
    total += int(sec)

    return seri[0:total]

    def multi_num(ex, num):
    rs = []
    for i in range(num):
    rs.append(str(ex))
    return ','.join(rs)

    def add_num(ex_stack):
    return ','.join(ex_stack)

    if __name__ == "__main__":
    params = sys.argv[1]
    tm = sys.argv[2]
    print('start !!!')
    print(params)
    print(tm)
    rs = calculate(params, tm)
    print(rs)