<?php
// This is the most inefficient piece of shit you will ever see
require_once('Date.php');
$base = getcwd();
$infile = $base . '/iChat Export.txt';
$outdir = $base . '/Converted Transcripts';
$myscreenname = 'theshane100';
$myname = 'Shaun Chapman';
$abort = false;
// Create the output directory if it doesn't exist
if (!file_exists($outdir)) {
mkdir($outdir);
}
$file = file_get_contents($infile);
$lines = explode("
", $file);
$last_alias = '';
foreach ($lines as $line) {
$pieces = explode(" ", $line);
$count = count($pieces);
$valid = false;
if ($count == 5) {
$valid = true;
} elseif ($count == 4) {
// Likely a return
$pieces[4] = "
";
$valid = true;
}
if ($valid) {
$alias = $pieces[0];
$info['sender'] = $pieces[1];
$info['time'] = date('Y-m-d', strtotime($pieces[2])) . "T{$pieces[3]}-05:00";
$info['message'] = $pieces[4];
if ($info['sender'] == $myscreenname) {
$info['alias'] = $myname;
} else {
$info['alias'] = $alias;
}
$alias_arr[$alias][] = $info;
}
}
// Build the dictionary
foreach ($alias_arr as $messages) {
foreach ($messages as $message) {
if (!isset($dictionary[$message['alias']])) {
$dictionary[$message['alias']] = $message['sender'];
} elseif ($dictionary[$message['alias']] != $message['sender']) {
echo "Warning: {$message['alias']} matches with both {$dictionary[$message['alias']]} and {$message['sender']}.
";
//$abort = true;
}
}
}
if ($abort) {
echo "Aborting...
";
exit;
}
// This takes a long time
foreach ($alias_arr as $alias => $messages) {
$last_time = new Date();
$log_num = 0;
foreach ($messages as $message) {
$this_time = new Date($message['time']);
$span = new Date_Span();
$span->setFromDateDiff($last_time, $this_time);
if ((int)$span->toHours() >= 1) {
$last_time = $this_time;
$log_num++;
}
$log_arr[$alias][$log_num][] = $message;
}
}
// Write matched files
foreach ($log_arr as $alias => $logs) {
$matched_folder = "$outdir/Matched";
$not_matched_folder = "$outdir/Not Matched";
if (!file_exists($matched_folder))
mkdir($matched_folder);
if (!file_exists($not_matched_folder))
mkdir($not_matched_folder);
foreach ($logs as $log) {
// Find the other screenname
$screenname = $myscreenname;
foreach ($log as $message) {
if ($message['sender'] != $myscreenname) {
$screenname = $message['sender'];
}
}
if ($screenname != $myscreenname) {
$sn_folder = "$matched_folder/$screenname";
} else {
// Try to match the screenname
if (!empty($dictionary[$alias])) {
$screenname = $dictionary[$alias];
echo "Matched $alias to $screenname.
";
$sn_folder = "$matched_folder/{$dictionary[$alias]}";
} else {
$screenname = '[Unknown]';
echo "Could not find match for $alias.
";
$sn_folder = "$not_matched_folder/$alias";
}
}
if (!file_exists($sn_folder)) {
mkdir($sn_folder);
}
$start_time = $log[0]['time'];
$end_time = $log[count($log) - 1]['time'];
$log_folder = "$sn_folder/$screenname (" . str_replace(':', '.', str_replace('-05:00', '-0500', $start_time)) . ").chatlog";
$log_file = "$log_folder/$screenname (" . str_replace(':', '.', str_replace('-05:00', '-0500', $start_time)) . ").xml";
$output = '';
// Create log folder if it doesn't exist
if (!file_exists($log_folder)) {
mkdir($log_folder);
}
$output .= '<?xml version="1.0" encoding="UTF-8" ?>' . "
";
$output .= "<!-- Converted from iChat Transcript -->
";
$output .= '<chat xmlns="http://purl.org/net/ulf/ns/0.4-02" account="' . $myscreenname . '" service="AIM">';
$output .= '<event type="windowOpened" sender="' . $myscreenname . '" time="' . $start_time . '"/>' . "
";
foreach ($log as $message) {
$output .= '<message sender="' . $message['sender'] . '" time="' . $message['time'] . '" alias="' . $message['alias'] . '">';
$output .= '<div><span style="font-family: Helvetica; font-size: 12pt;">';
$output .= str_replace("
", '', nl2br(htmlspecialchars($message['message'])));
$output .= '</span></div></message>' . "
";
}
$output .= '<event type="windowClosed" sender="' . $myscreenname . '" time="' . $end_time . '"/>' . "
";
$output .= "</chat>
";
// Write to file
file_put_contents($log_file, $output);
}
}
?>
Tag Archive for chat
iChat to Adium Chat Transcript Converter
Growl support for Aquamacs Emacs
;; Growl support ;;; Requires growlnotify, source for which is included in the Growl disk image ;;; Note that the growlnotify --image option is not reliable on OSX 10.5 ;;; see <a href="http://forums.cocoaforge.com/viewtopic.php?f=6&t=17526&p=114069" >http://forums.cocoaforge.com/viewtopic.php?f=6&t=17526&p=114069</a> ;;; Wrapper for growlnotify (defun growl-chat (title message &optional sticky) (interactive "sTitle: sGrowl: ") (shell-command (format "/usr/local/bin/growlnotify %s -m '%s' --appIcon 'Aquamacs Emacs' %s" title message (if sticky "--sticky" "")))) ;;; Sticky notifications (defun growl-chat-sticky (title message) (interactive "sTitle: sGrowl: ") (growl-chat title message t)) ;;; Growl nicknames and highlight words when they are mentioned ;;;; Nickname notifications are sticky (add-hook 'erc-text-matched-hook (lambda (match-type nickuserhost message) (when (and (boundp 'nick) (not (string= nick "ChanServ")) (not (string= nick "services."))) (cond ((eq match-type 'current-nick) (growl-chat-sticky (format "%s said %s" nick (erc-current-nick)) message)) ((eq match-type 'keyword) (growl-chat (format "%s mentioned a Keyword" nick) message))))))
facebook chat
require 'mechanize'
require 'json'
require 'ostruct'
require 'pp'
class FacebookChat
def initialize(email, pass); @email, @pass = email, pass; end
def login
@agent = WWW::Mechanize.new
@agent.user_agent_alias = 'Windows IE 7'
f = @agent.get("http://facebook.com/login.php").forms.first
f.fields.name("email").value = @email
f.fields.name("pass").value = @pass
f.submit
body = @agent.get("http://www.facebook.com/home.php").body
# parse info out of facebook home page
@uid = %r{<a href=".+?/profile.php?id=(d+)" class="profile_nav_link">Profile</a>}.match(body)[1].to_i
@channel = %r{"channel(d+)"}.match(body)[1]
@post_form_id = %r{<input type="hidden" id="post_form_id" name="post_form_id" value="([^"]+)}.match(body)[1]
end
def wait_for_messages
determine_initial_seq_number unless @seq
begin
json = parse_json @agent.get(get_message_url(@seq)).body
end while json["t"] == "continue" # no messages yet, keep waiting
@seq += 1
json["ms"].select{|m| m['type'] == 'msg'}.map do |msg|
info = msg.delete 'msg'
msg['text'] = info['text']
msg['time'] = Time.at(info['time']/1000)
OpenStruct.new msg
end.reject {|msg| msg.from == @uid } # get rid of messages from us
end
def send_message(uid, text)
r = @agent.post "http://www.facebook.com/ajax/chat/send.php",
:msg_text => text,
:msg_id => rand(999999999),
:client_time => (Time.now.to_f*1000).to_i,
:to => uid,
:post_form_id => @post_form_id
end
def buddy_list
json = parse_json(@agent.post("http://www.facebook.com/ajax/presence/update.php",
:buddy_list => 1, :post_form_id => @post_form_id, :user => @uid).body)
json['payload']['buddy_list']['userInfos'].inject({}) do |hash, (uid, info)|
hash.merge uid => info['name']
end
end
private
def determine_initial_seq_number
# -1 will always be a bad seq number so fb will tell us what the correct one is
json = parse_json @agent.get(get_message_url(-1)).body
@seq = json["seq"].to_i
end
def get_message_url(seq)
"http://0.channel#{@channel}.facebook.com/x/0/false/p_#{@uid}=#{seq}"
end
# get rid of initial js junk, like 'for(;;);'
def parse_json(s)
JSON.parse s.sub(/^[^{]+/, '')
end
end
if __FILE__ == $0
fb = FacebookChat.new(ARGV.shift, ARGV.shift)
fb.login
puts "Buddy List:"
pp fb.buddy_list
Thread.abort_on_exception = true
Thread.new do
puts usage = "Enter message as <facebook_id> <message> (eg: 124423 hey man wassup?) or type 'buddy' for buddy list"
loop do
case gets.strip
when 'buddy' then pp fb.buddy_list
when /^(d+) (.+)$/
uid, text = $1.to_i, $2
fb.send_message(uid, text)
else
puts usage
end
end
end
# message receiving loop
loop do
fb.wait_for_messages.each do |msg|
puts "[#{msg.time.strftime('%H:%M')}] #{msg.from_name} (#{msg.from}): #{msg.text}"
end
end
end
chat]
import socket
HOST = '127.0.0.1'# Nome simbolico che rappresenta il nodo locale
PORT = 90007 # Porta non privilegiata arbitraria
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(6)
while 1:
conn, addr = s.accept()
data = conn.recv(1024)
if data=='/quit':
print '...FINE CONNESSIONE CON',addr,'...'
conn.close()
if not data: break
print 'Client',addr,'::. '+data
risp=raw_input('Server::. ')
conn.send(risp)
conn.close()
chat]
# -*- coding: UTF-8 -*-
import socket
def risp():
HOST = '127.0.0.1'
PORT = 90007
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
text=raw_input('Client::. ')
if text=='/quit':
print 'BYE'
s.close()
else:
s.send(text)
data = s.recv(1024)
print 'Server::. ', `data`
s.close()
risp()
risp()
How to join a channel (irc network)
/join #channelname