It started with reading Quinn Norton (https://medium.com/@quinnnorton/context-collapse-architecture-and-plows-d23a0d2f7697) on one (incomplete) way of dealing with trolls.
The best technical approach for Twitter abuse I’ve heard of is Ella Saitta’s suggestion of subscribe-able block lists, which could be very like normal lists, but which would make sure you never see the sort of people your friends block. Trolls could shout all they wanted; no one of relevance would be able to see them. It would be a way to never manage to wander into the wrong neighborhood.
After my “cool down period” of a couple weeks, I still wanted to build it, so here goes.
TL;DR: Trying to write this communal blocklist in public here: https://github.com/tonyhschu/communal-blocklist/tree/master
(Here be boring designer-poking-at-dev-tutorials diary)
430ish: Starting with Heroku: https://devcenter.heroku.com/articles/getting-started-with-python-o
5pm-ish: Using Postgres for data storage with Flask: http://blog.y3xz.com/blog/2012/08/16/flask-and-postgresql-on-heroku
5:20ish: Ran into an issue with psychopg2 which is some sort of ORM thing that makes it easier to talk to databases? (update 6:01pm: not sure I need this?)
5:30ish: Started this blogpost.
5:39pm: Downloaded: http://postgresapp.com/ - to run postgres locally, via: https://devcenter.heroku.com/articles/heroku-postgresql
5:45pm: Postgres app
5:47pm: But “$ which psql" doesn’t work…
5:57pm: Oh so you need to put “psql” on your path, which involves adding a line to your .bash_profile file. This is why setting up programming environments is a pain, and unfriendly to non-programmers (or, really, even programmers) … but see: http://postgresapp.com/documentation/cli-tools.html
”$ which psql” now responds with “/Applications/Postgres.app/Contents/Versions/9.3/bin/psql”
Where was I? …
6:02pm: “$ psql -h localhost” opens a command line interface to … something. I guess I have a postgres thing running now.
6:04pm: Oh cool “$ pip install psycopg2" works now, because I have Postgres set up? That would make sense.
Don’t forget to “$ pip freeze > requirements.txt”
Where was I before this postgres business?
6:10pm: The next step appears to be setting ups sqlalchemy to magically talk to local postgres or heroku postgres depending on whether it’s running in development mode locally, or on production in heroku.
So I guess I have to “$ heroku create" first.
Creating quiet-servername-1234… done, stack is cedar
http://quiet-servername-1234.herokuapp.com/ | firstname.lastname@example.org:quiet-servername-1234.git
Git remote heroku added
6:20pm: Ok, so I “attach” a DB to my heroku instance thing, like so “$
heroku addons:add heroku-postgresql:dev”
Adding heroku-postgresql:dev on quiet-servername-1234… done, v5 (free)
Attached as HEROKU_POSTGRESQL_COPPER_URL
Database has been created and is available
! This database is empty. If upgrading, you can transfer
! data from another database with pgbackups:restore.
Use `heroku addons:docs heroku-postgresql` to view documentation.
Once the database is setup we should promote it such that the
DATABASE_URLenvironment variable will be set:
$ heroku pg:promote HEROKU_POSTGRESQL_COLOR
What does promoting even mean?!
6:32pm: Continuing to follow y3xz’s tutorial … but what about connecting to a localhost postgres when I’m developing?
6:37pm: The beginning of an answer is here: http://beatofthegeek.com/2013/04/how-to-setup-postgresql-python-flask.html
Now we have the database URI. We need to access it in the database. We can do this by simply accessing the $DATABASE_URL environment variable. This is how to do it with a flask app.
SQLALCHEMY_DATABASE_URI = os.environ.get(“DATABASE_URL”,”postgresql://pguser:password/dbname”)
This has an extra hack for accessing the local database. It loads heroku database url in heroku and local url in local dev environment. You obviously need to modify it with your local setup.
but how do I not store my config stuff in source code?
6:40pm: apparently, Heroku config vars: https://devcenter.heroku.com/articles/getting-started-with-python#define-config-vars
6:49pm: Or maybe I don’t need it. “$foreman start” worked with
app.config[‘SQLALCHEMY_DATABASE_URI’] = os.environ.get(“DATABASE_URL”,”postgresql://localhost/communal_blocklist”)
6:50pm: Commit. Break for dinner.
8:00pm: Back. Ok, OAuth with Twitter, hopefully using this: https://github.com/singingwolfboy/flask-dance -
8:05pm: Rabbit hole of Twitter developer docs stuff re: OAuth. Absorbing.
8:12pm: Registered a Twitter Application.
8:19pm: I knew all the pain in setting up Postgres was worth it! Using Postgres to store authentication tokens with flask dance. http://flask-dance.readthedocs.org/en/latest/token-storage.html
8:22pm: Before I forget, I need to set the config vars for with my Twitter app credentials:
heroku config:set TWITTER_KEY=XXXXXXXXXXX TWITTER_SECRET=XXXXXXXXXXXXXXXXXX
8:34pm: Copied/adjusted a bunch of Flask-dance code, tried to run it locally. Ran into an issue where those config variables isn’t set locally. Tangent off to: https://devcenter.heroku.com/articles/config-vars#local-setup
So now I’m setting up a .env file, and put .env in the .gitignore file so I don’t accidentally commit my TWITTER_SECRET.
8:39pm: Let’s see if that works. Yes! The local server started! I got a different error! This counts as a win.
8:59pm: Ok, I think I am truly stuck for now, because I have no idea what this means:
File "/Users/tony_chu/Documents/communal-blocklist/venv/lib/python2.7/site-packages/requests_oauthlib/oauth1_session.py", line 179, in authorized
if self._client.signature_method == SIGNATURE_RSA:
AttributeError: 'OAuth1' object has no attribute 'signature_method'
Opening a Github Issue. We’ll see how this goes.
9:43pm: Make repository public: https://github.com/tonyhschu/communal-blocklist/tree/master, and sent the nice man behind flask-dance a GitHub issue: https://github.com/singingwolfboy/flask-dance/issues/1
Calling it a night.
9:48pm: Or not. Searched for “requests_oauthlib/oauth1_session.py” and found https://github.com/requests/requests-oauthlib/blob/master/requests_oauthlib/oauth1_session.py - where line 179 is different from the stack trace I saw up there. So maybe I just need to get a newer version of requests_oauthlib?
Oh, the same singingwolfboy updated requests_oauthlib 3 days ago: https://github.com/requests/requests-oauthlib/commit/b94f16472d66f5ed0febb8c1985854f379f7bac3#diff-250e01746fa19f7c1e314df65ebf8a0c
Ok, so I don’t feel like a crazy person. This is good.