Skip to content

lemmings-io/01-twitter-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Twitter Example

A Twitter bot example in Clojure

Step-by-step Tutorial

  1. Make sure you have followed the Lemmings Clojure and Atom Editor setup.

  2. Start a new vagrant session by opening a new terminal window (on Windows you can use Git BASH), navigate to the 'clojure-master' directory you downloaded before which contains the Vagrantfile and run vagrant ssh.

    vagrant ssh

  3. In the VM, change into the projects directory with cd projects/ and start with the tutorial.

    cd projects

  4. "Clone" the Twitter example into your Vagrant environment

    git clone https://github.com/lemmings-io/01-twitter-example.git

    Now change into the twitter example directory:

    cd 01-twitter-example

    cd twitter-example

  5. Start the nREPL server

    Start another VM session by opening a new terminal window (Cmd-T) and run vagrant ssh.

    Navigate to the project folder you just created with cd projects/01-twitter-example.

    Start the nREPL server with lein repl :headless :host 0.0.0.0 :port 7888 as described in the Clojure and Atom Editor Setup

    run nREPL server

  6. Open your project in Atom.

    Start Atom and open the folder clojure-master/projects/01-twitter-example as an Atom project.

    There's two things to know about Atom:

    1. Ctrl-P on Windows and Cmd-P on macOS opens a file search. You can use this to jump to any file in your project quickly.

    2. Ctrl-Shift-P on Windows and Cmd-Shift-P on macOS opens the Atom Command Palette. You use it to start the nREPL or enable Autoeval.

  7. Connect to Atom's nREPL.

    Look at the Lemmings Clojure guide for detailled instructions.

    nrepl-connection-successful

  8. Turn on the "Autoeval" feature of Proto Repl:

    Open the core.clj file in Atom, then open Atom command palette and search for "Proto Repl: Autoeval file" and press return.

    Hint: You can find the core.clj file in src/twitter_example/core.clj, but if you press Ctrl-P on Windows or Cmd-P on macOS you can easily search through all files in your project.

    This feature will take care to synchronize your code in the core.clj file with the Clojure REPL.

  9. Artistic Tweaking

    You can see the lemmings bot in action here.

    However, you probably want to personalise your tweets now :)

    In your core.clj you'll find two lists: templates (the skeleton of your tweets) and blanks (the strings you'll fill the blanks with). You can replace these strings with your own, just remember to keep the ___.

    You can test the generated sentences in your REPL following these steps:

    • Run (ns twitter-example.core) to initialize your app's namespace in the nREPL.

      repl-ns

    • Run (generate-sentence).

    • Be amazed by your bot's creativity!

  10. Let's bring it to life! Provide your Twitter API tokens for local development by creating a file called profiles.clj in 01-twitter-example with Atom.

    You can find instructions for signing up for Twitter and getting these tokens in the Twitter Bot example in the section Hooking the bot up to Twitter.

    {:dev {:env {:app-consumer-key "<REPLACE>"
                 :app-consumer-secret "<REPLACE>"
                 :user-access-token "<REPLACE>"
                 :user-access-secret "<REPLACE>"}}}

    profiles.clj

  11. Test if your bot tweets in Atom's nREPL

    Run (ns twitter-example.core) to initialize your app's namespace in the nREPL.

    Then run (tweet-sentence) in the nREPL to send a status update through your twitter account.

    tweet via repl twitter tweet

  12. Start the twitter bot inside Vagrant:

    In the Terminal where you are connected to Vagrant (vagrant ssh) run lein trampoline run to start a Clojure system that will tweet every 2 hours.

Credit

This example is based on the Twitter Bot Example in Clojure by Carin Meier.

License

Copyright © 2017

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

About

A Twitter Bot Example in Clojure

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •