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

Source Code | CUT-up page generation

This program generates Cut-up Page. Note that the code doesn't generate the divs for the CSS, but it is the same algorithm.

Here is the source:

#!/usr/bin/python3
# coding=utf-8
# CUT up page generation
# 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 os
import spacy
import re
import base64
import random
from spacy.lang.en import English
nlp=English()
sentencizer = nlp.create_pipe("sentencizer")
nlp.add_pipe(sentencizer)
sites=('scm','cit','xfg','mcj','sig','log','tkt','sys','res','itd','crb','orn','are','mhc','cod','xyz','trb')
w=re.compile('[#├[\]<>&\*\\\/]')
sentences=[]
pics=[]
rootdoc='/home/divine/sync/files/photosites/site/media/thumbs' 
for root,dirs,files in os.walk(rootdoc, followlinks=False):
   for fname in files:
      f=os.path.join(root,fname)
      with open(f,'rb') as fl:
         pics.append(base64.b64encode(fl.read()).decode('utf-8'))
for s in sites:
   rootdoc='/home/divine/sync/websites/source/'+s+'/'
   with open(rootdoc+'details.txt') as d:
      domainurl=d.readline().rstrip()
   for root,dirs,files in os.walk(rootdoc, followlinks=False):
      for fname in files:
         f=os.path.join(root,fname)
         if fname=='narrative.md' and f.find('0/narrative.md')==-1:
            art=f[len(rootdoc)+1:-12]
            with open(f) as fl:
               #text=fl.readline()
               text=fl.read().replace('\n',' ').replace('\r',' ')
               if len(text)<10000:
                  doc = nlp(text)
                  for sent in doc.sents:
                     res=sent.text
                     if w.search(res)==None:
                        r=res.strip()
                        if len(r)>20 and r.count(' ')>10:
                           last=0
                           third=int(len(r)/3)
                           lthird=r.find(' ',third)
                           rthird=r.find(' ',third*2)
                           sentences.append(r[:lthird].strip()+'~'+s+'~'+art+'~'+domainurl) 
                           sentences.append(r[lthird:rthird].strip()+'~'+s+'~'+art+'~'+domainurl) 
                           sentences.append(r[rthird:].strip()+'~'+s+'~'+art+'~'+domainurl) 
pos='left'
for bitl in range(23):
   bitty=''               
   for bit in range(23):
      all=sentences[random.randrange(1,len(sentences))].split('~')
      bitty+=('<a href="'+all[3]+all[2]+'">'+all[0].upper()+'</a> ')
   print('<p>')
   if pos=='left':
      print('<div class="ileft"><a href="https://photos.metroponus.com" title="Metroponus"><img src="data:image/jpeg;charset=utf-8;base64,'+pics[random.randrange(0,len(pics))]+'" alt="pic 23 or so"></a></div>')
      pos='right'
      print('<div class="tright">'+bitty+'</div>') 
   else:
      print('<div class="tleft">'+bitty+'</div>') 
      print('<div class="iright"><a href="https://photos.metroponus.com" title="Metroponus"><img src="data:image/jpeg;charset=utf-8;base64,'+pics[random.randrange(0,len(pics))]+'" alt="pic 23 or so"></a></div>')
      pos='left'

raw source

cut_up