site_graphlogo
- Terms of Use and Privacy
Source Code
rss
site_graphlogo
- Terms of Use and Privacy
Source Code
rss

Source Code | Triple SHort export from file system

This exports the Cruft Buster file store to short-form emoji triples for Triple Pub.

#!/usr/bin/python3
# coding=utf-8
# Triple SHort export from file system
# The person who associated a work with this deed has dedicated
# the work to the public domain by waiving all of his or her rights
# to the work worldwide under copyright law, including all related
# and neighboring rights, to the extent allowed by law.
# You can copy, modify, distribute and perform the work, even for
# commercial purposes, all without asking permission.
# In no way are the patent or trademark rights of any person affected by
# CC0, nor are the rights that other persons may have in the work or in
# how the work is used, such as publicity or privacy rights.
# Unless expressly stated otherwise, the person who associated a work with
# this deed makes no warranties about the work, and disclaims liability
# for all uses of the work, to the fullest extent permitted by applicable law.
# When using or citing the work, you should not imply endorsement by the 
# author or the affirmer.
# https://creativecommons.org/publicdomain/zero/1.0/
import pprint
import re
import os
import base64
from pathlib import Path
from collections import defaultdict
from datetime import date,datetime
import paho.mqtt.publish as publish
aid='fsimport'
home = str(Path.home())+'/sync'
rootd=home+'/websites/source/itd/0/'
rootds=home+'/websites/source/itd/'
base='<https://itdocent.com/'
pbase='/source/itd/0/'
triples={}
padds=[]
for root,dirs,files in os.walk(rootd, followlinks=False):
   for fname in files:
      p=os.path.join(root,fname)
      if not fname.startswith('.') and fname.find('.predlabel.txt')==-1 and fname.find('.details.txt')==-1 and fname.find('^^')==-1 and fname[-3:]!='.md' and fname.find('_component_destination')==-1 and fname.find('_flow_destination')==-1:
         padds.clear()
         p=os.path.join(root,fname)
         bits=re.compile('^.+'+pbase+'(.+)/(has_specified_input|has_specified_output|has_specified_inp_and_out)/(.+)$')
         try:
            m = bits.match(p)
            subject=m.group(1)
            predicate=m.group(2)
            objctraw=m.group(3)
            if subject.find('/')==-1:
               nid=subject
               graph='0'
            else:
               nid=subject[subject.rfind('/')+1:]
               pgraph=subject[:subject.rfind('/')]
               graph=subject[:subject.rfind('/')].replace('/','.')
            ld=''
            if os.path.isfile(rootd+subject+'.title.txt'):
               with open(rootd+subject+'.title.txt') as f:
                  r=f.read().strip()
               if len(r)>0:
                  triples[aid+' '+graph+' '+nid+' 🏷ī¸ '+r.replace("\n","\\n").replace("\\n ","\\n")]=''
            if os.path.isfile(rootd+subject+'.details.txt'):
               with open(rootd+subject+'.details.txt') as f:
                  r=f.read().strip()
               if len(r)>0:
                  triples[aid+' '+graph+' '+nid+' đŸ’Ŧ '+r.replace("\n","\\n").replace("\\n ","\\n")]=''
            if os.path.isfile(rootd+subject+'/description.md'):
               with open(rootd+subject+'/description.md','rb') as f:
                  m=base64.b64encode(f.read()).decode('utf-8')
                  triples[aid+' '+graph+' '+nid+' 📄 '+m]=''
            if os.path.isfile(rootd+subject+'/narrative.md'):
               with open(rootd+subject+'/narrative.md','rb') as f:
                  m=base64.b64encode(f.read()).decode('utf-8')
                  triples[aid+' '+graph+' '+nid+' 📄 '+m]=''
            ttl=objctraw.find('title.txt')
            if ttl==-1:
               objct=objctraw[:-4]
            else:
               objct=objctraw[:ttl-1]
            if os.path.isfile(rootd+subject+'/'+predicate+'/'+objct+'.predlabel.txt'):
               with open(rootd+subject+'/'+predicate+'/'+objct+'.predlabel.txt') as f:
                  r=f.read().strip()
                  triples[aid+' '+graph+' '+nid+'DataFlow'+objct+' 🏷ī¸ '+r.replace("\n","\\n").replace("\\n ","\\n")]=''
            if os.path.isfile(rootd+subject+'/'+predicate+'/'+objct+'.details.txt'):
               with open(rootd+subject+'/'+predicate+'/'+objct+'.details.txt') as f:
                  r=f.read().strip()
                  triples[aid+' '+graph+' '+nid+'DataFlow'+objct+' đŸ’Ŧ '+r.replace("\n","\\n").replace("\\n ","\\n")]=''
            if predicate=='has_specified_inp_and_out':
               preddy='↔ī¸'
            elif predicate=='has_specified_output':
               preddy='➡ī¸'
            elif predicate=='has_specified_input':
               preddy='âŦ…ī¸'
            if graph=='0':
               pth=rootd+objct+'.txt'
            else:
               pth=rootd+pgraph+'/'+objct+'.txt'
            triples[aid+' '+graph+' '+nid+' '+preddy+' '+objct]=''
            if os.path.isfile(pth):
               with open(pth) as f:
                  r=f.read().strip()
               if len(r)>0:
                  triples[aid+' '+graph+' '+objct+' 🏷ī¸ '+r.replace("\n","\\n").replace("\\n ","\\n")]=''
            if graph=='0':
               pth=rootd+objct+'details.txt'
            else:
               pth=rootd+pgraph+'/'+objct+'details.txt'
            if os.path.isfile(pth):
               with open(pth) as f:
                  r=f.read().strip()
               if len(r)>0:
                  triples[aid+' '+graph+' '+nid+' đŸ’Ŧ '+r.replace("\n","\\n").replace("\\n ","\\n")]=''
         except:
            six=9
for t in triples:
   ts=datetime.utcnow().isoformat(sep='T', timespec='milliseconds').replace(':','').replace('-','').replace(' ','')+'Z'
   publish.single("allorg/dfd/full",'ℹī¸ '+ts+' '+t)