[PYTHON] [To Twitter gentlemen] I wrote a script to convert .jpg-large to .jpg at once.

What is? Omission

I know you're collecting ero images on Twitter ... And I also know that I manually convert .jpg-large to .jpg and save it ... (I'm sorry if I didn't).

That's it! To you !! Good news !!!

Let's convert the file names of sublime erotic images at once with this script !!!!!

Download it here

https://github.com/ykaito39/useful-script-for-photo/tree/master/rename_jpg-XXX_to_jpg

How to use

$python rename_jpg-XXX_to_jpg.py

Basically, you can execute it by copying it to the directory where .jpg-large is located and executing it by double-clicking.

Contents commentary

It's a very simple script, and it's the first script I made that I can use properly. I made it about 2 years ago, but I can use it in active duty.

Magic

# coding: UTF-8
import sys
import os

Target path specification

if len(sys.argv) == 2:
    DIR == sys.argv[1]
else:
    DIR = './'

Actually, I wrote it separately for each OS, but in the end I thought that it would be the most intuitive and easy to understand if I copied it directly under the download and executed it.

Body

#Get a list of files in a directory
#If the DIR is invalid, end here
try:
    file_list = os.listdir(DIR)
except os.error:
    exit(-1)

for file in file_list:
    print(file)
    if file[-6:] == '_large':
        #Get the full path to change
        full_path = os.path.join(DIR, file)

        #From the file name to the end_Erase large
        replaced_path = file[:-6] + ''
        replaced_full_path = os.path.join(DIR, replaced_path)

        #File name rewriting
        os.rename(full_path, replaced_full_path)
        print('[REPLACE]  ' + file + ' >> ' + replaced_path)

If you get the list of contents of the directory and the file name has -large at the end of the list slice, it is just deleted. Exception handling is also appropriate, and I'm sorry it's not a big deal.

Development environment

Python3.6 Windows10 pro x64 1903

contact information

@ykaito39

Thanks Thanks for watching...

Recommended Posts

[To Twitter gentlemen] I wrote a script to convert .jpg-large to .jpg at once.
I wrote a script to upload a WordPress plugin
I wrote a script to get a popular site in Japan
I wrote a script to combine the divided ts files
I made a script to say hello at my Koshien
I wrote a script to create a Twitter Bot development environment quickly with AWS Lambda + Python 2.7
I wrote a script to get you started with AtCoder fast!
I just wrote a script to build Android on another machine
I wrote a function to load a Git extension script in Python
I wrote a script to extract a web page link in Python
I wrote a script to help goodnotes5 and Anki work together
I tried to make a script that traces the tweets of a specific user on Twitter and saves the posted image at once
Convert memo at once with Python 2to3
I made a script to display emoji
I wrote a code to convert quaternions to z-y-x Euler angles in Python
I made a script in python to convert .md files to Scrapbox format
Get a lot of Twitter tweets at once
I wrote a script to revive the gulp watch that will die soon
Write a script to convert a MySQL dump to TSV
Beginners try to convert Word files to PDF at once
I made a script to put a snippet in README.md
I made a code to convert illustration2vec to keras model
A story that I was addicted to at np.where
I made a script in Python to convert a text file for JSON (for vscode user snippet)
I made a tool to get the answer links of OpenAI Gym all at once
A Python script that goes from Google search to saving the Search results page at once
I wrote a program quickly to study DI with Python ①
Convert the image data (png) at hand to a .pbm image
I wrote a script that splits the image in two
I tried to convert a Python file to EXE (Recursion error supported)
I wanted to convert my face photo into a Yuyushiki style.
numpy: I want to convert a single type ndarray to a structured array
I want to backtest a large number of exchange pairs and strategies at once with Python's backtesting.py