python 用于生成车库的唯一编号的脚本,用于文本广告系列。一个脚本用于创建XLS文件,另一个脚本用于单独创建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 用于生成车库的唯一编号的脚本,用于文本广告系列。一个脚本用于创建XLS文件,另一个脚本用于单独创建相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env python
"""
Generates URN/codes and saves them to a single Excel file with each depot on a separate sheet.

URN Format: (\d{3})([A-Z])(\d{3})
Group 1: Random capital letter A-Z (technically unecessary)
Group 2: Depot number 01-67
Group 3: Sequence number 001-250 (never repeats)
"""

import xlsxwriter
import random
import string
import argparse

def main(sheetnum=10, urnnum=250):
    filename = "depot_codes.xls"
    workbook = xlsxwriter.Workbook(filename)
    for depot in range(1, sheetnum+1):
        worksheet = workbook.add_worksheet()
        for code in range(1, urnnum+1):
            urn = "%02d%s%03d" % (depot, random.choice(string.ascii_uppercase), code)
            worksheet.write(code-1, 0, urn)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(
        description="Generates Excel file containing unique codes for a set number of depots with each depot's codes on a separate line"
    )
    parser.add_argument('depots', type=int, help="Number of depots from 0-99 (separate sheet in file created for each)")
    parser.add_argument('codes', type=int, help="Number of codes per depot")

    args = parser.parse_args()
    main(args.depots, args.codes)
#!/usr/bin/env python
"""
Generates URN/codes and saves them to separate CSV files - 1 for each depot.

URN Format: (\d{3})([A-Z])(\d{3})
Group 1: Random capital letter A-Z (technically unecessary)
Group 2: Depot number 01-67
Group 3: Sequence number 001-250 (never repeats)
"""

import csv
import random
import string
import argparse

def main(csvnum=10, urnnum=250):
    for depot in range(1, csvnum+1):
        filename = "depot-%d.csv" % depot
        with open(filename, 'wb') as f:
            fw = csv.writer(f, dialect='excel')
            for code in range(1, urnnum+1):
                urn = "%02d%s%03d" % (depot, random.choice(string.ascii_uppercase), code)
                fw.writerow([urn])

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description="Generates separate CSV files containing unique codes for a set number of depots")
    parser.add_argument('depots', type=int, help="Number of depots from 0-99 (separate CSV file created for each)")
    parser.add_argument('codes', type=int, help="Number of codes per depot")

    args = parser.parse_args()
    main(args.depots, args.codes)

以上是关于python 用于生成车库的唯一编号的脚本,用于文本广告系列。一个脚本用于创建XLS文件,另一个脚本用于单独创建的主要内容,如果未能解决你的问题,请参考以下文章

php如何生成订单号

PHP生成唯一会员卡号

生成订单编号 用java怎么处理

C#获取windows下用于标志当前电脑的唯一性编号

C#获取windows下用于标志当前电脑的唯一性编号

如何使用redis生成唯一编号及原理