User:Artemis gryllaki/PrototypingII: Difference between revisions

From XPUB & Lens-Based wiki
No edit summary
No edit summary
Line 291: Line 291:
Questions on networks: Centralized/Decentralized/Federated<br>
Questions on networks: Centralized/Decentralized/Federated<br>
http://please.undo.undo.it/questions.html<br>
http://please.undo.undo.it/questions.html<br>
<source lang="html5">
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Questions on Networks</title>
    <link rel="stylesheet" href="styleq.css">
    <script src="questions.js"></script>
  </head>
  <header><br>
    <h1>Questions on Networks</h1>
    <p><span class="blink">Centralized - Decentralized </br> Federated</blink></a></p>
  </header>
  <main>
    <br><br><br><br><br><br>
    <div class="box"><h2 id="oneliner-1">QUESTIONS</h2></div>
   
    <br>
    <!--<p>Contributors: </p>-->
   
   
  </main>
  <footer>
 
  </footer>
  </body>
</html>
</source>


<source lang="javascript">
<source lang="javascript">
Line 348: Line 377:


})();
})();
</source>
<source lang="html5">
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Questions on Networks</title>
    <link rel="stylesheet" href="styleq.css">
    <script src="questions.js"></script>
  </head>
  <header><br>
    <h1>Questions on Networks</h1>
    <p><span class="blink">Centralized - Decentralized </br> Federated</blink></a></p>
  </header>
  <main>
    <br><br><br><br><br><br>
    <div class="box"><h2 id="oneliner-1">QUESTIONS</h2></div>
   
    <br>
    <!--<p>Contributors: </p>-->
   
   
  </main>
  <footer>
 
  </footer>
  </body>
</html>
</source>
</source>

Revision as of 18:36, 7 April 2019

XMPP Bots

https://pad.xpub.nl/p/special_Issue8_29_1 https://pad.xpub.nl/p/special_issue_19_05_02 https://pad.xpub.nl/p/04_03_19_tools

04/03/2019

Mood (Archive) Bot

Artemis && Rita && Simon
Description: A bot that is used to share images or small notes that allows and suggests various ways of organizing them
— Highlights the social aspect of XMPP
— XMPP allows uploading on-the-fly
— Archives how the user interacts with a webpage
— Reveals how we map information collectively and individually (with hashtags), & how it is mapped by the tools that we're using (with metadata)
— Collective understanding of a network through abstraction (in jargon, annotations, archiving)

https://git.xpub.nl/XPUB/federated-publishing-prototypes/src/branch/master/archive-bot

Screenshot of the xmpp channel, where the archive bot is active.







#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
	Slixmpp: The Slick XMPP Library
	Copyright (C) 2010  Nathanael C. Fritz
	This file is part of Slixmpp.

	See the file LICENSE for copying permission.
"""
# Code source: https://git.poez.io/slixmpp/tree/examples/muc.py

# To run this bot:
# $ python3 streambot.py --jid username@yourdomainname.ext --password password --room channel@groups.domainname.ext --nick nickname --output ./output/
# python3 streambot.py --jid rita@please.undo.undo.it --room paranodal.activity@groups.please.undo.undo.it --nick test --output ./output/

import logging
from getpass import getpass
from argparse import ArgumentParser

import slixmpp
import ssl, os, requests, urllib
import os, sys
from PIL import Image
import exifread

#idea of class is important: like creating your own concepts, names, etc. like a library
class MUCBot(slixmpp.ClientXMPP):

	def __init__(self, jid, password, room, nick, output, outputparanodal):
		slixmpp.ClientXMPP.__init__(self, jid, password)
		self.room = room
		self.nick = nick
		self.output = output
		self.outputparanodal = outputparanodal
		self.tmp = None

		# The session_start event will be triggered when
		# the bot establishes its connection with the server
		# and the XML streams are ready for use. We want to
		# listen for this event so that we we can initialize
		# our roster.
		self.add_event_handler("session_start", self.start)

		# The groupchat_message event is triggered whenever a message
		# stanza is received from any chat room. If you also also
		# register a handler for the 'message' event, MUC messages
		# will be processed by both handlers.
		self.add_event_handler("groupchat_message", self.muc_message)

	def start(self, event):
		"""
		Process the session_start event.

		Typical actions for the session_start event are
		requesting the roster and broadcasting an initial
		presence stanza.
		"""

		self.get_roster()
		self.send_presence()

		# https://xmpp.org/extensions/xep-0045.html
		self.plugin['xep_0045'].join_muc(self.room,
										 self.nick,
										 # If a room password is needed, use:
										 # password=the_room_password,
										 wait=True)

	def muc_message(self, msg):
		"""
		Process incoming message stanzas from any chat room. Be aware
		that if you also have any handlers for the 'message' event,
		message stanzas may be processed by both handlers, so check
		the 'type' attribute when using a 'message' event handler.

		Whenever the bot's nickname is mentioned, respond to
		the message.

		IMPORTANT: Always check that a message is not from yourself,
				   otherwise you will create an infinite loop responding
				   to your own messages.

		This handler will reply to messages that mention
		the bot's nickname.

		Arguments:
			msg -- The received message stanza. See the documentation
				   for stanza objects and the Message stanza to see
				   how it may be used.
		"""

		# Some inspection commands
		#print('......,.......................')
		#print('Message:{}'.format(msg))
		# print('\nMessage TYPE:{}'.format(msg['type']))
		# print('\nMessage body:{}'.format(msg['body']))
		#print('Message OOB:{}'.format(msg['oob']))
		#print('Message OOB URL:{}'.format(msg['oob']['url']))
		# print('\nMessage MUCK NICK:{}'.format(msg['mucnick']))

		# Always check that a message is not the bot itself, otherwise you will create an infinite loop responding to your own messages.
		if msg['mucnick'] != self.nick:
			#
			#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)
			#print(len(msg['oob']['url']))
			if len(msg['oob']['url']) > 0:

				# Save the image to the output folder
				url = msg['oob']['url'] # grep the url in the message
				self.tmp = url

				#Send a reply

				self.send_message(mto=msg['from'].bare,
								  mbody="Please put hashtag!",
								  mtype='groupchat')

			# Include messages in the stream (only when '#' is used in the message. creates a folder for each #)
			for word in msg['body'].split():
				if word.startswith('#'):
					if self.tmp:
						url = self.tmp
						#print('URL:', url)
						folder = word.replace('#', '')
						filename = os.path.basename(url) # grep the filename in the url
						if not os.path.exists(folder):
							os.mkdir(folder)
						output_path = os.path.join(folder, filename)
						u = urllib.request.urlopen(url) # read the image data
						f = open(output_path, 'wb') # open the output file
						f.write(u.read()) # write image to file
						f.close() # close the output file

						# Add image to stream and resizes it
						img = '<img class="image" src="{}" width="400">'.format(filename)

						#f = open(img, 'rb')
						# Return Exif tags
						#tags = exifread.process_file(f)
						#to print a specific tag
						#for tag in tags.keys():
						#    if tag in ('Image ImageWidth'):
						#        print ("Key: {}, value {}".format(tag, tags[tag]))

						stream = 'index.html'
						stream_path = os.path.join(folder, stream)
						f = open(stream_path, 'a+')
						f.write(img+'\n')
						f.close()
					else:
						folder = word.replace('#', '')
						self.send_message(mto=msg['from'].bare,
										  mbody="Be aware {} ! You are creating a hashtag called {}.".format(msg['mucnick'], folder),
										  mtype='groupchat')
						message = '<p class="message">{}</p>'.format(msg['body'])
						if not os.path.exists(folder):
							os.mkdir("{}".format(folder))
						stream = 'index.html'
						stream_path = os.path.join(folder, stream)
						f = open(stream_path, 'a+')
						message = message.replace(word, '')
						f.write(message+'\n')
						f.close()
						#adds content to index.htm
						path = "."
						with os.scandir(path) as it:
							for entry in it:
								if not entry.name.startswith('.') and not entry.is_file():
									a = entry.name
									print(a)
						#note that the 'w' writes, the 'a' appends
									f = open('index.htm','w')
									message = """<html>
									<head></head>
									<body>
									<p>The archive</p>
									<p> See the categories: </p>
									"""
									f.write(message)
									f.close()
						#appends the name of the folder and link to index
						for a in os.listdir('.'):
							if os.path.isdir(a):
								f = open('index.htm','a')
								message = """
								<a href="./{}/index.html">{}</a>
								""".format(a, a)
								f.write(message)
								f.close()


if __name__ == '__main__':
	# Setup the command line arguments.
	parser = ArgumentParser()

	# output verbosity options.
	parser.add_argument("-q", "--quiet", help="set logging to ERROR",
						action="store_const", dest="loglevel",
						const=logging.ERROR, default=logging.INFO)
	parser.add_argument("-d", "--debug", help="set logging to DEBUG",
						action="store_const", dest="loglevel",
						const=logging.DEBUG, default=logging.INFO)

	# JID and password options.
	parser.add_argument("-j", "--jid", dest="jid",
						help="JID to use")
	parser.add_argument("-p", "--password", dest="password",
						help="password to use")
	parser.add_argument("-r", "--room", dest="room",
						help="MUC room to join")
	parser.add_argument("-n", "--nick", dest="nick",
						help="MUC nickname")

	# output folder for images
	parser.add_argument("-o", "--output", dest="output",
						help="output folder, this is where the files are stored",
						default="./output/", type=str)

		# output folder for images
	parser.add_argument("-op", "--outputpara", dest="outputparanodal",
						help="outputparanodal folder, this is where the files are stored",
						default="./outputparanodal/", type=str)

	args = parser.parse_args()

	# Setup logging.
	logging.basicConfig(level=args.loglevel,
						format='%(levelname)-8s %(message)s')

	if args.jid is None:
		args.jid = input("User: ")
	if args.password is None:
		args.password = getpass("Password: ")
	if args.room is None:
		args.room = input("MUC room: ")
	if args.nick is None:
		args.nick = input("MUC nickname: ")
	if args.output is None:
		args.output = input("Output folder: ")

	# Setup the MUCBot and register plugins. Note that while plugins may
	# have interdependencies, the order in which you register them does
	# not matter.
	xmpp = MUCBot(args.jid, args.password, args.room, args.nick, args.output, args.outputparanodal)
	xmpp.register_plugin('xep_0030') # Service Discovery
	xmpp.register_plugin('xep_0045') # Multi-User Chat
	xmpp.register_plugin('xep_0199') # XMPP Ping
	xmpp.register_plugin('xep_0066') # Process URI's (files, images)


	# Connect to the XMPP server and start processing XMPP stanzas.
	xmpp.connect()
	xmpp.process()


I used the mood (archive) xmpp bot we created, in the beginning of my research about the evolution of Social Media.
The outcome created is an image dump, of social media logos, looks like a moodboard and it is related with the context of my personal research.
SocialMediaEvolution



Personal Research

https://pad.xpub.nl/p/SI8-reflections 12/02/2019

1st prototype

Artemis
Questions on networks: Centralized/Decentralized/Federated
http://please.undo.undo.it/questions.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Questions on Networks</title>
    <link rel="stylesheet" href="styleq.css">
    <script src="questions.js"></script>
  </head>
  <header><br>
    <h1>Questions on Networks</h1>
    <p><span class="blink">Centralized - Decentralized </br> Federated</blink></a></p>
  </header>
  <main>
    <br><br><br><br><br><br>
    <div class="box"><h2 id="oneliner-1">QUESTIONS</h2></div>
    
    <br>
    <!--<p>Contributors: </p>-->
    
    
  </main>
  <footer>
   
  </footer>
  </body>
</html>
(function () {

  Messages = [
    "HOW CAN DECENTRALIZED WEB HAVE AN IMPACT BEYOND GEEKS, SOCIAL WEB ENTHUSIASTS & HACKERS?",
    "WHY DO WE NEED A DECENTRALIZED NETWORK?",
    "HOW DO WE PERCEIVE FEDERATED PUBLISHING?",
    "WHAT IS THE CONTENT WE WANT TO PRODUCE?",
    "COLLECTIVITY VS INDIVIDUALITY: DOES DECENTRALIZATION HELPS?",
    "WHO MAKES A FEDERATED NETWORK? FOR WHO? WHY? HOW?",
    "WHAT CONTENT DOES A FEDERATED NETWORK HOST?",
    "IS THE MEDIUM THE MESSAGE?",
    "DOES THE MEDIUM TRANSFORM THE MESSAGE?",
    "DOES THE SAME STORY HAVE DIFFERENT VALUE, ACCORDING TO WHERE IS IT HEARD?",
    "HOW IMPORTANT IS TO CHOOSE, OR CREATE OUR MEDIA OF COMMUNICATION?",
    "IS DECENTRALIZATION A PANACEA, OR A “PHARMAKON”?",
    "IS DECENTRALIZATION ENOUGH?",
    "WHAT ARE THE DANGERS OF CENTRALIZED NETWORKS?",
    "WHOSE VOICE IS AMPLIFIED AND WHOSE VOICE IS CURBED IN A CENTRALIZED NETWORK?",
    "DO WE NEED DIGITAL SOCIAL NETWORKING PLATFORMS?",
    "DO WE NEED VIRTUAL PUBLIC SPHERES THAT ARE DIFFICULT TO SHUT DOWN?",
    "IS THE FEDERATED NETWORK ORIENTED TOWARDS ANSWERING A COMMON GOAL?",
    "HOW IS THE COMMON GOAL OF THE NETWORK SHAPED?",
    "IS BEING PART OF THE NETWORK AS IMPORTANT AS BEING A CUSTODIAN OF IT?",
    "WHO MAINTAINS A FEDERATED NETWORK?",
    "WHAT IS THE LIFESPAN OF A FEDERATED NETWORK?",
    "HOW CAN A FEDERATED NETWORK BE SUSTAINED WITH ECONOMIC, ECOLOGICAL AND TIME-EFFICIENT MEANS?"
  ];

  function getRandomInt(min, max) {
    min = Math.ceil(min);
    max = Math.floor(max);
    return Math.floor(Math.random() * (max - min + 1)) + min;
  }

  function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }

  async function newMessage(id) {
    while (true) {
      ms = getRandomInt(1000, 3000);
      Message = Messages[Math.floor(Math.random()*Messages.length)];
      document.getElementById(id).innerHTML = Message;
      await sleep(ms);
    }
  }

  function questions(){
    newMessage('oneliner-1');
    
  }

  window.onload = questions;

})();