GithubHelp home page GithubHelp logo

kmcelwee / mondrianify-twitter Goto Github PK

View Code? Open in Web Editor NEW
0.0 0.0 0.0 5.42 MB

A twitter bot wrapper for the mondrianify repository

Home Page: https://twitter.com/PietMondrianAI

License: MIT License

Python 100.00%
twitter twitter-bot mondrian twitter-api art-generator

mondrianify-twitter's Introduction

mondrianify-twitter

โš ๏ธ This bot was discontinued.

A Twitter bot wrapper for the mondrianify repository, a pipeline for turning images into paintings by Piet Mondrian. The attached bot (@PietMondrianAI) is deployed to Heroku.

bot.py

A bot class to handle all requests and process the different kinds of tweets we'd like to send:

  • introduction: If a user mentions the bot, it will introduce itself and ask for an image.
  • random: The bot grabs a random image of a random dimension using Unsplash and runs the transformation on the image. It tweets the results.
  • reply_transform: If there is an image in a tweet that mentions this bot, take the first image, apply the Mondrian tranform, and tweet the results.
  • error: If given a blank or undistinct image the clustering algorithms will fail. The bot will respond with a brief explanation of what might have gone wrong.

latest_id.txt

The ID of the last tweet the bot processed. On restart, we can configure what tweet we'd like the bot to continue from. This is referenced in the search "since_id" keyword argument in the search API. Twitter will fetch all tweets that fit our query and occur after (but not including) the given tweet id.

Procfile

The file that runs our Heroku app. The contents are simply python bot.py

Aptfile

A file that helps handle some of the unique dependencies we have with running opencv-python on Heroku.

mondrianify

The submodule that links to the mondrianify repository, which contains all the code necessary to process an image.

Twitter API and rate limits

Given Twitter's rate limits, the bot can only tweet once or twice a minute, with a backlog of about 1000 tweets. More specifically, there are only two unique Twitter API calls used: one to listen for new mentions (via search) and one to update status. In other words, it can process one request per 36 seconds, and the max queue is 1000 tweets.

Local and remote setup

This repo is deployed to Heroku, which simply installs the packages in requirements.txt and launches the bot with python bot.py. However to run a similar bot locally or replicate this repo there are some other configurations you'll have to keep in mind.

Configuring secrets

Twitter requires that you register as a developer in order to interact with their platform and/or request data. (Apply to be a Twitter developer).

For easy local setup, I recommend creating a shell script twitter_secrets.sh to briefly add these variables to your shell, something like:

export CONSUMER_KEY=xxxxxx
export CONSUMER_SECRET=xxxxxx
export ACCESS_TOKEN=xxxxxx
export ACCESS_TOKEN_SECRET=xxxxxx

If deploying to Heroku, you'll need to add these environment variables manually.

Using opencv-python

Using opencv-python (the library used to apply deep learning techniques to our input images) on Heroku requires some additional setup that isn't reflected in the Procfile. Assuming you've properly downloaded and configured heroku for your repository, the following command needs to be run:

heroku buildpacks:add --index 1 heroku-community/apt

The specifics of these packages are referenced in Aptfile

mondrianify-twitter's People

Contributors

kmcelwee avatar

mondrianify-twitter's Issues

Error: list index out of range

Error from unknown line number, but caught in the try/except block in the start method. (Perhaps include full trace back in error handling?)

Simplify logs

If "0 tweets tweeted, 0 tweets to respond to" don't message about it, it removes useful information.

Memory is malfunctioning (!)

Every five hours our so, replies restart. Presumably, this is because the heroku bot restarts and memory is lost. Either pay the $7 for a proper Heroku bot or create a list of IDs that we have already replied to?

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.