def save_stats(username, save_dir, st, mode="from"): seen = False for s in st: time_parsed = dateutil.parser.parse(s['created_at']) tt = time_parsed.timetuple() uid = '%s.%s' % (s['id'], username) guid, subdir = util.split_to_guid(uid) dir = os.path.join(save_dir, subdir) fname = "%s.lifeentry" % guid full_fname = os.path.join(dir, fname) if not os.path.isfile(full_fname): if not os.path.isdir(dir): os.makedirs(dir) time_float = time.mktime(tt) s['_uid'] = guid s['_timestamp'] = time_float s['_type'] = 'com.twitter' if mode == "from": s['_from'] = { 'type': 'twitter', 'id': urlid(s['user']['screen_name']) } if 'in_reply_to_screen_name' in s and s['in_reply_to_screen_name']: s['_to'] = [ { 'type' : 'Twitter', 'id': urlid(s['in_reply_to_screen_name']) } ] else: s['_from'] = { 'type' : 'twitter', 'id': urlid(s['from_user']) } s['_to'] = [ { 'type' : 'twitter', 'id': urlid(s['to_user']) } ] fout = open(full_fname, 'w') simplejson.dump(s, fout, indent=2) fout.close() print "Written: (%s) %s" % (s['_from']['id'] , full_fname) else: seen = True return seen
def create_osascript(c, uidmapdir, tmpdir, entries): print >> sys.stderr, "tempdir: %s" % tmpdir # group all the froms into a temporary directory of their own frms = {} for (atts,frm,tags) in entries: frmtmp = os.path.join(tmpdir, frm) for att in atts: attdir, attfname = os.path.split(att) dst = os.path.join(frmtmp, attfname) if not os.path.isdir(frmtmp): os.makedirs(frmtmp) if not frms.get(frm, None): frms[frm] = frmtmp os.symlink(att, dst) print >> sys.stderr, "symlink: %s -> %s" % (att,dst) err=False for frm,frmdir in frms.items(): osa = osa_template % (frm, frmdir) p = subprocess.Popen("/usr/bin/osascript", shell=True, stdin=subprocess.PIPE, close_fds=True) p.stdin.write(osa) p.stdin.close() pid, sts = os.waitpid(p.pid, 0) ecode = os.WEXITSTATUS(sts) if ecode != 0: err = True # now retrieve the UIDs we just injected into iPhoto back innames = map(os.path.basename, glob.glob(frmdir + "/*")) for fname in innames: # fname is of form guid.jpg sql = "select uid from SqFileInfo inner join SqFileImage on (SqFileInfo.primaryKey = SqFileImage.primaryKey) inner join SqPhotoInfo on (SqFileImage.photoKey = SqPhotoInfo.primaryKey) where relativePath like \"Originals/%%/%s\"" % fname; c.execute(sql) newuid=None for row in c: if newuid: print >> sys.stderr, "unexpected multiple results in UID query: %s %s" % (newuid, row) exit(1) newuid = row[0] if newuid: # fname is of form guid.jpg, so split out the extension and convert the guid to lifedb origuid = util.split_to_guid(os.path.splitext(fname)[0])[0] # newuid is of form "uuid" so convert it into the lifedb uid format newlifeuid = util.split_to_guid(newuid)[0] fout = open(os.path.join(uidmapdir, newlifeuid), 'w') fout.write(origuid) fout.close() print >> sys.stderr, "UIDMap: %s -> %s" % (newuid, origuid) return err
def main(): save_dir = os.getenv("LIFEDB_DIR") if not save_dir: print >> sys.stderr, "no LIFEDB_DIR in env" exit(1) skype = Skype4Py.Skype() skype.Attach() myHandle = skype.CurrentUserHandle calls = skype.Calls() for call in calls: tt = call.Datetime.timetuple() tstamp = time.mktime(tt) if call.Type == Skype4Py.cltIncomingPSTN or call.Type == Skype4Py.cltOutgoingPSTN: ctype = "PhoneCall" else: ctype = "Skype" m = { '_type' : 'com.skype', '_timestamp' : tstamp, 'duration' : call.Duration, 'type' : call.Type, 'status' : call.Status, '_from' : { 'type' : ctype, 'id' : call.PartnerHandle }, '_to' : [ { 'type' : 'Skype', 'id' : myHandle } ] } if call.Participants: m['participants'] = map(lambda x: x.Handle, call.Participants) uid = "%s.%s.%s" % (call.Id, tstamp, myHandle) guid, subdir = util.split_to_guid(uid) dir = os.path.join(save_dir, subdir) fname = "%s.lifeentry" % guid m['_uid'] = guid full_fname = os.path.join(dir, fname) if not os.path.isfile(full_fname): if not os.path.isdir(dir): os.makedirs(dir) fout = open(full_fname, 'w') simplejson.dump(m, fout, indent=2) fout.close() print "Written: %s" % full_fname
if a == 'sms': mode = 'SMS' elif a== 'call': mode = 'Call' else: usage() if len(args) != 1 or not mode or not save_dir: usage() conn = sqlite3.connect(args[0]) c = conn.cursor() if mode == 'SMS': res = parseSMS(c, uid_prefix) elif mode == 'Call': res = parseCall(c, uid_prefix) for uid in res: guid, output_subdir = util.split_to_guid(uid) output_dir = os.path.join(save_dir, output_subdir) res[uid]['_uid'] = guid full_path = os.path.join(output_dir, "%s.lifeentry" % uid) if not os.path.isdir(output_dir): os.makedirs(output_dir) if not os.path.isfile(full_path): print "+ %s" % full_path fout = open(full_path, 'w') simplejson.dump(res[uid], fout, indent=2) fout.close() def normalize_phone(p): import re if len(p) < 1: return p