#!/usr/bin/env python
# -*- coding: utf-8 -*-

''' Fast gophermap generator '''

import os

header = '''
Tengu phlog
===========
'''

footer = '''
All Files in root folder Here
=============================
*
    '''


dirs = {'Low_Tech': 'Low Tech Pim',
       'misc' : 'Scripts, code, etc'}
       #'2021' : 'Tengu journal'}

text = {'name': '', 'noname': '', 'journal':'\n Tengu journal\n =============\n'}

def cut_path(n):
   ''' cut path to folder'''
   return n[2:]


for i in os.walk('.'):

   # pass if i is root folder
   if i[0] == '.':
       continue

   # dir
   d = cut_path(i[0]).strip()
   if d in dirs:
       n = 'name'
       text[n] += f'\n {dirs[d]}\n'
       text[n] += f' {"=" * len(dirs[d])}\n'
   elif len(d) == 4 and d[:2] == '20':
       n = 'journal'
   else:
       n = 'noname'


   ds = f'\n1{d}/\t{d}\n\n'
   text[n] += ds

   for f in i[2]: # filez

       # files inside dir
       ext = os.path.basename(f).split('.')[-1].strip()
       if ext == 'png':
           flag = 'I'
       else:
           flag = '0'
       fn = f'{flag}{f}\t{cut_path(os.path.join(i[0], f))}\n'
       text[n] += fn



t = f"{header} {text['name']} {text['noname']} {text['journal']} {footer}"

print(t)

'''
f = open('gophermap', 'w')
f.write(header + text + footer)
f.close()
'''


#  Copyright 2021 Vik Voinikoff
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
#  MA 02110-1301, USA.