[PYTHON] I made a repeating text data generation tool "rpttxt"

What is rpttxt?

It is distributed here (https://github.com/nendo-code/rpttxt).

For example, suppose you want to create data like this.

output.txt


{
	"id": 1,
	"name": "John",
	"age": 21
}
{
	"id": 2,
	"name": "Paul",
	"age": 35
}
{
	"id": 3,
	"name": "Tom",
	"age": 64
}

What would you do if you created this data? I think it would be like this if I could do it manually.

First, make one item.

step1.txt


{
	"id": 1,
	"name": "John",
	"age": 21
}

Copy and paste as many items as you need.

step2.txt


{
	"id": 1,
	"name": "John",
	"age": 21
}
{
	"id": 1,
	"name": "John",
	"age": 21
}
{
	"id": 1,
	"name": "John",
	"age": 21
}

3. Rewrite the value of each item to the target value.

step3.txt


{
	"id": 1,
	"name": "John",
	"age": 21
}
{
	"id": 2,
	"name": "Paul",
	"age": 35
}
{
	"id": 3,
	"name": "Tom",
	"age": 64
}

You can do it manually like this, but if there are many cases, it is easy to make mistakes. I thought it would be nice if data could be written separately for data and templates for templates. So

Write a template

template.txt


{
	"id": {No},
	"name": "{Name}",
	"age": {Age}
}

Write the data in csv (or export it in csv with Excel etc.)

data.csv


{No},{Name},{Age}
1,John,21
2,Paul,35
3,Tom,64

I created a program that gives the following output when I feed them. That is rpttxt.

output.txt


{
	"id": 1,
	"name": "John",
	"age": 21
}
{
	"id": 2,
	"name": "Paul",
	"age": 35
}
{
	"id": 3,
	"name": "Tom",
	"age": 64
}

Why did you make it?

I felt that there might be a tool similar to the one in the world, but I couldn't find the one with the desired operation feeling, so I reinvented the wheel. Also, I read the book "The idea of UNIX-its design concept and philosophy" and thought it was wonderful, so I made it a command line tool with a simple interface like that.

(Example) Execution on the command line

$ python3 rpttxt.py template.txt data.csv > output.txt

What did you make it?

I wrote it in python3 and made the binary for Windows with PyInstaller. PyInstaller is an easy and very good tool. Also, since it is dull to start the command line on Windows, I also added a batch file to convert in one shot as a bonus.

Recommended Posts

I made a repeating text data generation tool "rpttxt"
I made a python text
I made a browser automatic stamping tool.
I made a useful tool for Digital Ocean
I made a router config collection tool Config Collecor
I made a tool to compile Hy natively
I made a tool to get new articles
〇✕ I made a game
I made a tool to easily display data as a graph by GUI operation.
I made a user management tool for Let's Chat
I made a cleaning tool for Google Container Registry
I made a prime number generation program in Python 2
I made a discord bot
I made a tool to create a word cloud from wikipedia
[I made it with Python] XML data batch output tool
[Titan Craft] I made a tool to summon a giant to Minecraft
I made a C ++ learning site
Can I be a data scientist?
I made a Line-bot using Python!
I made a CUI-based translation script (2)
I made a wikipedia gacha bot
I made a fortune with Python.
I made a client / server CLI tool for WebSocket (like Netcat for WebSocket)
I made a CUI-based translation script
Impressions of touching Dash, a data visualization tool made by python
I made a scaffolding tool for the Python web framework Bottle
I made a daemon with Python
I made a tool to automatically browse multiple sites with Selenium (Python)
[Updated Ver1.3.1] I made a data preprocessing library DataLiner for machine learning.
I made a CLI tool to convert images in each directory to PDF
I made a kind of simple image processing tool in Go language.
I made a tool to convert Jupyter py to ipynb with VS Code
I made a tool that makes decompression a little easier with CLI (Python3)
I made a package like Weblio pop-up English-Japanese dictionary with Sublime Text3
I made a new AWS S3 bucket
I made a payroll program in Python!
I touched "Orator" so I made a note
Beginner: I made a launcher using dictionary
Memo for creating a text formatting tool
I made a conversation partner like Siri
I made a script to display emoji
I made a Hex map with Python
I made a stamp generator with GAN
I touched the data preparation tool Paxata
After studying Python3, I made a Slackbot
I created a password tool in Python.
I made a roguelike game with Python
I made a simple blackjack with Python
I made a configuration file with Python
I made a library for actuarial science
I made a WEB application with Django
I made a neuron simulator with Python
I made a tool to estimate the execution time of cron (+ PyPI debut)
I created a tool to correct GPS data with Mapbox Map Matching API (Mapbox Map Matching API)
I made a tool to notify Slack of Connpass events and made it Terraform
I made a tool to generate Markdown from the exported Scrapbox JSON file
I made a tool to automatically back up the metadata of the Salesforce organization
I made a stamp substitute bot with line
I made a python dictionary file for Neocomplete
I made a competitive programming glossary with Python
I made a weather forecast bot-like with Python.