Refactor mode and command stuff and fix bug

This is very much still in progress, pull request just for review as I go along.

Ultimate aim is to fix https://github.com/scraperwiki/twitter-search-tool/issues/19, am taking chance to refactor code.

- [x] Get rid of global variables in twsearch.py
- [x] Split main code into obvious functions (one for clear data, set mode, set crontab, diagnostics)
- [x] Make mode setting do nothing else but update the mode field in database and exit
- [x] Add flock or similar to stop main scrape part running twice concurrently
- [x] Fix the actual original bug (remove backlog-cleared mode)
- [x] Doesn't make the crontab when you restart monitoring
- [x] Truncation of max_id (some id_str badness)
- [x] Make sure Javascript reads mode correctly
- [x] UI shows wrong thing when first converted to new code, without running twsearch.py
- [x] Actually test it all
- [ ] Notify this user when it works https://app.intercom.io/apps/63b0c6d4bb5f0867b6e93b0be9b569fb3a7ab1e3/conversations/363013245