Some recent changes and stuff

This commit is contained in:
Russell 2016-01-06 14:08:25 -05:00
parent ebb5f2fe37
commit 86916fb5fa
18 changed files with 321 additions and 30 deletions

View File

@ -14,3 +14,4 @@ alias usenet='tin -r'
alias units='~/Code/units/units-2.11/units -f ~/Code/units/units-2.11/definitions.units'
alias beats_raw='echo "x = (`date +%s` + 3600) % 86400; scale=3; x / 86.4" | bc'
alias beats='printf "@\e[0;36m`beats_raw`\e[m\n"'
alias pp='python -mjson.tool'

View File

@ -16,7 +16,9 @@ import mentions
import pretty_date
import inflect
from rhymesWith import getRhymes
from defineWord import define
from rhymesWith import rhymeZone
from defineWord import defWord
from rainbow import makeRainbow
parser = OptionParser()
@ -112,7 +114,7 @@ def get_rhymes(channel, user, text):
else:
with open("/home/nossidge/poems/words_poetic.txt", "r") as words:
word = random.choice(words.readlines()).strip("\n")
rhymes = getRhymes(word)
rhymes = rhymeZone(word)
if(len(rhymes) == 0):
ircsock.send("PRIVMSG " + channel + " :" + user + ": Couldn't find anything that rhymes with '" + word + "' :(\n")
else:
@ -122,15 +124,18 @@ def define_word(channel, user, text):
word = ""
if(len(text.split(' ')) > 1):
word = text.split(' ')[1]
defs = define(word)
defs = defWord(word)
if(len(defs) == 0):
ircsock.send("PRIVMSG " + channel + " :" + user + ": Couldn't find the definition of '" + word + "' :(\n")
else:
ircsock.send("PRIVMSG " + channel + " :" + user + ": Define '" + word + "'" + ''.join(defs)[0:200] + "\n")
def make_rainbow(channel, user, text):
rbword = makeRainbow(text[9:])
ircsock.send("PRIVMSG " + channel + " :" + rbword + "\n")
def rollcall(channel):
ircsock.send("PRIVMSG "+ channel +" :U wot m8? I score all the top drawer #banter and #bantz on this channel! Find new top-shelf banter with !newbanter, !rhyme, and !define\n")
ircsock.send("PRIVMSG "+ channel +" :U wot m8? I score all the top drawer #banter and #bantz on this channel! Find new top-shelf banter with !newbanter, !rhymes, and !define. Make your chatter #legend with !rainbow\n")
def connect(server, channel, botnick):
ircsock.connect((server, 6667))
@ -183,6 +188,9 @@ def listen():
if ircmsg.find(":!define") != -1:
define_word(channel, user, messageText)
if ircmsg.find(":!rainbow") != -1:
make_rainbow(channel, user, messageText)
if ircmsg.find(":!rollcall") != -1:
rollcall(channel)

25
Code/irc/defineWord.py Normal file
View File

@ -0,0 +1,25 @@
import urllib
from bs4 import BeautifulSoup
import random
def define(word):
defs = []
url = 'http://www.merriam-webster.com/dictionary/%s' % word
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
head = soup.find('div', id='headword')
if head:
for p in head.find_all('p'):
defs.append(p.text.encode('ascii', 'ignore'))
return defs
key = open("/home/krowbar/.secret/key").readline().rstrip()
def defWord(word):
defs = []
url = 'http://www.dictionaryapi.com/api/v1/references/collegiate/xml/%s?key=%s' % (word, key)
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html5lib')
entry = soup.find('entry')
if entry:
for d in entry.find_all('dt'):
defs.append(d.text.encode('ascii', 'ignore'))
return defs

View File

@ -1,2 +1,4 @@
endorphant&^%68
krowbar&^%60
krowbar&^%119
karlen&^%2
jumblesal&^%37

38
Code/irc/puzzle.py Normal file
View File

@ -0,0 +1,38 @@
#!/usr/bin/python
import random
import inflect
p = inflect.engine()
def make_puzzle():
answer = 0
puzzle = random.choice(["Prove you're not a robot: ", "Are you a robot?: ", "Anti-bot check: ", "Counter-cndorphant measures: "])
puzzle += random.choice(["What is", "How many is", "What do you get from", "What do you get with", "What is the value of", "Can you answer", "Can you tell me"])
puzzle += " "
roll = random.randrange(0,4)
var1 = random.randrange(1,10)
var2 = random.randrange(1,10)
if roll == 0:
answer = var1 + var2
puzzle += p.number_to_words(var1) + " " + random.choice(["and", "plus", "sum", "add"]) + " " + p.number_to_words(var2)
elif roll == 1:
answer = var1 * var2
puzzle += p.number_to_words(var1) + " " + random.choice(["times", "multiply", "multiplied by", "product"]) + " " + p.number_to_words(var2)
elif roll == 2:
if var2 > var1:
var1,var2 = var2,var1
answer = var1 - var2
puzzle += p.number_to_words(var1) + " " + random.choice(["minus", "subtract", "take away", "less"]) + " " + p.number_to_words(var2)
elif roll == 3:
if var2 > var1:
var1,var2 = var2,var1
answer = var1 * 2 / var2
puzzle += p.number_to_words(var1*2) + " " + random.choice(["divided by", "over"]) + " " + p.number_to_words(var2) + " (no remainder)"
elif roll == 4:
answer == var1 ** var2
puzzle += p.number_to_words(var1) + " to the " + p.ordinal(p.number_to_words(var2)) + " power"
puzzle += "? (Answer with numbers)"
return [answer, puzzle]

18
Code/irc/rainbow.py Normal file
View File

@ -0,0 +1,18 @@
import random
def makeRainbow(word):
word = word or "RAINBOW"
output = ""
rb = ["5","7","8","3","12","13","6"]
bg = "01"
idx = random.randrange(0, len(rb))
for l in word:
if l == " ":
output += ' '
else:
output += "\x03" + rb[idx % len(rb)] + "," + bg + l
idx += 1
return output

25
Code/irc/rhymesWith.py Normal file
View File

@ -0,0 +1,25 @@
import urllib
#from lxml.html import fromstring
from bs4 import BeautifulSoup
import random
def getRhymes(word):
words = []
url = 'http://www.rhymer.com/RhymingDictionaryLast/%s.html' % word
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
for t in soup.find_all('table', 'table'):
words.append(random.choice([w for w in t.text.split('\n') if w not in [u'', u'\xa0'] and '-' not in w]))
return words
def rhymeZone(word):
words = []
url = 'http://rhymezone.com/r/rhyme.cgi?Word=%s&typeofrhyme=perfect&org1=syl&org2=l&org3=y' % word
soup = BeautifulSoup(urllib.urlopen(url).read(), 'html.parser')
for t in soup.find_all('a', 'd'):
w = t.text.rstrip()
if w not in [u'', u'\xa0'] and '?' not in t:
words.append(w)
random.shuffle(words)
return words[0:5]

View File

@ -1,20 +1,20 @@
krowbar&^%263&^%1448316671
karlen&^%271&^%1426779321
krowbar&^%292&^%1452094972
karlen&^%272&^%1449500011
endorphant&^%682&^%1444775660
jumblesale&^%24&^%1426171214
marcus&^%815&^%1446654919
marcus&^%826&^%1452092376
papa&^%179&^%1438878499
epicmorphism&^%5&^%1421937744
audy&^%78&^%1442345315
kc&^%18&^%1422326056
vilmibm&^%9&^%1445468087
cmr&^%1054&^%1447812299
cmr&^%1074&^%1451719260
imt&^%519&^%1424087616
cndorphant&^%788&^%1424094192
rain&^%17&^%1422310975
sl2c&^%91&^%1424847521
selfsame&^%1&^%1422230012
bear&^%213&^%1443668443
bear&^%220&^%1452096373
coaxial&^%8&^%1422325983
joe&^%8&^%1422325983
hardmath123&^%4&^%1422325983
@ -28,6 +28,8 @@ reppard&^%11&^%1437512059
jesse&^%6&^%1437569027
khoi&^%3&^%1438044039
sanqui&^%4&^%1438184911
endorphan&^%52&^%1448373701
endorphan&^%57&^%1450367628
cndorphbo&^%2&^%1447862524
santi&^%3&^%1447873216
insom&^%1&^%1450346059
tahnok&^%3&^%1450457276

View File

@ -17,3 +17,4 @@
1443998393&^%cmr&^%http://tilde.town/~wiki/ircbots.html
1444203916&^%cmr&^%http://tilde.town/~wiki/ircbots.html | cndorphbot:
1447252215&^%krowbar&^%#bots, the last bastion of the free
1451487092&^%krowbar&^%Bots rule! Users drool!

View File

@ -125,3 +125,8 @@
1447266389&^%vilmibm&^%let's talk about html + feels now
1447728949&^%vilmibm&^%which html color do you wish the sky was?
1448033496&^%krowbar&^%What is your favorite color tea?
1448660232&^%vilmibm&^%hugsgiving > thanksgiving
1449269868&^%vilmibm&^%is there ethical consumption under capitalism
1449698715&^%vilmibm&^%hack the planet (with feels)
1451971379&^%vilmibm&^%let's talk about html & feels | welcome new users!
1452017977&^%vilmibm&^%let's talk about html & feels! | add yrself to the map of townies! http://tilde.town/~bear/where.html

View File

@ -1,5 +1,5 @@
krowbar&^%3&^%16
vilmibm&^%0&^%14
krowbar&^%7&^%17
vilmibm&^%0&^%19
hardmath123&^%0&^%6
joe&^%1&^%1jumblesale
audiodude&^%1&^%0

View File

@ -30,7 +30,7 @@ parser.add_option("-n", "--nick", dest="nick", default='numberwang_bot',
(options, args) = parser.parse_args()
p = inflect.engine()
LIMIT_GUESSING = False
LIMIT_GUESSING = True
MIN_ROUNDS = 5
MAX_ROUNDS = 12
SCORE_FILE = "numberwangscores.txt"

39
Code/python/chatstats.py Normal file
View File

@ -0,0 +1,39 @@
#!/usr/bin/python
import fileinput
import json
import time
import calendar
import shutil
logfile = "/home/jumblesale/Code/irc/log"
outfile = "/home/krowbar/logs/chatStats.json"
userData = {} #hash keyed by "user" that contains a start timestamp, last timestamp, last said string, chat count, letter count, and word count
with open(logfile, "r") as log:
for line in log:
try:
time, user, message = line.split("\t", 3)
time = int(time)
except ValueError:
continue #There are some bad lines in the log file that we'll ignore if we can't parse
if user in userData:
if userData[user]['startTime'] == 0:
userData[user]['startTime'] = time
userData[user]['endTime'] = time
#userData[user]['lastSaid'] = message
userData[user]['lineCount'] += 1
userData[user]['wordCount'] += len(message.split())
userData[user]['charCount'] += len(message)
else: #if they are new
userData[user] = {}
userData[user]['startTime'] = time
userData[user]['endTime'] = time
#userData[user]['lastSaid'] = message
userData[user]['lineCount'] = 1
userData[user]['wordCount'] = len(message.split())
userData[user]['charCount'] = len(message)
with open(outfile + ".tmp", "w") as tmpFile:
tmpFile.write(json.dumps(userData))
shutil.move(outfile + ".tmp", outfile)

View File

@ -0,0 +1,45 @@
<!DOCTYPE html>
<html>
<head>
<title>Who chats and when?</title>
</head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"
charset="utf-8"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1", {packages:["timeline"]});
data = [];
jQuery.getJSON("/~krowbar/data/userData.json", function(json) {
_.forEach(json, function(times, user) {
console.log("~" + user + ":", times.length, "item(s)");
_.forEach(times, function(time) {
d = new Date(0);
d.setUTCSeconds(Number(time));
<!--data.push([user, d.toISOString().slice(11,16), d, d]);-->
data.push([user, d, d]);
})
});
google.setOnLoadCallback(drawChart);
});
function drawChart() {
var container = document.getElementById('timeline');
var chart = new google.visualization.Timeline(container);
var dataTable = new google.visualization.DataTable();
dataTable.addColumn({ type: 'string', id: 'User' });
<!--dataTable.addColumn({ type: 'string', id: 'tooltip' });-->
dataTable.addColumn({ type: 'date', id: 'Start' });
dataTable.addColumn({ type: 'date', id: 'End' });
dataTable.addRows(data);
chart.draw(dataTable);
}
</script>
<body>
<div id="timeline" style="height: 800px;"></div>
</body>
</html>

View File

@ -0,0 +1,26 @@
How do do stuff
Data structure
users["name"]
.talked = array of irc times
.mentioned = array of irc times
DATA DAEMON
* Parse log for nicks that said something
- Populate data structure
* For each line, log the person who talked
- Check if any other person was mentioned
- Only log if it is at least 1 minute past their last chat/reference (maybe
to reduce data size)
* Write to log file
- Same file or dated one?
- Only certain time frames??
* Run daily/hourly?
PRESENTATION
* Select a user name from the drop down
- See a timeline with colored strands of when they spoke and were mentioned
* Something that looks like the Github commit history
* Use D3 for coolness

View File

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<title>IRC chat stats</title>
</head>
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/3.5.6/d3.min.js"
charset="utf-8"></script>-->
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("visualization", "1.1", {packages:["table"]});
data = [];
jQuery.getJSON("/~krowbar/data/chatStats.json", function(json) {
_.forEach(json, function(userData, user) {
data.push([user, new Date(userData.startTime*1000), new Date(userData.endTime*1000),
Number(((userData.endTime - userData.startTime) / 86400).toFixed(2)), userData.lineCount,
userData.wordCount, Number((userData.wordCount / userData.lineCount).toFixed(2)),
userData.charCount, Number((userData.charCount / userData.lineCount).toFixed(2))]);
});
google.setOnLoadCallback(drawTable);
});
function drawTable() {
var dataTable = new google.visualization.DataTable();
dataTable.addColumn('string', 'User');
dataTable.addColumn('datetime', 'Start');
dataTable.addColumn('datetime', 'End');
dataTable.addColumn('number', 'Days Active');
dataTable.addColumn('number', 'Lines');
dataTable.addColumn('number', 'Words');
dataTable.addColumn('number', 'per Line');
dataTable.addColumn('number', 'Characters');
dataTable.addColumn('number', 'per Line');
dataTable.addRows(data);
var table = new google.visualization.Table(document.getElementById('statTable'));
table.draw(dataTable, {showRowNumber: false, width:'80%', height: '60%', sortColumn:2, sortAscending:false});
}
</script>
<body>
<div id="statTable"></div>
</body>
</html>

View File

@ -6,9 +6,10 @@
Links and stuff
<ul>
<li><a href="chatchecker/">Tilde.town IRC Chat checker</a></li>
<li><a href="chatstats/">IRC User Chat Statistics</a></li>
<li><a href="twine2/">Twine 2.0</a></li>
<li><a href="grimoire/app/">Grimoire: The Pathfinder Item Roller</a></li>
<li><a href="https://github.com/RussellChamp/PragmaticDiceBag">Pragmatic Dice Bag</a></li>
<li><a href="https://github.com/RussellChamp/PragmaticDiceBag">Pragmatic Dice Bag: Artsy fartsy guide!</a></li>
</ul>
<h2><a href="chatcloud/">Tilde.town IRC Chat cloud</a></h2>

View File

@ -7,24 +7,24 @@
var self = this;
var adjectives = Array('Bold','Breaking','Brilliant','Crescent','Dark|Darkness','Desert|Desert','Eternal','Evening|Darkness','Final','First','Forever','Glorious','Joyful','July','Last','Libery|Liberty','Magic|Magic','Morning|Morning','Power|Power','Phantom','Present','Roaring|Roar|Scream','Rolling','Sand','Screaming|Roar|Scream','Soaring','Standing|Stand','Star|Star','Twisted','Urgent','Utopian','Valiant');
var adjectives = Array('Bold','Breaking','Brilliant','Crescent','Dark|Darkness','Desert|Desert','Eternal','Evening|Darkness','Final','First','Forever','Glorious','Joyful','July','Last','Liberty|Liberty','Magic|Magic','Morning|Morning','Power|Power','Phantom','Present','Roaring|Roar|Scream','Rolling','Sand','Screaming|Roar|Scream','Soaring','Standing|Stand','Star|Star','Twisted','Urgent','Utopian','Valiant');
var nouns = Array('Action','Alert','Beauty','Claw','Darkness','Dawn','Day','Desert','Envy','Fall','Fist','Flight','Fury','Guard','Hammer','Hand','Honor','Hope','Hurricane','Liberty','Light','Lightning','Magic','Morning','October','Power','Rain','Repose','Roar','Scream','Skull','Sky','Skies','Shield','Stand','Star','Storm','Streak','Strike','Sun','Thunder','Victory','Whisper','Wind','Wrath');
var colors = Array('Black','Blue','Brown','Gray','Green','Indego','Orange','Purple','Rainbow','Red','Scarlet','Silver','Violet','White','Yellow');
var actors = Array('Cobra','Condor','Dragon','Eagle','Guardian','Hawk','Hydra','Jackal','King','Knight','Lady','Lion','Scorpion','Spartan','Titan','Victor','Viking','Warrior');
var mission_grammars = Array(
{chance:30, grammar: 'adj1 + " " + noun1'},
{chance:20, grammar: 'adj1 + " " + actor'},
{chance:10, grammar: 'color + " " + noun1'},
{chance:10, grammar: 'color + " " + actor'},
{chance:10, grammar: 'actor +"\'s " + noun1'},
{chance:10, grammar: 'noun1 + " of the " + noun2'},
{chance:10, grammar: 'noun1 + " of the " + actor'},
{chance:10, grammar: 'actor + " of the " + noun1'},
{chance:10, grammar: 'noun1 + " of " + noun2'},
{chance:10, grammar: 'noun1 + " of " + color + " " + noun2'},
{chance:10, grammar: 'adj1 + " " + noun1 + " and " + adj2 + " " + noun2'},
{chance:3, grammar: '"Attack of the " + actor + "s"'},
{chance:3, grammar: '"Return of the " + actor + "s"'}
{chance:30, grammar: "{adj1} {noun1}"},
{chance:20, grammar: "{adj1} {actor}"},
{chance:10, grammar: "{color} {noun1}"},
{chance:10, grammar: "{color} {actor}"},
{chance:10, grammar: "{actor}'s {noun1}"},
{chance:10, grammar: "{noun1} of the {noun2}"},
{chance:10, grammar: "{noun1} of the {actor}"},
{chance:10, grammar: "{actor} of the {noun1}"},
{chance:10, grammar: "{noun1} of {noun2}"},
{chance:10, grammar: "{noun1} of {color} {noun2}"},
{chance:10, grammar: "{adj1} {noun1} and {adj2} {noun2}"},
{chance:3, grammar: "Attack of the {actor}s"},
{chance:3, grammar: "Return of the {actor}s"}
);
this.getNoun = function(badNouns) {
return _.chain(nouns)
@ -65,7 +65,13 @@ this.getMissionName = function() {
rand -= g.chance;
}
else {
mission += eval(g.grammar);
mission += g.grammar
.replace(/{adj1}/, adj1)
.replace(/{adj2}/, adj2)
.replace(/{noun1}/, noun1)
.replace(/{noun2}/, noun2)
.replace(/{color}/, color)
.replace(/{actor}/, actor);
return mission;
}
}