Init fregment class
This commit is contained in:
parent
cffa246415
commit
af96c6aa59
7 changed files with 263 additions and 0 deletions
|
|
@ -1,6 +1,7 @@
|
||||||
import base64
|
import base64
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
|
||||||
import magic
|
import magic
|
||||||
|
|
@ -9,6 +10,9 @@ from PIL import Image
|
||||||
from distribusi.page_template import html_footer, html_head
|
from distribusi.page_template import html_footer, html_head
|
||||||
from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES
|
from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES
|
||||||
|
|
||||||
|
from distribusi import fregments
|
||||||
|
|
||||||
|
|
||||||
MIME_TYPE = magic.Magic(mime=True)
|
MIME_TYPE = magic.Magic(mime=True)
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -109,6 +113,9 @@ def write_index(args,index, html, html_head, html_footer):
|
||||||
|
|
||||||
|
|
||||||
def distribusify(args, directory): # noqa
|
def distribusify(args, directory): # noqa
|
||||||
|
|
||||||
|
freg = fregments.Fregments()
|
||||||
|
|
||||||
for root, dirs, files in os.walk(directory):
|
for root, dirs, files in os.walk(directory):
|
||||||
|
|
||||||
if args.exclude_directory:
|
if args.exclude_directory:
|
||||||
|
|
@ -123,6 +130,14 @@ def distribusify(args, directory): # noqa
|
||||||
dirs.sort()
|
dirs.sort()
|
||||||
files.sort()
|
files.sort()
|
||||||
|
|
||||||
|
#
|
||||||
|
# fregments index
|
||||||
|
# 작가 폴더 내인 경우 아티스트명 저장
|
||||||
|
#
|
||||||
|
path = root.split('/')
|
||||||
|
if len(path) == 3:
|
||||||
|
artist = path[2].strip()
|
||||||
|
|
||||||
if not args.remove_index:
|
if not args.remove_index:
|
||||||
html = []
|
html = []
|
||||||
|
|
||||||
|
|
@ -185,6 +200,15 @@ def distribusify(args, directory): # noqa
|
||||||
|
|
||||||
html.append(div(args, type_, subtype, a, name))
|
html.append(div(args, type_, subtype, a, name))
|
||||||
|
|
||||||
|
#
|
||||||
|
# fregments index
|
||||||
|
# 작가 폴더 내부의 파일인 경우 조각 추가
|
||||||
|
#
|
||||||
|
if len(path) == 3 and artist:
|
||||||
|
id_name = name.split('.')[0].replace(' ', '_')
|
||||||
|
freg.add(artist, id_name)
|
||||||
|
|
||||||
|
|
||||||
if root != directory:
|
if root != directory:
|
||||||
if args.menu_with_index:
|
if args.menu_with_index:
|
||||||
html.append('<a href="../index.html">../</a>')
|
html.append('<a href="../index.html">../</a>')
|
||||||
|
|
@ -192,12 +216,21 @@ def distribusify(args, directory): # noqa
|
||||||
html.append('<a href="../">../</a>')
|
html.append('<a href="../">../</a>')
|
||||||
|
|
||||||
for name in dirs:
|
for name in dirs:
|
||||||
|
'''
|
||||||
if args.menu_with_index:
|
if args.menu_with_index:
|
||||||
a = "<a href='{}/index.html'>{}</a>".replace('{}', name)
|
a = "<a href='{}/index.html'>{}</a>".replace('{}', name)
|
||||||
else:
|
else:
|
||||||
a = "<a href='{}'>{}/</a>".replace('{}', name)
|
a = "<a href='{}'>{}/</a>".replace('{}', name)
|
||||||
|
|
||||||
html.insert(0, div(args, 'dir', 'dir', a, 'folder'))
|
html.insert(0, div(args, 'dir', 'dir', a, 'folder'))
|
||||||
|
'''
|
||||||
|
#
|
||||||
|
# fregments index
|
||||||
|
# 작가 폴더 내부의 폴더인 경우 조각 추가
|
||||||
|
#
|
||||||
|
if len(path) == 3 and artist:
|
||||||
|
id_name = name.split('.')[0].replace(' ', '_')
|
||||||
|
freg.add(artist, id_name)
|
||||||
|
|
||||||
index = os.path.join(root, 'index.html')
|
index = os.path.join(root, 'index.html')
|
||||||
if os.path.exists(index):
|
if os.path.exists(index):
|
||||||
|
|
@ -216,3 +249,22 @@ def distribusify(args, directory): # noqa
|
||||||
os.remove(index)
|
os.remove(index)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
|
|
||||||
|
#
|
||||||
|
# fregments index
|
||||||
|
# 임시 데이터 저장
|
||||||
|
#
|
||||||
|
print("-----------------------")
|
||||||
|
html = []
|
||||||
|
freg.save()
|
||||||
|
json_data = freg.get_fregments()
|
||||||
|
count = freg.get_count()
|
||||||
|
for f in json_data:
|
||||||
|
file = f['file']
|
||||||
|
url = "/{}/#{} ".format(file['artist'], file['fregment'])
|
||||||
|
label = "{} 번째 조각".format(count)
|
||||||
|
html.append('<a href="{}">{}</a><br/>'.format(url, label))
|
||||||
|
count = count - 1
|
||||||
|
|
||||||
|
index = os.path.join(directory, 'index.html')
|
||||||
|
write_index(args, index, html, html_head, html_footer)
|
||||||
|
|
|
||||||
62
distribusi/distribusi/fregments.py
Normal file
62
distribusi/distribusi/fregments.py
Normal file
|
|
@ -0,0 +1,62 @@
|
||||||
|
import json
|
||||||
|
import time
|
||||||
|
from operator import itemgetter
|
||||||
|
|
||||||
|
class Fregments:
|
||||||
|
def __init__(self):
|
||||||
|
self.file = 'fregments_index.json';
|
||||||
|
with open(self.file) as json_file:
|
||||||
|
self.json_data = json.load(json_file)
|
||||||
|
print(json.dumps(self.json_data))
|
||||||
|
|
||||||
|
self.temp_data = {"fregments":[]}
|
||||||
|
self.count = len(self.json_data["fregments"])
|
||||||
|
|
||||||
|
|
||||||
|
def add(self, artist, fregment):
|
||||||
|
|
||||||
|
temp = {
|
||||||
|
"index" : 0,
|
||||||
|
"update" : 0,
|
||||||
|
"file" : {
|
||||||
|
"artist": artist,
|
||||||
|
"fregment": fregment
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
added = False
|
||||||
|
for f in self.json_data['fregments']:
|
||||||
|
# 기존 조각과 비교
|
||||||
|
if f['file'] == temp['file']:
|
||||||
|
added = True
|
||||||
|
|
||||||
|
if added:
|
||||||
|
print("Already added - artist:", artist, ", fregment: ", fregment)
|
||||||
|
else:
|
||||||
|
self.count = self.count + 1
|
||||||
|
print("Add fregment - artist:", artist, ", fregment: ", fregment)
|
||||||
|
temp["index"] = self.count
|
||||||
|
temp["update"] = int(time.time())
|
||||||
|
self.temp_data['fregments'].append(temp)
|
||||||
|
|
||||||
|
def save(self):
|
||||||
|
print(json.dumps(self.temp_data))
|
||||||
|
for f in self.temp_data['fregments']:
|
||||||
|
self.json_data['fregments'].append(f)
|
||||||
|
with open(self.file, 'w') as outfile:
|
||||||
|
json.dump(self.json_data, outfile, indent=4)
|
||||||
|
self.count = len(self.json_data["fregments"])
|
||||||
|
|
||||||
|
def get_fregments(self):
|
||||||
|
fregments = self.json_data['fregments']
|
||||||
|
# reverse
|
||||||
|
fregments.sort(key = itemgetter('index'), reverse=True)
|
||||||
|
return fregments
|
||||||
|
|
||||||
|
def get_count(self):
|
||||||
|
return self.count
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
freg = Fregments()
|
||||||
116
fregments_index.json
Normal file
116
fregments_index.json
Normal file
|
|
@ -0,0 +1,116 @@
|
||||||
|
{
|
||||||
|
"fregments": [
|
||||||
|
{
|
||||||
|
"index": 1,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "carrot",
|
||||||
|
"fregment": "RTF\ud14c\uc2a4\ud2b8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 2,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "carrot",
|
||||||
|
"fregment": "\uafb8\ubb3c\uafb8\ubb3c"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 3,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "carrot",
|
||||||
|
"fregment": "\uc9c8\uc8fc"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 4,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "fig",
|
||||||
|
"fregment": "test"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 5,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "fig",
|
||||||
|
"fregment": "20201020"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 6,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "fig",
|
||||||
|
"fregment": "20201022"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 7,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "fig",
|
||||||
|
"fregment": "20201029"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 8,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "grape",
|
||||||
|
"fregment": "IMG_1334"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 9,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "grape",
|
||||||
|
"fregment": "IMG_1340"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 10,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "grape",
|
||||||
|
"fregment": "IMG_1690"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 11,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "grape",
|
||||||
|
"fregment": "IMG_1693"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 12,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "grape",
|
||||||
|
"fregment": "fbdbdbf54d766dd86e5964de01ddc16b"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 13,
|
||||||
|
"update": 1604054082,
|
||||||
|
"file": {
|
||||||
|
"artist": "grape",
|
||||||
|
"fregment": "sample"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"index": 14,
|
||||||
|
"update": 1604054149,
|
||||||
|
"file": {
|
||||||
|
"artist": "carrot",
|
||||||
|
"fregment": "1030"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
33
test_data/404.html
Normal file
33
test_data/404.html
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
<title>Page Not Found</title>
|
||||||
|
|
||||||
|
<style media="screen">
|
||||||
|
body { background: #ECEFF1; color: rgba(0,0,0,0.87); font-family: Roboto, Helvetica, Arial, sans-serif; margin: 0; padding: 0; }
|
||||||
|
#message { background: white; max-width: 360px; margin: 100px auto 16px; padding: 32px 24px 16px; border-radius: 3px; }
|
||||||
|
#message h3 { color: #888; font-weight: normal; font-size: 16px; margin: 16px 0 12px; }
|
||||||
|
#message h2 { color: #ffa100; font-weight: bold; font-size: 16px; margin: 0 0 8px; }
|
||||||
|
#message h1 { font-size: 22px; font-weight: 300; color: rgba(0,0,0,0.6); margin: 0 0 16px;}
|
||||||
|
#message p { line-height: 140%; margin: 16px 0 24px; font-size: 14px; }
|
||||||
|
#message a { display: block; text-align: center; background: #039be5; text-transform: uppercase; text-decoration: none; color: white; padding: 16px; border-radius: 4px; }
|
||||||
|
#message, #message a { box-shadow: 0 1px 3px rgba(0,0,0,0.12), 0 1px 2px rgba(0,0,0,0.24); }
|
||||||
|
#load { color: rgba(0,0,0,0.4); text-align: center; font-size: 13px; }
|
||||||
|
@media (max-width: 600px) {
|
||||||
|
body, #message { margin-top: 0; background: white; box-shadow: none; }
|
||||||
|
body { border-top: 16px solid #ffa100; }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="message">
|
||||||
|
<h2>404</h2>
|
||||||
|
<h1>Page Not Found</h1>
|
||||||
|
<p>The specified file was not found on this website. Please check the URL for mistakes and try again.</p>
|
||||||
|
<h3>Why am I seeing this?</h3>
|
||||||
|
<p>This page was generated by the Firebase Command-Line Interface. To modify it, edit the <code>404.html</code> file in your project's configured <code>public</code> directory.</p>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
0
test_data/carrot/1030.txt
Normal file
0
test_data/carrot/1030.txt
Normal file
0
test_data/fig/test.txt
Normal file
0
test_data/fig/test.txt
Normal file
BIN
test_data/grape/fbdbdbf54d766dd86e5964de01ddc16b.jpg
Normal file
BIN
test_data/grape/fbdbdbf54d766dd86e5964de01ddc16b.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 43 KiB |
Loading…
Reference in a new issue