Code Monkey home page Code Monkey logo

01-twitter-example's Introduction

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) 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
  5. Start the nREPL server

    Start another VM session by opening a new terminal window and run vagrant ssh.

    Navigate to the project folder you just created with cd projects/<your-project-name>.

    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 (status-update) 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.

01-twitter-example's People

Contributors

msch avatar allanberger avatar feychou avatar menreiki avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.