diff --git a/distribusi/distribusi/distribusi.py b/distribusi/distribusi/distribusi.py
index 198e58d..828f9d4 100644
--- a/distribusi/distribusi/distribusi.py
+++ b/distribusi/distribusi/distribusi.py
@@ -1,6 +1,7 @@
import base64
import os
import subprocess
+
from io import BytesIO
import magic
@@ -9,6 +10,9 @@ from PIL import Image
from distribusi.page_template import html_footer, html_head
from distribusi.mappings import CODE_TYPES, FILE_TYPES, SUB_TYPES
+from distribusi import fregments
+
+
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
+
+ freg = fregments.Fregments()
+
for root, dirs, files in os.walk(directory):
if args.exclude_directory:
@@ -123,6 +130,14 @@ def distribusify(args, directory): # noqa
dirs.sort()
files.sort()
+ #
+ # fregments index
+ # 작가 폴더 내인 경우 아티스트명 저장
+ #
+ path = root.split('/')
+ if len(path) == 3:
+ artist = path[2].strip()
+
if not args.remove_index:
html = []
@@ -185,6 +200,15 @@ def distribusify(args, directory): # noqa
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 args.menu_with_index:
html.append('../')
@@ -192,12 +216,21 @@ def distribusify(args, directory): # noqa
html.append('../')
for name in dirs:
+ '''
if args.menu_with_index:
a = "{}".replace('{}', name)
else:
a = "{}/".replace('{}', name)
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')
if os.path.exists(index):
@@ -216,3 +249,22 @@ def distribusify(args, directory): # noqa
os.remove(index)
except Exception as 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('{}
'.format(url, label))
+ count = count - 1
+
+ index = os.path.join(directory, 'index.html')
+ write_index(args, index, html, html_head, html_footer)
diff --git a/distribusi/distribusi/fregments.py b/distribusi/distribusi/fregments.py
new file mode 100644
index 0000000..4b7d255
--- /dev/null
+++ b/distribusi/distribusi/fregments.py
@@ -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()
diff --git a/fregments_index.json b/fregments_index.json
new file mode 100644
index 0000000..567c0b8
--- /dev/null
+++ b/fregments_index.json
@@ -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"
+ }
+ }
+ ]
+}
\ No newline at end of file
diff --git a/test_data/404.html b/test_data/404.html
new file mode 100644
index 0000000..829eda8
--- /dev/null
+++ b/test_data/404.html
@@ -0,0 +1,33 @@
+
+
+
The specified file was not found on this website. Please check the URL for mistakes and try again.
+This page was generated by the Firebase Command-Line Interface. To modify it, edit the 404.html file in your project's configured public directory.