Booksoup

Booksoup allows you to analyse and traverse your downloaded facebook data, including features such as sentiment analysis and message frequency analysis over time.

Booksoup requires BeautifulSoup4 and TextBlob, and requires matplotlib to run the demo graphs.

Usage

</>code

  1. BookSoup

Basic usage

</>code

  1. from booksoup import BookSoup
  2. me = BookSoup("facebook-data")
  3. # Get a conversation by name
  4. convo = me.load_conversation("Jane Doe")
  5. # Print participants of the conversation
  6. print(convo.participants)
  7. # Print messages in the conversation
  8. for message in convo.messages:
  9. print(message.date, message.timestamp, message.name, message.content)

Interaction frequency

</>code

  1. interaction_freq

</>code

  1. me = BookSoup("facebook-data")
  2. convo = me.load_conversation("John Smith")
  3. times = convo.interaction_freq()

</>code

  1. demo_interaction_frequency.py

Interaction frequency example

Interaction timeline

</>code

  1. interaction_timeline(name)

</>code

  1. me = BookSoup("facebook-data")
  2. convo = me.load_conversation("Lewis, Andrew, Michelle and 4 others")
  3. times = convo.interaction_timeline(me.name)

</>code

  1. demo_interaction_timeline.py

Interaction timeline example

Another example below with one friend over a longer timeline:

Single user example

Sentiment

</>code

  1. Conversation.avg_sentiment(name)Conversation.sentiment_timeline

</>code

  1. convo = me.load_conversation("David Grocer")
  2. # Print the average sentiment of David Grocer in the conversation
  3. print(convo.avg_sentiment("David Grocer"))
  4. # Print the timeline dictionary of my average sentiment in the conversation
  5. print(convo.sentiment_timeline(me.name))

Loading a conversation

A conversation can either be loaded using either the title of the conversation (as in all the previous examples) or the numerical ID of the conversation (the filename of the conversation's html file).

</>code

  1. convo = me.load_conversation(40)

Specifying interval duration

</>code

  1. monthdaymonthinterval

</>code

  1. convo = me.load_conversation("David Grocer", interval="day")

Events

Booksoup can extract and categorise event information. This includes title, description, location, timestamp and a 2-element array containing the latitude and longitude of the event if available.

</>code

  1. me = BookSoup("facebook-data")
  2. events = me.load_all_events()
  3. # Events are organised into attending, maybe, declined and no_reply:
  4. for event in events.attending:
  5. print(event.title, event.description, event.location, event.timestamp, event.latlon)