<commit_before># myshelf
Batteries-included twitter bot for managing your Goodreads library.

## Build Status
[![Build Status](https://travis-ci.org/mindbat/myshelf.svg?branch=master)](https://travis-ci.org/mindbat/myshelf)

## Using the Bot

You can run the bot either locally or via Heroku to use it to manage your own Goodreads shelves and get recommendations on what you should read next.

### Twitter Access

You'll need to give the bot access to your twitter account. Go to Twitter and create an application for it. You'll need four keys: the Consumer Key and Consumer Secret for the application, and your Access Token and Access Token Secret for the application to access your account.

These four values will need to be set in a few environment variables: TWITTER_APP_KEY, TWITTER_APP_SECRET, TWITTER_USER_TOKEN, TWITTER_USER_SECRET

### Goodreads Access

You'll also need to sign up for the Goodreads API. The application key and secret you get from them will need to be in two different environment variables: GOODREADS_KEY and GOODREADS_SECRET

### Additional Dependencies

The bot will also need access to rabbitmq. It'll assume rabbitmq is running locally, unless you give it a different connection uri in the CLOUDAMQP_URL environment variable.

The bot tracks some state in postgresql. It will assume postgresql is running locally, with a db named myshelf that it can access. You can specify a different connection (hostname, db name, etc) using the DATABASE_URL environment variable.

### Running the Migrations

Myshelf uses migratus to manage its db migrations. Once you've got the postgresql db created and accessible, you'll need to run the migrations so you have the right db schema.

The easiest way to run the migrations is using lein:

    lein migratus migrate

### Running the bot

With all the setup complete, you're ready to run the bot:

     java $JVM_OPTS -cp target/myshelf-standalone.jar clojure.main -m myshelf.twitter

### Bot Commands

Myshelf accepts two commands: add and rank.

To issue the add command, send a tweet that looks like:

     myshelf-bot: add <book-title> by <book-author>

This will trigger the bot to look up the book in Goodreads by the title and author you've given it, and then add that book to your to-read shelf.

If successful, the bot will reply with a tweet that looks like:

     @<your-twitter-handle>: Added <book-author> to to-read

To issue the rank command, send a tweet that looks like:

     myshelf-bot: rank <shelf-name>

This will trigger the bot to pull down all the books you have on the given shelf, and then rank them in order of which ones you should read first. It'll then tweet back with the titles of the top four:

     @<your-twitter-handle>: <title-1>
  		             	       <title-2>
			               <title-3>
			               <title-4>

### Approving the Bot

The first time you run the bot and give it a command, it'll need to get approval from you to access your account in Goodreads.

It'll tweet back with a url for you to hit in your browser. Clicking on the link it tweets should be sufficient.

Once you've approved the bot, it'll store your access token for later use, so you won't have to do it again.

## Using the Library

The core myshelf nses for interacting with the Goodreads API are available in clojars as a separate library.

To use it, in your project.clj, add myshelf as a dependency:

     [myshelf "0.2.1"]
<commit_msg>more code formatting changes<commit_after># myshelf
Batteries-included twitter bot for managing your Goodreads library.

## Build Status
[![Build Status](https://travis-ci.org/mindbat/myshelf.svg?branch=master)](https://travis-ci.org/mindbat/myshelf)

## Using the Bot

You can run the bot either locally or via Heroku to use it to manage your own Goodreads shelves and get recommendations on what you should read next.

### Twitter Access

You'll need to give the bot access to your twitter account. Go to Twitter and create an application for it. You'll need four keys: the Consumer Key and Consumer Secret for the application, and your Access Token and Access Token Secret for the application to access your account.

These four values will need to be set in a few environment variables: TWITTER_APP_KEY, TWITTER_APP_SECRET, TWITTER_USER_TOKEN, TWITTER_USER_SECRET

### Goodreads Access

You'll also need to sign up for the Goodreads API. The application key and secret you get from them will need to be in two different environment variables: GOODREADS_KEY and GOODREADS_SECRET

### Additional Dependencies

The bot will also need access to rabbitmq. It'll assume rabbitmq is running locally, unless you give it a different connection uri in the CLOUDAMQP_URL environment variable.

The bot tracks some state in postgresql. It will assume postgresql is running locally, with a db named myshelf that it can access. You can specify a different connection (hostname, db name, etc) using the DATABASE_URL environment variable.

### Running the Migrations

Myshelf uses migratus to manage its db migrations. Once you've got the postgresql db created and accessible, you'll need to run the migrations so you have the right db schema.

The easiest way to run the migrations is using lein:

    lein migratus migrate

### Running the bot

With all the setup complete, you're ready to run the bot:

     java $JVM_OPTS -cp target/myshelf-standalone.jar clojure.main -m myshelf.twitter

### Bot Commands

Myshelf accepts two commands: add and rank.

To issue the add command, send a tweet that looks like:

     myshelf-bot: add <book-title> by <book-author>

This will trigger the bot to look up the book in Goodreads by the title and author you've given it, and then add that book to your to-read shelf.

If successful, the bot will reply with a tweet that looks like:

     @<your-twitter-handle>: Added <book-author> to to-read

To issue the rank command, send a tweet that looks like:

     myshelf-bot: rank <shelf-name>

This will trigger the bot to pull down all the books you have on the given shelf, and then rank them in order of which ones you should read first. It'll then tweet back with the titles of the top four:

     @<your-twitter-handle>: <title-1>
                             <title-2>
			     <title-3>
			     <title-4>

### Approving the Bot

The first time you run the bot and give it a command, it'll need to get approval from you to access your account in Goodreads.

It'll tweet back with a url for you to hit in your browser. Clicking on the link it tweets should be sufficient.

Once you've approved the bot, it'll store your access token for later use, so you won't have to do it again.

## Using the Library

The core myshelf nses for interacting with the Goodreads API are available in clojars as a separate library.

To use it, in your project.clj, add myshelf as a dependency:

     [myshelf "0.2.1"]

{'fraction_non_alphanumeric': 0.05331391114348143, 'fraction_numerical': 0.002039329934450109, 'mean_word_length': 3.821629213483146, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2668327', 'n_tokens_mistral': 1981, 'n_tokens_neox': 1840, 'n_words': 1033}