mirror of
https://github.com/balkian/gists.git
synced 2024-11-24 02:12:29 +00:00
Add rename script
This commit is contained in:
parent
08690cd72d
commit
f798a3e673
22
rename.py
Normal file
22
rename.py
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
import json
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
index = json.load(open('index.json', 'r'))
|
||||||
|
|
||||||
|
repos = Path('repos')
|
||||||
|
|
||||||
|
for repo in index:
|
||||||
|
path = repos / repo["id"]
|
||||||
|
if not os.path.exists(path):
|
||||||
|
print(f'Repo {path} does not exist or it has already been moved')
|
||||||
|
continue
|
||||||
|
if repo['description']:
|
||||||
|
print(f'Renaming: {repo["id"]} -> {repo["description"]}')
|
||||||
|
os.rename(path, repos/repo["description"].replace('/', ' '))
|
||||||
|
else:
|
||||||
|
files = os.listdir(path)
|
||||||
|
if len(files) == 1:
|
||||||
|
onefile = files[0]
|
||||||
|
fname = onefile.rsplit(".", 1)[0]
|
||||||
|
os.rename(path, repos / fname)
|
Loading…
Reference in New Issue
Block a user