From 1671c4f3cb24e48f31ec6c64ad9fdc2ed590767f Mon Sep 17 00:00:00 2001 From: Russell Date: Wed, 13 Jun 2018 14:34:23 +0000 Subject: [PATCH] Modified some bots. Added madlib bot. --- Code/irc/banterbot.py | 2 +- Code/irc/madlibbot/another.madlib | 2 + Code/irc/madlibbot/madlib.py | 110 ++++++++++++++ Code/irc/madlibbot/madlib.pyc | Bin 0 -> 3750 bytes Code/irc/madlibbot/madlibbot.py | 232 +++++++++++++++++++++++++++++ Code/irc/madlibbot/madliblog | 1 + Code/irc/madlibbot/msgformatter.py | 16 ++ Code/irc/madlibbot/story.madlib | 2 + Code/irc/run_madlib.sh | 8 + Code/irc/tildescores.txt | 50 ++++--- Code/irc/topics_#tildetown.txt | 7 + Code/irc/topicscores.txt | 4 +- Code/python/chatcloud2.py | 2 +- Code/python/chatstack.py | 55 +++++++ madlibs/haiku.madlib | 3 + madlibs/limerick.madlib | 5 + madlibs/occupation_song.madlib | 4 + madlibs/test_story.madlib | 2 + public_html/chatcloud/index.html | 2 + 19 files changed, 482 insertions(+), 25 deletions(-) create mode 100644 Code/irc/madlibbot/another.madlib create mode 100755 Code/irc/madlibbot/madlib.py create mode 100644 Code/irc/madlibbot/madlib.pyc create mode 100755 Code/irc/madlibbot/madlibbot.py create mode 100644 Code/irc/madlibbot/madliblog create mode 100644 Code/irc/madlibbot/msgformatter.py create mode 100644 Code/irc/madlibbot/story.madlib create mode 100755 Code/irc/run_madlib.sh create mode 100755 Code/python/chatstack.py create mode 100644 madlibs/haiku.madlib create mode 100644 madlibs/limerick.madlib create mode 100644 madlibs/occupation_song.madlib create mode 100644 madlibs/test_story.madlib diff --git a/Code/irc/banterbot.py b/Code/irc/banterbot.py index 901563c..7990cf5 100755 --- a/Code/irc/banterbot.py +++ b/Code/irc/banterbot.py @@ -204,7 +204,7 @@ def get_acronym(channel, text): else: defs = acronymFinder.get_acros(text, True, True) for d in defs[0:5]: #only the first five. they are already sorted by 'score' - ircsock.send("PRIVMSG " + channel + " :" + d + "\n") + ircsock.send("PRIVMSG " + channel + " :" + d.encode('utf-8') + "\n") if len(defs) > 5: ircsock.send("PRIVMSG " + channel + " :" + defs[-1] + "\n") diff --git a/Code/irc/madlibbot/another.madlib b/Code/irc/madlibbot/another.madlib new file mode 100644 index 0000000..f08cc60 --- /dev/null +++ b/Code/irc/madlibbot/another.madlib @@ -0,0 +1,2 @@ +I'm the {{a number}} {{a body part}}, {{another number}} {{another body part}} {{verb ending in -ing}} {{a color}} people eater! +The End diff --git a/Code/irc/madlibbot/madlib.py b/Code/irc/madlibbot/madlib.py new file mode 100755 index 0000000..90068d0 --- /dev/null +++ b/Code/irc/madlibbot/madlib.py @@ -0,0 +1,110 @@ +#!/usr/bin/python + +import glob +import random +import re + +file_pattern = "/home/*/madlibs/*.madlib" +file_regex = re.compile(r'^/home/(.*?)/.*/([^/]*)\.madlib$') +word_regex = re.compile(r'{{(.*?)}}') + +# Take a file path and return a tuple with the title and original path +def munge_story(file_name): + match = re.match(file_regex, file_name) + count = count_words_file(file_name) + return ("'" + match.group(2).replace('_', ' ') + "' by ~" + match.group(1), match.group(0), count) + +# Retrive a list of all madlib story files +def find_stories(limit=999, shuffle=False): + files = glob.glob(file_pattern) + if shuffle == True: + files = random.sample(files, max(1, min(limit, len(files)))) + else: + files = files[:limit] + return map(munge_story, files) + +# Count the number of replacable words in the story +def count_words(story): + return len(word_regex.findall(story)) + +# Count the number of replacable words in the story when given a file path +def count_words_file(storyPath): + with open(storyPath, "r") as storyFile: + story = storyFile.read() + return count_words(story) + +# Get the next replaceable word in the story. Includes full token and just the word +# If you specify rand as True, it will get a random word instead of the next one +def find_next_word(story, rand=False): + matches = list(word_regex.finditer(story)) + if len(matches) == 0: + return None + match = matches[0] + if rand is True: + match = random.choice(matches) + + return (match.group(0), match.group(1)) + +# Replace a word and return the entire story body +def replace_word(story, query, word): + return story.replace(query, word, 1) + #return re.sub(query, word, story, 1) + +# A helper function that will split the story up into chat-printable lengths +def yield_lines(line, max_size): + words = [] + words_length = 0 + # Add words to the words line untill we run out of space + for word in line.split(): + # If the next word itself is longer thatn max_size, we'll have to chop it up + while len(word) > max_size: + splitsize = max_size - words_length - 1 + words.append(word[:splitsize] + "-") + yield ' '.join(words) + words = [] + words_length = 0 + word = word[splitsize:] + if words_length + len(word) + 1 > max_size: + yield ' '.join(words) + words = [] + words_length = 0 + words.append(word) + words_length += len(word) + 1 # For the space + yield ' '.join(words) # For any words left over + +# Open a story file and ask for the parts +def make_story(storyFile): + with open(storyFile, "r") as storyFile: + story = storyFile.read() + match = word_regex.search(story) + while match is not None: + word = raw_input('Give me {}: '.format(match.group(1))) + print "Replacing '{}' with '{}'".format(match.group(0), word) + print story + story = re.sub(match.group(0), word, story, 1) + match = word_regex.search(story) + print story + +def start(): + stories = find_stories(20, True) + if len(stories) == 0: + print "Sorry, no stories found. :/" + return + + input = -1 + while input < 0 or input >= len(stories): + for idx, story in enumerate(stories): + print "[{}] {}".format(idx, story[0]) + input = raw_input("Which story would you like?: ") + try: + # Try to convert the string input into a number + input = int(input) + except: + # If they put something stupid in, treat it as a -1 and ask for + # input again + input = -1 + # Call make_story with the file path of the selected story + make_story(stories[input][1]) + +if __name__ == "__main__": + start() diff --git a/Code/irc/madlibbot/madlib.pyc b/Code/irc/madlibbot/madlib.pyc new file mode 100644 index 0000000000000000000000000000000000000000..99418789e190ac9e818311113693ead219bedc20 GIT binary patch literal 3750 zcmbtXOK;rP6+V~qkVYCkYR9$JCNUiZ^;k(XO^P;w5hMW;#9jnKLj{pxTOLs4m4*_B z9Fd$#6KR41@;*N!o36Sjx(K=tkpIzDSN#Fa_nk{Q3W{!2d3bs5gZG^Cou?cBURqe3 z^Pfag|26Rb2v7MPh8RC1smS9Ow2{Z=V%?L+p2Qd%Vm&!%O5Bih9B5rkn>uYv+>+6KKALb+5U+<5?I8AoT{`y8u`Ph8sc6%G^AKvS4 ztoM6Qp7nRu?>(*0yk2&2==4HQ*~jH@~Q ze4K`n?NQ^3KQrBTnFVaJuLF$-LU9?oX57G6j5z}-Mp%)jq$Wv z#PQK2+qZ+V%8O|iQ`Je#HPbc8KfyYpCKQ1{DCh$a1RbLxQa~9fLSwqaL!u9t1bh$> z=vQqT0}5dUhk?8M;j3(ci`exssphF94|zbHOg9zN9)YW<@P3-_RuoZj7>8A5i%fUE zC?*zsfOwe2`AEq!9E|}fB_D++?ww@%POW>7!f`+Z9KtkJnv9Z4!7qoCy}jBbA6VZG4P+SH1ItYLagb$o&E7V&(9@DZjGtJ8H4uD$FLKL!iI71GKil-K~?%=SPeBWboME%6i~P;YZ_3E z+juU;KtxR`1l3d(a}fV+8ES^Kqnbf=hQb@n*IQV^d~JqJ1Vc*>=cU+UR2*D{1h$Yn z&k#09(Q4+J*30%74rIQm*~P^Kvw=dBCS?_@amMhZtH#mwQ1=uzj_jActrGgn5lB3nu{$dK)Cz;|99j1yAz2 zd)s8s3`bq&4CAkq>X;>S%Vj>w&PY_3{SL&>GT*l{b586spH@iPK_eXL;$)_tEpphA z;xAe)VGC4CjOf_3rDMTVhoS{uY_+sM!2wSmJj8tu9s<1sEuQ@HVjDZWrKv3uF1^J2 z=(lhfez*-|);X9a+6-R7Skm_&B!9C0$oi+V`@SX}?dAfFh$P$h@1D-?`o~E%R7!J` zmg?YDd>k-~y1c||OB)u^FnArLnyv_s2T3-bRGN_X@&XA*6H?IN5f0^K*JYA=JNYvW&Rwwjob-!N4qHxia7eDl9BN^xF8 z2T9_S|F7D+6jg;q^@vPf#=wT`8tmWn+VFuj{Og*Aw`v-VWls~-U@!`kY%u7thYJ`c zT36L=gC$J0d`9_b%w~k1qd}lurt7;2X6_`wnj vS8r|fs`p2EJW1^b8ecxH>q5USbcN?PI_;HCr`eh7E_Pa-Uv|2k8(s4weB8`` literal 0 HcmV?d00001 diff --git a/Code/irc/madlibbot/madlibbot.py b/Code/irc/madlibbot/madlibbot.py new file mode 100755 index 0000000..7d71134 --- /dev/null +++ b/Code/irc/madlibbot/madlibbot.py @@ -0,0 +1,232 @@ +#!/usr/bin/python +# http://wiki.shellium.org/w/Writing_an_IRC_bot_in_Python + +# Import some necessary libraries. +import socket +import os +import sys +from optparse import OptionParser +import fileinput +import random +import time +import re +import operator + +import msgformatter +import madlib + +class State: + idle = 0 # When the bot is started and after it has finished a story + thinking = 1 # I intentionally speed throttle this bot so it feels a little more natural + story_selection = 2 # When the bot is waiting for a user input for story selection + word_input = 3 # When the bot is waiting for user input after prompted for a word + +# Globals +MAX_LINE = 80 # The maximum number of characters in a line +MAX_STORIES = 5 # The maximum number of stories a user can pick from +THROTTLE_FACTOR = 1 # A factor by which all sleep event durations will be multiplied +# Allow madlbibbot to run multiple simultaneous stories +state = {} # The current state of the bot +stories = {} # The list of stories available to users +story = {} # The madlib story currently being worked on +nextword = {} # The word that the bot is currently expecting data for + +parser = OptionParser() + +parser.add_option("-s", "--server", dest="server", default='127.0.0.1', + help="the server to connect to", metavar="SERVER") +parser.add_option("-c", "--channel", dest="channel", default='#madlibs', + help="the channel to join", metavar="CHANNEL") +parser.add_option("-n", "--nick", dest="nick", default='madlibbot', + help="the nick to use", metavar="NICK") + +(options, args) = parser.parse_args() + +def resetGlobals(channel=""): + global state + global stories + global story + global nextword + + if channel == "": + state = {} + stories = {} + story = {} + nextword = {} + else: + state[channel] = State.idle + stories[channel] = [] + story[channel] = "" + nextword[channel] = {} + +def get_stories(channel): + global state + global stories + state[channel] = State.thinking + stories[channel] = madlib.find_stories(MAX_STORIES, True) + if len(stories[channel]) == 0: + sendmsg(channel, "Uh oh! There are no stories!") + state[channel] = State.idle + else: + sendmsg(channel, "Here are a couple good stories:") + time.sleep(1 * THROTTLE_FACTOR) + for idx, story in enumerate(stories[channel]): + sendmsg(channel, "[{}] {} ({} words)".format(idx, story[0], story[2])) + time.sleep(0.5 * THROTTLE_FACTOR) + sendmsg(channel, "Please select a story by index:") + state[channel] = State.story_selection + +# Handle user input when the bot is directly addressed +def handle_bot_msg(channel, msg): + global state + global stories + + if channel not in state: + state[channel] = State.idle + + saved_state = state[channel] + state[channel] = State.thinking + time.sleep(1 * THROTTLE_FACTOR) + + # First check if we should quit the current game + if saved_state != State.idle and msg == "!quit": + quit_game(channel) + elif saved_state == State.idle and msg == "startgame": + get_stories(channel) + elif saved_state == State.story_selection: + handle_story_selection(channel, msg) + elif saved_state == State.word_input: + handle_story_step(channel, msg) + else: + state[channel] = State.idle + +# Handle how to quit the game +def quit_game(channel): + resetGlobals(channel) + sendmsg(channel, "Ok, quitting the current game.") + +# Handle user input when we are in story selection mode +def handle_story_selection(channel, msg): + global stories + global state + try: + imsg = int(msg) + if imsg < 0 or imsg > len(stories[channel]): + sendmsg(channel, "Selection out of bounds. Try again!") + return + time.sleep(1 * THROTTLE_FACTOR) + sendmsg(channel, "Give me a second to load up {}".format(stories[channel][imsg][0])) + + with open(stories[channel][imsg][1], "r") as storyFile: + story[channel] = storyFile.read() + stories[channel] = {} # Clear out the saved selectable stories in memory + story_start(channel) + except ValueError: + sendmsg(channel, "Invalid selection. Try again!") + state[channel] = State.story_selection + +# Handle when a story is being started +def story_start(channel): + global story + global state + global nextword + + state[channel] = State.thinking + sendmsg(channel, "Alright! Let's get started!") + nextword[channel] = madlib.find_next_word(story[channel], True) + time.sleep(0.5 * THROTTLE_FACTOR) + sendmsg(channel, "Give me {}:".format(nextword[channel][1])) + state[channel] = State.word_input + +# Handle user input when we have asked the user for input and are expecting a +# response +def handle_story_step(channel, msg): + global state + global story + global nextword + + state[channel] = State.thinking + word = nextword[channel] #madlib.find_next_word(story[channel]) + if word is not None: + story[channel] = madlib.replace_word(story[channel], nextword[channel][0], msg) + time.sleep(1 * THROTTLE_FACTOR) + + nextword[channel] = madlib.find_next_word(story[channel], True) + if nextword[channel] is None: + finish_story(channel) + return + #else + count = madlib.count_words(story[channel]) + sendmsg(channel, "Thanks! Now give me {} ({} words left)".format(nextword[channel][1], count)) + state[channel] = State.word_input + +# Finish the story +def finish_story(channel): + global state + global story + + sendmsg(channel, "Ok, here's the story..."); + sendmsg(channel, '=' * MAX_LINE) + for line in story[channel].splitlines(): + for part in madlib.yield_lines(line, MAX_LINE): + time.sleep(0.4 * THROTTLE_FACTOR) + sendmsg(channel, part) + padlen = (MAX_LINE - 9)/2 + mod = (MAX_LINE - 9) % 2 + sendmsg(channel, '=' * padlen + ' THE END ' + '=' * (padlen + mod)) + + story[channel] = "" + state[channel] = State.idle + +# System things +def ping(): + ircsock.send("PONG :pingis\n") + +def sendmsg(chan , msg): + ircsock.send("PRIVMSG {} :{}\n".format(chan, msg)) + +def joinchan(chan): + ircsock.send("JOIN {}\n".format(chan)) + +def rollcall(channel, botnick): + sendmsg(channel, "Do you like MadLibs? Start a collaborative story by saying '{}: startgame'".format(botnick)) + +def connect(server, channel, botnick): + ircsock.connect((server, 6667)) + ircsock.send("USER {} {} {} :krowbar\n".format(botnick, botnick, botnick)) # user authentication + ircsock.send("NICK {}\n".format(botnick)) + joinchan(channel) + +def listen(botnick): + botmsgre = re.compile('^{}\:?\s*(.*)$'.format(botnick)) # re to strip the bot's name from a message + while 1: + ircmsg = ircsock.recv(2048) + ircmsg = ircmsg.strip('\n\r') + + if ircmsg.find("PING :") != -1: + ping() + + formatted = msgformatter.format_message(ircmsg) + if "" == formatted: + continue + # print formatted + + split = formatted.split("\t") + msgtime = split[0] + user = split[1] + command = split[2] + channel = split[3] + message = split[4] + + if message.startswith("!rollcall") == True or message.startswith("!help") == True: + rollcall(channel, botnick) + elif message.startswith(botnick) == True: + botmsg = botmsgre.match(message).group(1) + handle_bot_msg(channel, botmsg) + + sys.stdout.flush() + time.sleep(1 * THROTTLE_FACTOR) + +ircsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) +connect(options.server, options.channel, options.nick) +listen(options.nick) diff --git a/Code/irc/madlibbot/madliblog b/Code/irc/madlibbot/madliblog new file mode 100644 index 0000000..3eade97 --- /dev/null +++ b/Code/irc/madlibbot/madliblog @@ -0,0 +1 @@ +nohup: failed to run command './madlibbot/madlibbot.py': No such file or directory diff --git a/Code/irc/madlibbot/msgformatter.py b/Code/irc/madlibbot/msgformatter.py new file mode 100644 index 0000000..d438aca --- /dev/null +++ b/Code/irc/madlibbot/msgformatter.py @@ -0,0 +1,16 @@ +import time +import re + +def format_message(message): + pattern = r'^:.*\!~(.*)@.* (.*) (.*) :(.*)' + now = int(time.time()) + matches = re.match(pattern, message) + if not matches: + return '' + + nick = matches.group(1).strip() + command = matches.group(2).strip() + channel = matches.group(3).strip() + message = matches.group(4).strip() + + return "%s\t%s\t%s\t%s\t%s" % (now, nick, command, channel, message) diff --git a/Code/irc/madlibbot/story.madlib b/Code/irc/madlibbot/story.madlib new file mode 100644 index 0000000..e9952a2 --- /dev/null +++ b/Code/irc/madlibbot/story.madlib @@ -0,0 +1,2 @@ +The {{an adjective}}, {{a color}} {{an animal}} jumped over the {{an adjective}} {{a color}} {{an animal}}. +The End diff --git a/Code/irc/run_madlib.sh b/Code/irc/run_madlib.sh new file mode 100755 index 0000000..9ef73ca --- /dev/null +++ b/Code/irc/run_madlib.sh @@ -0,0 +1,8 @@ +#!/bin/bash + +if [[ ! `pidof -sx madlibbot.py` ]]; then + nohup ./madlibbot/madlibbot.py -s 127.0.0.1 -n madlibbot -c \#madlibs >> madliblog 2>> madliblog & + echo "Starting madlibbot" +else + echo "madlibbot has already been started" +fi diff --git a/Code/irc/tildescores.txt b/Code/irc/tildescores.txt index 2916d7d..6d7da72 100644 --- a/Code/irc/tildescores.txt +++ b/Code/irc/tildescores.txt @@ -1,8 +1,8 @@ -krowbar&^%2120&^%1524572882 -karlen&^%476&^%1524572484 +krowbar&^%2209&^%1528899514 +karlen&^%498&^%1527613440 endorphant&^%682&^%1444775660 jumblesale&^%24&^%1426171214 -marcus&^%2545&^%1523553363 +marcus&^%2571&^%1528142058 papa&^%181&^%1474509971 epicmorphism&^%5&^%1421937744 audy&^%83&^%1504564254 @@ -12,7 +12,7 @@ cmr&^%2244&^%1485978592 imt&^%519&^%1424087616 cndorphant&^%788&^%1424094192 rain&^%17&^%1422310975 -sl2c&^%765&^%1524175962 +sl2c&^%769&^%1524856648 selfsame&^%1&^%1422230012 bear&^%424&^%1510759605 coaxial&^%8&^%1422325983 @@ -44,22 +44,22 @@ xkeeper&^%14&^%1461967961 cosnok&^%807&^%1508878859 escobar&^%1&^%1475431401 amicabot&^%30&^%1481225205 -caff&^%990&^%1524015156 +caff&^%1022&^%1528745010 kadin&^%5&^%1479870008 desvox&^%5&^%1481632697 mankins&^%3&^%1480211581 cinch&^%2&^%1480454755 -caffbot&^%933&^%1524015163 +caffbot&^%968&^%1528745018 evilbot&^%4&^%1480693919 tybaltcat&^%7&^%1481076625 minerbot&^%146&^%1520382015 mio&^%339&^%1506434277 archangel&^%464&^%1524447604 -tehfraga&^%252&^%1524036040 +tehfraga&^%263&^%1527511198 sushi&^%10&^%1493253212 -troido&^%177&^%1524564338 -gamebot&^%103&^%1524564349 -nilaky&^%1083&^%1524522303 +troido&^%284&^%1528830675 +gamebot&^%157&^%1528830687 +nilaky&^%1144&^%1528826579 bucket&^%103&^%1507931139 lolbot&^%1&^%1502568407 m455&^%12&^%1512076715 @@ -72,8 +72,8 @@ pinhook&^%8&^%1509744722 emfor&^%3&^%1509671353 k2l8m11n2&^%11&^%1510932395 sacredpix&^%3&^%1522082931 -deltawitc&^%1436&^%1524565071 -login&^%718&^%1524579121 +deltawitc&^%2003&^%1528899800 +login&^%1133&^%1528853906 kelpiebot&^%3&^%1513101957 unreal&^%1&^%1514940020 tildethie&^%3000&^%1521573658 @@ -82,26 +82,34 @@ testgameb&^%2&^%1517405361 erin&^%2&^%1517681999 wuz&^%3&^%1518125300 hashdang&^%4&^%1518666906 -ubergeek&^%41&^%1524236676 +ubergeek&^%63&^%1526043601 silver&^%9&^%1519333029 -equa&^%43&^%1523911663 +equa&^%47&^%1528124305 audiodude&^%2&^%1519453927 jumblesal&^%1&^%1519746512 -whimsy&^%16&^%1523551815 -wangofett&^%59&^%1524257254 +whimsy&^%45&^%1527777458 +wangofett&^%100&^%1528482540 saturn597&^%3&^%1521429369 cwmccabe&^%2&^%1521598124 -lucidiot&^%14&^%1522018847 +lucidiot&^%28&^%1526201925 tracer&^%1&^%1521744878 -jan6&^%201&^%1524583286 +jan6&^%533&^%1528899537 jan&^%10&^%1522319160 etathetae&^%3&^%1522937843 -eeeeeta&^%28&^%1524463842 -cmccabe&^%55&^%1524509916 +eeeeeta&^%31&^%1527704747 +cmccabe&^%66&^%1528506935 jan6_test&^%7&^%1523252589 jan6_&^%8&^%1523641589 carbon&^%9&^%1524135505 ne1&^%7&^%1524024485 -Halian&^%4&^%1524536199 +Halian&^%32&^%1528360263 lunasspec&^%4&^%1524164784 bowlercap&^%3&^%1524165068 +littlebig&^%35&^%1528853503 +severak&^%6&^%1528897303 +ralph&^%4&^%1526980620 +benjaminw&^%69&^%1528849036 +von&^%113&^%1528896624 +ensis&^%150&^%1528817036 +simon&^%26&^%1527937489 +benharri&^%48&^%1528851037 diff --git a/Code/irc/topics_#tildetown.txt b/Code/irc/topics_#tildetown.txt index 63c2638..f14addb 100644 --- a/Code/irc/topics_#tildetown.txt +++ b/Code/irc/topics_#tildetown.txt @@ -243,3 +243,10 @@ 1522845488&^%etathetae&^%What is the best/worst pick up line you have ever heard? 1523919506&^%vilmibm&^%how are you? 1524157985&^%vilmibm&^%feels or gtfo +1524684964&^%vilmibm&^%we restarted, sadly. let ~vilmibm know if anything isn't running that should be. +1525713202&^%vilmibm&^%how is your plant? +1525971188&^%vilmibm&^%want to tell other townies more about yourself? try a ~/.plan or a ~/.project file! run `info finger` to learn more +1526254152&^%vilmibm&^%have you hugged your computer today? +1526577609&^%archangel&^%When you were in grade school, what did you want to be when you grew up? Why? +1526842324&^%vilmibm&^%welcome, wave of new users <3 +1528317036&^%vilmibm&^%what are the feels? diff --git a/Code/irc/topicscores.txt b/Code/irc/topicscores.txt index c062b15..7002fb3 100644 --- a/Code/irc/topicscores.txt +++ b/Code/irc/topicscores.txt @@ -1,4 +1,4 @@ -krowbar&^%5&^%2 +krowbar&^%6&^%2 jan&^%0&^%1vilmibm&^%0&^%1etathetae&^%1&^%0 etathetae&^%0&^%2 -jan6&^%0&^%1vilmibm&^%0&^%1vilmibm&^%0&^%1 \ No newline at end of file +jan6&^%0&^%1vilmibm&^%0&^%1vilmibm&^%0&^%1vilmibm&^%0&^%1vilmibm&^%0&^%1vilmibm&^%0&^%1vilmibm&^%0&^%1archangel&^%0&^%1vilmibm&^%0&^%1vilmibm&^%0&^%1 \ No newline at end of file diff --git a/Code/python/chatcloud2.py b/Code/python/chatcloud2.py index 2c3d22c..bc8ece0 100755 --- a/Code/python/chatcloud2.py +++ b/Code/python/chatcloud2.py @@ -11,7 +11,7 @@ import logging, sys logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) parser = argparse.ArgumentParser(description='Generate word cloud data based off of irc chat logs') -parser.add_argument('-logfile', help='irc log file to read from', default='/home/jumblesale/Code/irc/log') +parser.add_argument('-logfile', help='irc log file to read from', default='/home/archangelic/irc/log') parser.add_argument('-outfile', help='output file to write to', default='') parser.add_argument('-timeend', type=int, help='end time of the word cloud (in epoch time)', default=calendar.timegm(time.gmtime())) diff --git a/Code/python/chatstack.py b/Code/python/chatstack.py new file mode 100755 index 0000000..2480acc --- /dev/null +++ b/Code/python/chatstack.py @@ -0,0 +1,55 @@ +#!/usr/bin/python +import fileinput +import json +import time +import calendar +import shutil + +logfile = "/home/archangelic/irc/log" +#logfile = "/home/jumblesale/Code/irc/log" +outfile = "/home/krowbar/logs/chatStack.json" +chatData = { 'hours': [], 'regions': {} } #hash keyed by "region" and then hour that counts chat instances +#we only care about recent chats, let's say for the past couple weeks +oneHour = 60 * 60 +oneWeek = 7 * 24 * 60 * 60 +timeNow = calendar.timegm(time.gmtime()) +timeCutoff = calendar.timegm(time.gmtime()) - (2 * oneWeek) + +# this will eventually represent each region users are from +def getAllRegions(): + return ['unknown'] + +# this will provide a way to look up what region a user is from +def getRegion(user): + return 'unknown' + +# populate the hours array with time 1 hour away from each other +startTime = timeCutoff +while startTime < timeNow: + chatData['hours'].append(startTime) + startTime += oneHour + +# populate the regions array with blank data for each region +for region in getAllRegions(): + chatData['regions'][region] = { 'name': region, 'values': [0] * len(chatData['hours']) } + +with open(logfile, "r") as log: + hourIdx = 0 # starting with the oldest time slot, we will count instances of user chatting + 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 time > timeCutoff: + region = getRegion(user) + while time > chatData['hours'][hourIdx] + oneHour: # we are past the current hour idx, move ahead until we find the right idx + hourIdx += 1; + if hourIdx >= len(chatData['hours']): + break; #uh oh! somehow we are parsing a line from the future! we're in pretty bad shape! + # hourIdx should now be a good value + chatData['regions'][region]['values'][hourIdx] += 1 # increment the user region's count for the current hour + +with open(outfile + ".tmp", "w") as tmpFile: + tmpFile.write(json.dumps(chatData)) +shutil.move(outfile + ".tmp", outfile) diff --git a/madlibs/haiku.madlib b/madlibs/haiku.madlib new file mode 100644 index 0000000..549517a --- /dev/null +++ b/madlibs/haiku.madlib @@ -0,0 +1,3 @@ +The {{a plural noun (one syllables)}} in {{a place (two syllables)}} / +bring {{something that causes ennui (two sylables)}} to my {{a body part (two syllables)}} / +Will I {{a verb (one syllable)}} again? diff --git a/madlibs/limerick.madlib b/madlibs/limerick.madlib new file mode 100644 index 0000000..8213821 --- /dev/null +++ b/madlibs/limerick.madlib @@ -0,0 +1,5 @@ +There once was a fellow from {{a place (two syllables. rhyming scheme 1)}} +Who frequently was found to be {{an adjective (one syllable. rhyming scheme 1)}} +One {{a time (two syllables)}} while {{an activity or state of being (two syllables. rhyming scheme 2)}} +Was {{a verb (one syllable. past tense)}} by a {{a noun (two syllables, rhyming scheme 2)}} +And never again able to {{a verb (one syllable. rhyming scheme 1)}} diff --git a/madlibs/occupation_song.madlib b/madlibs/occupation_song.madlib new file mode 100644 index 0000000..52f42d7 --- /dev/null +++ b/madlibs/occupation_song.madlib @@ -0,0 +1,4 @@ +Oh! I'm a {{an occupation}} and I'm ok! +I {{a verb}} all {{a time of day}} and I {{a verb}} all {{a time of day}}! +I cut down {{a type of plant or foliage, plural}}, I {{a way to locomote}} and jump, I go to the {{a room in a house}}! +On {{a day of the week}} I go {{a verb ending in -ing}} and have {{an afternoon snack}} for tea! diff --git a/madlibs/test_story.madlib b/madlibs/test_story.madlib new file mode 100644 index 0000000..e9952a2 --- /dev/null +++ b/madlibs/test_story.madlib @@ -0,0 +1,2 @@ +The {{an adjective}}, {{a color}} {{an animal}} jumped over the {{an adjective}} {{a color}} {{an animal}}. +The End diff --git a/public_html/chatcloud/index.html b/public_html/chatcloud/index.html index 9304135..d4e1bc5 100644 --- a/public_html/chatcloud/index.html +++ b/public_html/chatcloud/index.html @@ -4,6 +4,8 @@