{"id":15350496,"url":"https://github.com/takuti/twitter-bot","last_synced_at":"2025-04-15T04:17:53.516Z","repository":{"id":147156698,"uuid":"11314077","full_name":"takuti/twitter-bot","owner":"takuti","description":":ghost: Markov chain-based Japanese twitter bot","archived":false,"fork":false,"pushed_at":"2018-07-12T20:25:38.000Z","size":71,"stargazers_count":13,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-15T04:17:45.175Z","etag":null,"topics":["markov-chain","natural-language-processing","ruby","twitter","twitter-bot"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/takuti.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2013-07-10T14:23:21.000Z","updated_at":"2021-02-18T13:12:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"6219e28f-492a-4ebe-b5fa-f7ac488c2d21","html_url":"https://github.com/takuti/twitter-bot","commit_stats":{"total_commits":110,"total_committers":1,"mean_commits":110.0,"dds":0.0,"last_synced_commit":"2272ec729487127abb2e485424a00011df3b6991"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuti%2Ftwitter-bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuti%2Ftwitter-bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuti%2Ftwitter-bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/takuti%2Ftwitter-bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/takuti","download_url":"https://codeload.github.com/takuti/twitter-bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003986,"owners_count":21196793,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["markov-chain","natural-language-processing","ruby","twitter","twitter-bot"],"created_at":"2024-10-01T11:58:33.693Z","updated_at":"2025-04-15T04:17:53.496Z","avatar_url":"https://github.com/takuti.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Markov-Chain-Based Japanese Twitter Bot\n===\n\n[![Build Status](https://travis-ci.org/takuti/twitter-bot.svg)](https://travis-ci.org/takuti/twitter-bot)\n\n***Since this project is strongly optimized for Japanese, other languages are not supported :sushi:***\n\n## Description\n\n- Generate a tweet based on so-called **Markov Chain** from particular user's tweet history\n- Sample: [@yootakuti](https://twitter.com/yootakuti)\n- My Japanese article: [マルコフ連鎖でTwitter Botをつくりました | takuti.me](http://takuti.me/note/twitter-bot/)\n\n## Installation\n\nIf you want to host this bot directly on your local or server machine, you first need to install Ruby gems:\n\n\t$ gem install bundle\n\t$ bundle install\n\nNote that this application specially depends on [***kusari***](https://github.com/takuti/kusari), a gem for Japanese Markov chain.\n\nNext, you should generate a directory **ipadic/**, the IPA dictionary for Japanese tokenization, as described in the [Igo documentation](http://igo.osdn.jp/index.html#usage).\n\nAdditionally, in order to connect to a Twitter account, the following environment variables need to be appropriately set:\n\n```sh\nexport SCREEN_NAME=yootakuti\n\nexport CONSUMER_KEY=foo\nexport CONSUMER_SECRET=bar\nexport OAUTH_TOKEN=hoge\nexport OAUTH_TOKEN_SECRET=piyo\n```\n\nFYI: we can use [direnv](https://github.com/direnv/direnv) to flexibly configure project-specific environment variables:\n\n\t$ brew install direnv\n\t$ touch .envrc # and write the above `export` statements\n\t$ direnv allow\n\n## Usage\n\nBefore enjoying this bot, you must download your tweet history from [the Twitter setting page](https://twitter.com/settings/account). The downloaded folder must be placed under **/path/to/twitter-bot/data/**, and the bot will use *text* column of **data/tweets/tweets.csv**. Note that this repository contains [sample tweets.csv file](data/tweets/tweets.csv).\n\n### Post on Twitter\n\nAfter setting the environment variables, we can generate and post a markov tweet as:\n\n\t$ ruby lib/post_tweet.rb\n\nIf you just want to check if a markov tweet is generated correctly, `dry-run` option is available.\n\n\t$ ruby lib/post_tweet.rb dry-run\n\n#### Hourly post by cron\n\nSet your crontab as:\n\n\t$ echo \"01 * * * * /usr/local/rvm/wrappers/ruby-2.2.3/ruby /path/to/twitter-bot/lib/post_tweet.rb\" \u003e cron.txt\n\t$ crontab cron.txt\n\nFor more detail of RVM+cron setting: [RVM: Ruby Version Manager - Using Cron with RVM](https://rvm.io/deployment/cron)\n\n#### Build API server\n\nThis repository implements a tiny Sinatra-based API server.\n\nRun:\n\n```sh\n$ bundle exec foreman start # PORT=5000 by default\n```\n\nEventually, http://localhost:5000/ and http://localhost:5000/tweet respectively execute `lib/post_tweet.rb dry-run` and `lib/post_tweet.rb`.\n\nIn case that you publicly build this API server, scheduling a request to `/tweet` would be an alternative choice to periodically post Markov-chain-based tweet.\n\n### Reply daemon\n\n`reply_daemon` tracks tweets which contain `SCREEN_NAME` of your bot and replies to all of them:\n\n\t$ ruby lib/reply_daemon.rb start\n\nStop the process:\n\n\t$ ruby lib/reply_daemon.rb stop\n\n## Docker\n\nYou can easily setup this application as a Docker image:\n\n```sh\n$ docker build -t takuti/twitter-bot\n```\n\nOnce the image has been created, running the scripts in container is straightforward:\n\n```sh\n$ docker run -it takuti/twitter-bot /bin/sh -c \"ruby lib/post_tweet.rb\"\n$ docker run -it takuti/twitter-bot /bin/sh -c \"ruby lib/post_tweet.rb dry-run\"\n```\n\nBy default, container automatically launches the API sever on port 5000 via `bundle exec foreman start`, so you can get access to http://localhost:5000/ once a container started running:\n\n```sh\n$ docker run -it -d -p 5000:5000 takuti/twitter-bot\n```\n\nNotice that, as long as the required environmental variables are properly set in container, http://localhost:5000/tweet also works as we expected.\n\n### Deploy on Heroku\n\nOur Docker image enables us to make the API server public on Heroku:\n\n```sh\n$ heroku create takuti-twitter-bot\n$ heroku container:push web\n```\n\nSee https://takuti-twitter-bot.herokuapp.com/, for example.\n\nWhile https://takuti-twitter-bot.herokuapp.com/tweet currently returns an error, you can make it available by [configuration of variables](https://devcenter.heroku.com/articles/config-vars#setting-up-config-vars-for-a-deployed-application).\n\n### Deploy on Dokku\n\n[Dokku](https://github.com/dokku/dokku) is a Docker-powered OSS PaaS which enables you to build mini-Heroku-like platform on your own server. Similarly to the deployment on Heroku, once you have set up a server with Dokku, the API server can be easily deployed as a Docker image.\n\nServer:\n\n```sh\n$ dokku apps:create twitter-bot\n$ dokku config:set twitter-bot DOKKU_DOCKERFILE_START_CMD=\"bundle exec foreman start\"\n```\n\nNote that setting a way to start running a container to `DOKKU_DOCKERFILE_START_CMD` is important, because Dokku directly [executes a task defined as the `web` process in `Procfile`](http://dokku.viewdocs.io/dokku/deployment/methods/dockerfiles/#procfiles-and-multiple-processes) by default. Consequently, your container launches differently from what `CMD` defines in `Dockerfile`.\n\nLocal:\n\n```sh\n$ cd /path/to/takuti/twitter-bot\n$ git remote add dokku dokku@dokku.example.com:twitter-bot\n$ git push dokku master\n```\n\nEventually, an \"Application deployed\" message shows up on your local screen with corresponding URL, and you can get access to the API server.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakuti%2Ftwitter-bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftakuti%2Ftwitter-bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftakuti%2Ftwitter-bot/lists"}