→ Fichamentos
Estudos para Mnemônicos Yupana
Postado por glerm em Fichamentos, Rascunhos on fevereiro 13th, 2012
Estudos para criação de sintaxe-semântica com remix da wikipedia
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | #!/usr/bin/python # -*- coding: utf-8 -*- import sys import urllib2 from stripogram import html2text import random import re #emabaralhador do baralho def scramble(string): palavras=string.split() random.shuffle(palavras,random.random) return ' '.join([p for p in palavras]) # busca=[(meme,lingua),(...)] pt(portugues), el (grego), hi (hindi) ou en (ingles), mas da pra implemntar mais mexendo na expressã regular regex, mais abaixo busca=[('Alchemy','en'),('Nuvem','pt'),('Vida','pt'),('Turing_Test','en'),('Oráculo','pt'),('Curupira','pt'),('Μαντείο','el'),('Ποίηση' ,'el'),('नैतिकता', 'hi'),('मनोविज्ञान','hi')] brain='' #inicializando cerebro letras=140 #limite de caracteres ### mais sobre expressões regulares: #<TAG\b[^>]*>(.*?)</TAG> - expressão regular pra tirar uma tag da uma ideia de como cortar trechos # http://www.pythonregex.com/ for b in busca: opener = urllib2.build_opener() opener.addheaders = [('User-agent', 'Mozilla/5.0')] infile = opener.open('http://'+b[1]+'.wikipedia.org/wiki/'+b[0]) page = infile.read() html = page pattern = re.compile('(?<=p>).+(?=</p)', re.DOTALL) p=pattern.search(html).group() text = html2text(p) regex = re.compile("(.*?)(Contents|Índice|\[edit\]|\[editar\]|Πίνακας|\[Επεξεργασία\]|अनुक्रम|\[संपादित करें\])",re.DOTALL) r = regex.search(text) t=r.groups() bio=t[0] brain=brain+bio sorte = scramble(brain)#embaralhador sorte = "#wiqua "+sorte sorte = sorte[:letras] sorte = scramble(sorte) print sorte |
Separação de sílabas:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | import string import re def syllables (text): text = " " + text + " " vowel_list = ['a', 'e', 'i', 'o', 'u', 'y'] vowel_pairs = ['ai', 'au', 'aw', 'ee','ea', 'oa', 'oi', 'ou', 'oo', 'ow', 'oy', 'uu'] consonant_list = ['b', 'c', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'm', 'n', 'p', 'q', 'r', 's', 't', 'v', 'w', 'x', 'z'] consonant_blends = ['bl', 'br', 'ch', 'chr', 'cl', 'cr', 'dr', 'fl', 'fr', 'gl', 'gr', 'kn', 'pl', 'pr', 'sc', 'sh', 'sk', 'sl', 'sm', 'sn', 'sp', 'spr', 'squ', 'st', 'str', 'sw', 'th', 'tr', 'thr', 'nt', 'wh'] # Cut numbers in digits p = re.compile ("([0-9])([0-9])", re.IGNORECASE) for i in range (2): text = p.sub ("\\1#\\2", text) # Cut i / vowel (- o) / consonant p = re.compile ("i([aeiuy])([bcdfghjklmnpqrstvwxz])", re.IGNORECASE) text = p.sub ("i+\\1+\\2", text) # Cut the / vowel / consonant p = re.compile ("the([aeiouy])([bcdfghjklmnpqrstvwxz])", re.IGNORECASE) text = p.sub ("the+\\1+\\2", text) # Cut vowel / vowel except for pairs position = 0 while position < len (text)-1: if text [position] in vowel_list and text [position+1] in vowel_list: if not (text [position:position+2] in vowel_pairs): if not (text [position-1:position+3] in ["tion", "dual", "nion", "quir", "tiou"]): text = text [:position+1] + "_" + text [position+1:] position = position + 1 # Cut consonant / consonant (ll, mm, ...) p = re.compile ("([bcdfghjklmnpqrstvwxz])\\1([^ ])", re.IGNORECASE) text = p.sub ("\\1-\\1\\2", text) # Cut vowel / consonant vowel start = 0 end = 0 while start < len (text)-1: if text [start] in vowel_list and text [start+1] in consonant_list: end = start + 1 while end <= len (text)-1 and text [end] in consonant_list: end = end + 1 if end <= len (text)-1 and (text [start+1:end] in consonant_list or text [start+1:end] in consonant_blends) and text [end] in vowel_list and text [end:end+2] <> "e ": text = text [:start+1] + "/" + text [start+1:] start = start + 1 # Cut vowel consonant / consonant+ vowel (trumpet, simple, understanding, ...) start = 0 end = 0 while start < len (text)-1: if text [start] in vowel_list and text [start+1] in consonant_list: end = start + 2 while end <= len (text)-1 and text [end] in consonant_list: end = end + 1 if end <= len (text)-1 and end > start+2 and text [end] in vowel_list: if not (text [start+1:end] in consonant_blends): text = text [:start+2] + "-" + text [start+2:] start = start + 1 # Return the words splitted return text wordlist = ["2008", "piano", "waffle", "kissing", "diode", "museum", "simple", "hundred", "understanding", "trumpet", "paper", "preparing", "strengh", "theatre", "facetious", "abstemious", "statement", "consent", "extent", "event", "documents", "fire", "oil", "pattern", "fireplace", "theme", "based", "site", "sites", "within", "browse", "required", "ensures", "dictionary", "dichotomy", "pamphlet", "methan", "etherosexual"] for word in wordlist: print syllables (word) |
script de interação com gtalk
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | #!/usr/bin/python # -*- coding: utf-8 -*- # PyGtalkRobot: A simple jabber/xmpp bot framework using Regular Expression Pattern as command controller # Copyright (c) 2008 Demiao Lin <ldmiao@gmail.com> # # 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 3 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, see <http://www.gnu.org/licenses/>. # # Homepage: http://code.google.com/p/pygtalkrobot/ # # # This is an sample PyGtalkRobot that serves to set the show type and status text of robot by receiving message commands. # import sys import time from PyGtalkRobot import GtalkRobot ############################################################################################################################ class SampleBot(GtalkRobot): #Regular Expression Pattern Tips: # I or IGNORECASE <=> (?i) case insensitive matching # L or LOCALE <=> (?L) make \w, \W, \b, \B dependent on the current locale # M or MULTILINE <=> (?m) matches every new line and not only start/end of the whole string # S or DOTALL <=> (?s) '.' matches ALL chars, including newline # U or UNICODE <=> (?u) Make \w, \W, \b, and \B dependent on the Unicode character properties database. # X or VERBOSE <=> (?x) Ignores whitespace outside character sets #"command_" is the command prefix, "001" is the priviledge num, "setState" is the method name. #This method is used to change the state and status text of the bot. def command_001_setState(self, user, message, args): #the __doc__ of the function is the Regular Expression of this command, if matched, this command method will be called. #The parameter "args" is a list, which will hold the matched string in parenthesis of Regular Expression. '''(available|online|on|busy|dnd|away|idle|out|off|xa)( +(.*))?$(?i)''' show = args[0] status = args[1] jid = user.getStripped() # Verify if the user is the Administrator of this bot # if jid == ('organismo@gmail.com') : # print jid, " ---> ",bot.getResources(jid), bot.getShow(jid), bot.getStatus(jid) # self.setState(show, status) # self.replyMessage(user, "State settings changed!") # Verify if the user is the Administrator of this bot if jid == ('organismo@gmail.com') : print jid, " ---> ",bot.getResources(jid), bot.getShow(jid), bot.getStatus(jid) self.setState(show, status) self.replyMessage(user, "State settings changed!") #This method is used to send email for users. def command_002_SendEmail(self, user, message, args): #email yupanakernel@gmail.com hello dmeiao, nice to meet you, bla bla ... '''[email|mail|em|m]\s+(.*?@.+?)\s+(.*?),\s*(.*?)(?i)''' email_addr = args[0] subject = args[1] body = args[2] #call_send_email_function(email_addr, subject, body) self.replyMessage(user, "\nEmail sent to "+ email_addr +" at: "+time.strftime("%Y-%m-%d %a %H:%M:%S", time.gmtime())) #This method is used to response users. def command_100_default(self, user, message, args): '''.*?(?s)(?m)''' # self.replyMessage(user, time.strftime("%Y-%m-%d %a %H:%M:%S", time.gmtime())) self.replyMessage(user,"Você disse: "+ message + "\n") ############################################################################################################################ if __name__ == "__main__": bot = SampleBot() bot.setState('available', "<3 == Ψ") bot.start("yupanakernel@gmail.com", "senhasupersecretaperigo") |
postando em IRC
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | # -*- coding: utf-8 -*- #guardar esse arquivo para estudos basicos e pra criar um tutorial no futuro... import sys import socket import string HOST="irc.freenode.net" PORT=6667 NICK="yupana" IDENT="senha" REALNAME="yupana" CHAN="#metareciclagem" readbuffer=" " s=socket.socket( ) s.connect((HOST, PORT)) s.send("NICK %s\r\n" % NICK) s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME)) s.send("JOIN :%s\r\n" % CHAN) s.send("PRIVMSG %s :%s\r\n" % (CHAN, "Ola")) s.send("PRIVMSG %s :%s\r\n" % (CHAN, "Eu sou Yupana. Meu código esta em https://github.com/glerm/yupana. Se precisar aprofundar sobre IRC, tente esse link: http://www.irchelp.org/irchelp/rfc/rfc.html")) while 1: readbuffer=readbuffer+s.recv(1024) temp=string.split(readbuffer, "\n") readbuffer=temp.pop( ) for line in temp: line=string.rstrip(line) line=string.split(line) if(line[0]=="PING"): s.send("PONG %s\r\n" % line[1]) if(line[1]=="PRIVMSG"): l=line[3].split(':')+line[4:] #split do ponto e virgula so pra testar, bug se tentar fazer frases tipo "Seguinte: blablabla" s.send("PRIVMSG %s :%s\r\n" % (CHAN, "Você disse: "+" ".join(l[1:]))) #print line #debug mode |
Postando no Wordpress
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | # -*- coding: utf-8 -*- #depende de https://github.com/maxcutler/python-wordpress-xmlrpc from wordpress_xmlrpc import Client, WordPressPost from wordpress_xmlrpc.methods.posts import GetRecentPosts, NewPost from wordpress_xmlrpc.methods.users import GetUserInfo wp = Client('http://yupana.pontaodaeco.org/xmlrpc.php', 'gesuselva', 'kernelpanic') post = WordPressPost() post.title = 'Que as atuais máquinas informacionais e comunicacionais não se contentem em veicular conteúdos representativos, mas que concorram igualmente para a confecção de novos agenciamentos de enunciação (individuais e/ou coletivos)?' post.description = '<h1></h1><br><p>ﻊﺑﻭﺭ ﺎﻠﺣﺩﻭﺩ aquilo que dissolve no solo e continua a jornada electroquímica dos corpos finalmente será separada daquilo que sempre esteve apenas permeando - <a href=\"https://github.com/glerm/yupana\"/>um dicionário em aglutinação movendo aqueles braços, pernas, cabeça, tripas.</a> esta árvore de sinais, continua se espalhando e entidades que חציית הגבול</p><img src=\"http://upload.wikimedia.org/wikipedia/commons/2/20/Boltzmanns-molecule.jpg\"/>' post.tags = 'yupana, kernel' post.categories = ['coding'] wp.call(NewPost(post, True)) |
Postando no twitter. Antes precisa criar uma chave de API.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | #!/usr/bin/python # -*- coding: utf-8 -*- import twitter import random string="segundo o último hoax utilizava sistemas de numeração binários e de outras bases diferentes da decimal, como o numero 144, cuja a raiz quadrada é 12. Quantas tautologias precisamos?" def twitta(string): api = twitter.Api( consumer_key=' ', consumer_secret=' ', access_token_key=' ', access_token_secret=' ') status = api.PostUpdate(string) #AQUI VAI O POST |
Na Wiki MediaWiki (mesma usada na wikipedia):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | from wikitools import wiki from wikitools import api # create a Wiki object site = wiki.Wiki("http://my.wikisite.org/w/api.php") # define the params for the query params = {'action':'query', 'titles':'Main Page'} # create the request object request = api.APIRequest(site, params) # query the API result = request.query() #The result will look something like: #{u'query': # {u'pages': #{u'15580374': # {u'ns': 0, u'pageid': 15580374, u'title': u'Main Page'} #} #} #} #For most normal usage, you may not have to do API queries yourself and can just #use the various classes. For example, to add a template to the top of all the #pages in namespace 0 in a category: from wikitools import wiki from wikitools import category site = wiki.Wiki("http://my.wikisite.org/w/api.php") # Create object for "Category:Foo" cat = category.Category(site, "Foo") # iterate through all the pages in ns 0 for article in cat.getAllMembersGen(namespaces=[0]): # edit each page article.edit(prependtext="{{template}}\n") |