Skip to content

Instantly share code, notes, and snippets.

@kanazux
Last active August 29, 2015 14:27
Show Gist options
  • Save kanazux/630e439200f1150e1070 to your computer and use it in GitHub Desktop.
Save kanazux/630e439200f1150e1070 to your computer and use it in GitHub Desktop.
Create files for conversations on facebook backup
#!/usr/local/bin/python
# -*- coding: UTF-8 -*-
#
# kanazuchi <[email protected]>
#
import re
import sys
import bs4
from urllib2 import urlopen
read_index = bs4.BeautifulSoup(urlopen('file:///home/kanazuchi/facebook_backup/html/messages.htm').read())
conv_threads = [ x for x in read_index.findAll('div') if 'class' in x.attrs and 'thread' in x.attrs['class'] ]
for idx, conv in enumerate(conv_threads):
nome = "_".join([ x for x in re.sub(r'\ |,', '_', b[idx].next.encode('UTF-8')).split('__') if 'Dann' not in x ])
new_list = []
try:
for line in conv:
new_list.append(line)
new_list.reverse()
order_name_conv = []
for line in new_list:
remove_html = filter(None, re.split(r'<[^>]+>|\[|\]',line.encode('UTF-8')))
if len(remove_html) == 1:
order_name_conv.append("<p style='color: red'>{}</p>".format(w[0]))
else:
order_name_conv.append("<p style='color: blue'>{}</p>".format("\t\t| ".join([w[0],w[1]])))
if len(order_name_conv) == 2:
print >> open('nomes/{}.html'.format(nome), 'a'), "\n".join([order_name_conv[1],order_name_conv[0]])
order_name_conv = []
except Exception, error:
print error
print sys.exc_info()[0]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment