work----in----progress

This commit is contained in:
manetta 2021-01-11 23:08:38 +01:00
parent 662eb5645d
commit a783c06fd8
13 changed files with 278 additions and 47 deletions

View File

@ -40,45 +40,87 @@ def request_handle(used_handles_path):
return handle return handle
def write_to_log(self, entry): def rec(self, entry):
output = self.output output = self.output
# print(f'Output: { output }')
log = 'index.html'
css = 'stylesheet.css'
used_handles = '.handles.txt' used_handles = '.handles.txt'
log_path = os.path.join(output, log)
css_path = os.path.join(output, css)
used_handles_path = os.path.join(output, used_handles) used_handles_path = os.path.join(output, used_handles)
# check if file exists, if not: write it! # save entry
if not os.path.isfile(log_path):
html_template = open('templates/index.html', 'r').read()
css_template = open('templates/stylesheet.css', 'r').read()
with open(log_path, 'w') as l:
l.write(html_template)
l.write(f'<h1>{ self.groupchat }</h1>')
with open(css_path, 'w') as c:
c.write(css_template)
with open(used_handles_path, 'w') as h:
h.write('-----')
# add entry to log
handle = request_handle(used_handles_path) handle = request_handle(used_handles_path)
print(f'Picked a handle: { handle }') newfile_path = output + '/entries/' + handle + '.txt'
now = datetime.now().strftime('%A %d %B (%Y)') with open(newfile_path, 'w') as f:
print(f'Now is: { now }') f.write(entry)
post = f'''<div id="{ handle }" class="post">
<small class="postid">{ handle }</small>
{ entry }
<small class="date">Added on { now }</small>
</div>'''
print(f'Post: { post }')
with open(log_path, 'a+') as l:
l.write(post)
print('added to the log!')
with open(used_handles_path, 'a+') as h: with open(used_handles_path, 'a+') as h:
h.write(handle) h.write(handle)
print('added to the .handles file!')
print('Saved!')
def delete(self, handle):
used_handles = '.handles.txt'
used_handles_path = os.path.join(self.output, used_handles)
possible_file_paths = [
os.path.join(self.output, 'entries', handle + '.txt'),
os.path.join(self.output, 'entries', handle + '.png'),
os.path.join(self.output, 'entries', handle + '.jpg')
]
for path in possible_file_paths:
if os.path.isfile(path):
cmd = f'rm { path }'
print(f'> { cmd }')
os.system(cmd)
print(f'Removed { path }.')
pass
# delete handle from .handles.txt file
# read
with open(used_handles_path, 'r') as h:
txt = h.read()
txt = txt.replace(handle+'\n', "")
# write
with open(used_handles_path, 'w') as h:
h.write(txt)
# def write_to_log(self, entry):
# output = self.output
# # print(f'Output: { output }')
# log = 'index.html'
# css = 'stylesheet.css'
# used_handles = '.handles.txt'
# log_path = os.path.join(output, log)
# css_path = os.path.join(output, css)
# used_handles_path = os.path.join(output, used_handles)
# # check if file exists, if not: write it!
# if not os.path.isfile(log_path):
# html_template = open('templates/index.html', 'r').read()
# css_template = open('templates/stylesheet.css', 'r').read()
# with open(log_path, 'w') as l:
# l.write(html_template)
# l.write(f'<h1>{ self.groupchat }</h1>')
# with open(css_path, 'w') as c:
# c.write(css_template)
# with open(used_handles_path, 'w') as h:
# h.write('-----')
# # add entry to log
# handle = request_handle(used_handles_path)
# print(f'Picked a handle: { handle }')
# now = datetime.now().strftime('%A %d %B (%Y)')
# print(f'Now is: { now }')
# post = f'''<div id="{ handle }" class="post">
# <small class="postid">{ handle }</small>
# { entry }
# <small class="date">Added on { now }</small>
# </div>'''
# print(f'Post: { post }')
# with open(log_path, 'a+') as l:
# l.write(post)
# print('added to the log!')
# with open(used_handles_path, 'a+') as h:
# h.write(handle)
# print('added to the .handles file!')
# *spark # *spark
# add annotations # add annotations
@ -119,12 +161,13 @@ class MUCBot(slixmpp.ClientXMPP):
and messages that are marked with @bot to a folder. and messages that are marked with @bot to a folder.
""" """
def __init__(self, use, password, groupchat, nickname, output): def __init__(self, use, password, groupchat, nickname, output, mode):
slixmpp.ClientXMPP.__init__(self, use, password) slixmpp.ClientXMPP.__init__(self, use, password)
self.groupchat = groupchat self.groupchat = groupchat
self.nick = nickname self.nick = nickname
self.output = output self.output = output
self.mode = mode
# The session_start event will be triggered when # The session_start event will be triggered when
# the bot establishes its connection with the server # the bot establishes its connection with the server
@ -179,6 +222,9 @@ PS. you can access these logs at https://vvvvvvaria.org/logs/.''',
# Check if output folder exists # Check if output folder exists
if not os.path.exists(self.output): if not os.path.exists(self.output):
os.mkdir(self.output) os.mkdir(self.output)
os.mkdir(self.output + '/entries/')
with open(os.path.join(self.output, '.handles.txt'), 'w') as f:
pass
# Check if an OOB URL is included in the stanza (which is how an image is sent) # Check if an OOB URL is included in the stanza (which is how an image is sent)
# (OOB object - https://xmpp.org/extensions/xep-0066.html#x-oob) # (OOB object - https://xmpp.org/extensions/xep-0066.html#x-oob)
@ -210,23 +256,34 @@ PS. you can access these logs at https://vvvvvvaria.org/logs/.''',
mbody=f'Noted! And added to the log. Thanks { msg["mucnick"] }!', mbody=f'Noted! And added to the log. Thanks { msg["mucnick"] }!',
mtype='groupchat') mtype='groupchat')
# Add the message to the log! # Record the entry
message = msg['body'].replace('__ADD__','') rec(self, msg['body'])
message = f'<div class="entry text">{ message }</div>'
write_to_log(self, message)
# Include a new post in the log (only when '__ADD__' is used in the message) # Delete a post from the log
if '__ANNOTATE__' in msg['body']: if '__DELETE__' in msg['body']:
handle = msg['body'].split()[1] handle = re.findall("[aioeu][aioeu][aioeu][aioeu][aioeu]", msg['body'])[0]
annotation = msg['body'].replace('__ANNOTATE__', '').replace(handle, '')
post = find_in_soup(self, handle, annotation)
# reply from the bot # reply from the bot
self.send_message(mto=self.groupchat, self.send_message(mto=self.groupchat,
mbody="Thanks!", mbody=f'Noted! The following post is deleted from the log: { handle }',
mtype='groupchat') mtype='groupchat')
# Delete the entry
delete(self, handle)
# Include a new post in the log (only when '__ADD__' is used in the message)
# if '__ANNOTATE__' in msg['body']:
# handle = msg['body'].split()[1]
# annotation = msg['body'].replace('__ANNOTATE__', '').replace(handle, '')
# post = find_in_soup(self, handle, annotation)
# # reply from the bot
# self.send_message(mto=self.groupchat,
# mbody="Thanks!",
# mtype='groupchat')
# Check if this is a book ... # Check if this is a book ...
if '__BOOK__' in msg['body']: if '__BOOK__' in msg['body']:
@ -270,6 +327,16 @@ PS. you can access these logs at https://vvvvvvaria.org/logs/.''',
self.send_message(mto=self.groupchat, mbody='Sorry, no book found!', mtype='groupchat') self.send_message(mto=self.groupchat, mbody='Sorry, no book found!', mtype='groupchat')
# Generate HTML logfiles
# By default: log
if self.mode:
mode = str(self.mode.lower().strip())
if mode == "log":
print('> log.py')
elif mode == "stream":
print('> stream.py')
elif mode == "distribusi":
print('> distribusi.py')
if __name__ == '__main__': if __name__ == '__main__':
# Setup the command line arguments. # Setup the command line arguments.
@ -295,6 +362,9 @@ if __name__ == '__main__':
parser.add_argument("-o", "--output", dest="output", parser.add_argument("-o", "--output", dest="output",
help="output folder, this is where the files are stored", help="output folder, this is where the files are stored",
type=str) type=str)
parser.add_argument("-m", "--mode", dest="mode",
help="logmode, options include: log, stream, distribusi",
type=str, default='log')
args = parser.parse_args() args = parser.parse_args()
@ -316,7 +386,7 @@ if __name__ == '__main__':
# Setup the MUCBot and register plugins. Note that while plugins may # Setup the MUCBot and register plugins. Note that while plugins may
# have interdependencies, the order in which you register them does # have interdependencies, the order in which you register them does
# not matter. # not matter.
xmpp = MUCBot(args.use, args.password, args.groupchat, args.nickname, args.output) xmpp = MUCBot(args.use, args.password, args.groupchat, args.nickname, args.output, args.mode)
xmpp.register_plugin('xep_0030') # Service Discovery xmpp.register_plugin('xep_0030') # Service Discovery
xmpp.register_plugin('xep_0045') # Multi-User Chat xmpp.register_plugin('xep_0045') # Multi-User Chat
xmpp.register_plugin('xep_0199') # XMPP Ping xmpp.register_plugin('xep_0199') # XMPP Ping

View File

@ -0,0 +1,2 @@
soon :) still thinking how to "insert" distribusi here,
or make it a dependency

View File

@ -0,0 +1 @@
ieiauieiauiiuioiiuioooooeooooeieoooieooouuaiauuaia

Binary file not shown.

After

Width:  |  Height:  |  Size: 70 KiB

View File

@ -0,0 +1 @@
text msg, image, video, audio

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

65
RECbot/example/index.html Normal file
View File

@ -0,0 +1,65 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Log</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
</head>
<body>
<div id="welcome">
<p>Welcome to this Log!</p>
<p>This Log file is based on chat messages exchanged in a <em>XMPP groupchat</em> and is written by <em>RECbot</em>.</p>
<hr>
<p>For the writers of this log, you can:
<br>
<br>
send an image,
<br>
<br>
<code>__ADD__</code> a message,
<br>
<br>
<code>__DELETE__</code> it by using the <code>HANDLE</code> on the left (*spark),
<br>
<br>
<!-- <code>__ANNOTATE__</code> something using the <code>~HANDLE</code>, -->
<!-- <br> -->
<!-- <br> -->
<!-- <code>__ECHO__</code> material using the <code>~HANDLE</code> or a <code>#TAG</code> (*spark), -->
<!-- <br> -->
<!-- <br> -->
Request information about a <code>__BOOK__</code> by sending a <code>TITLE</code> (*spark, almost there),
<br>
<br>
... (*spark)
</p>
<!-- <hr> -->
</div>
<!-- <div id="echo">
<label for="echo" style="display: none;">__ECHO__</label>
<select name="echo" id="echo">
<option value="~HANDLE">~HANDLE</option>
<option value="#TAG">#TAG</option>
</select>
<input type="text" name="echo">
<button><code>__ECHO__</code></button>
</div> -->
<h1>ibugev@muc.vvvvvvaria.org</h1>
<div id="entries">
<div id="{ handle }" class="post">
<small class="postid">ieooo</small>
In general terms, “transhackfeminism” refers to hacking_with_care, using hacking with a meaning of (active) resistance and transformation to generate transversal knowledge through transdisciplinary artistic, aesthetic or cultural practices/ proposals. To work on producing knowledge collectively: without differentiating between theory and practice; as well as to embrace, protect and advance in free culture. To create communities where people meet, exchange, experience and share knowledge. To work on human and non-human alliances and solidarity through DIY/DIWO/DIT biotechnology, artistic and cultural practices.
<br><br>
To stay in touch with the material-affective dimensions of doing and engaging (bio)practices.
<br><br>
https://syllabus.pirate.care/topic/transhackfeminism/
<small class="date">Added on 11 January 2021</small>
</div>
<div id="{ handle }" class="post">
<small class="postid">auiio</small>
<img src="entries/soviet-80s-computers-EFcZsx0VUAAZZoC.jpeg">
<small class="date">Added on 12 January 2021</small>
</div>
</div>
</body>

View File

@ -1,14 +1,16 @@
import random import random
characters = ['*','+','-','/','-','-'] # characters = ['*','+','-','/','-','-']
characters = ['a','e','o','i','u']
out = open('handles.txt', 'w') out = open('handles.txt', 'w')
handles = set() handles = set()
# generate handles # generate handles
while len(handles) < 1000: while len(handles) < 2500:
handle = '' handle = ''
for h in range(5): for h in range(5):
handle += random.choice(characters) handle += random.choice(characters)
print(handle)
handles.add(handle) handles.add(handle)
# write handles to file # write handles to file

15
RECbot/log/log.py Normal file
View File

@ -0,0 +1,15 @@
import os
from jinja2 import Template
def generate_log_page(input, output):
files = os.listdir(input)
template = Template(open('./log/templates/index.html').read())
html = template.render(entries=files)
print(html)
logfile = os.path.join(output, 'index.html')
with open(logfile, 'w') as log:
log.write(html)
if __name__ == "__main__":
generate_log_page('./testing/entries/', './testing/')

View File

@ -44,4 +44,9 @@
<input type="text" name="echo"> <input type="text" name="echo">
<button><code>__ECHO__</code></button> <button><code>__ECHO__</code></button>
</div> --> </div> -->
<!-- Hmm ... We don't close the body anymore ... --> <div id="entries">
{% for entry in entries %}
<div>{{ entry }}</div>
{% endfor %}
</div>
</body>

View File

@ -0,0 +1,69 @@
body{
background-color: lightgrey;
min-width: 1080px;
margin: 40px;
font-size: 20px;
line-height: 24px;
}
div#welcome{
float: right;
top:40px;
right:40px;
width: 200px;
font-size: 16px;
}
div#welcome p{
margin:0 0 1em 0;
padding:0;
}
div#welcome hr{
border:0;
border-bottom:1px dotted blue;
margin:2em 0;
}
div#echo{
position: fixed;
bottom: 0;
left: 0;
width: 100%;
padding: 0.5em;
background-color: pink;
}
div.post{
margin: 2em 5em 2em 9em;
width: 800px;
}
div.post span.tagcontainer span{
padding-left: 0.5em;
color: blue;
}
p{
margin: 1em 0;
}
code{
color: blue;
}
small{
font-size: 12px;
line-height:1.2;
}
small.postid{
float: left;
font-family: monospace;
margin: 0 0 0 -180px;
padding: 1em 1.5em;
/*border-radius: 50px;*/
/*border: 1px dotted blue;*/
color: blue;
background-color: white;
font-size: 20px;
}
small.date{
display:block;
color:magenta;
margin:1em 0;
}
img{
max-width: 100%;
}

1
RECbot/stream/stream.py Normal file
View File

@ -0,0 +1 @@
soon :)