This repository has been archived by the owner on Sep 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from datasciencebr/irio-facebook-messenger
Make code ready to Digital Ocean
- Loading branch information
Showing
19 changed files
with
278 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Configure SSH access | ||
# source: https://www.digitalocean.com/community/tutorials/initial-server-setup-with-ubuntu-16-04 | ||
# | ||
# ---------- | ||
|
||
useradd -ms /bin/bash serenata_de_amor | ||
git clone --recursive https://github.com/datasciencebr/whistleblower.git /home/serenata_de_amor/whistleblower | ||
chown -hR serenata_de_amor /home/serenata_de_amor/whistleblower | ||
|
||
# Setup auto restart services after VM restart | ||
cat >/home/serenata_de_amor/server.sh <<EOL | ||
touch /home/serenata_de_amor/running.txt | ||
sudo -u serenata_de_amor bash << EOF | ||
cd /home/serenata_de_amor/whistleblower | ||
nohup docker-compose -f docker-compose.yml up & | ||
EOF | ||
EOL | ||
(crontab -l ; echo "@reboot /home/serenata_de_amor/server.sh") | sort - | uniq - | crontab - | ||
|
||
# Install Docker | ||
# source: https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04 | ||
|
||
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - | ||
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | ||
sudo apt-get update | ||
apt-cache policy docker-ce | ||
sudo apt-get install -y docker-ce | ||
sudo systemctl status docker | ||
sudo usermod -aG docker serenata_de_amor | ||
|
||
# Install Docker Compose | ||
# source: https://www.digitalocean.com/community/tutorials/how-to-install-docker-compose-on-ubuntu-16-04 | ||
sudo curl -o /usr/local/bin/docker-compose -L "https://github.com/docker/compose/releases/download/1.11.2/docker-compose-$(uname -s)-$(uname -m)" | ||
sudo chmod +x /usr/local/bin/docker-compose | ||
|
||
# Missing: .env file and environment-specific docker-compose.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: "3" | ||
services: | ||
mongo: | ||
ports: | ||
- 27017:27017 | ||
|
||
rabbitmq: | ||
ports: | ||
- 5672:5672 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
amqp==2.1.4 | ||
celery==4.0.2 | ||
amqp==2.2.2 | ||
celery==4.1.0 | ||
ipdb==0.10.3 | ||
ipython==6.1.0 | ||
pandas==0.19.2 | ||
pymongo==3.4.0 | ||
python-twitter==3.2.1 | ||
serenata-toolbox==12.0.4 | ||
pandas==0.21.0 | ||
pymongo==3.5.1 | ||
python-twitter==3.3 | ||
requests==2.18.4 | ||
serenata-toolbox==12.2.2 |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
from unittest import TestCase, mock | ||
|
||
import pandas as pd | ||
|
||
from whistleblower.queue import Queue as subject_class | ||
|
||
|
||
class TestQueue(TestCase): | ||
def setUp(self): | ||
self.database = mock.MagicMock() | ||
self.subject = subject_class(self.database) | ||
|
||
@mock.patch('whistleblower.queue.Suspicions') | ||
@mock.patch('whistleblower.queue.Twitter') | ||
def test_update(self, twitter_mock, suspicions_mock): | ||
suspicions = pd.DataFrame([pd.Series({'document_id': 1})]) | ||
twitter_mock.return_value.post_queue.return_value.sample.return_value = suspicions | ||
self.subject.update() | ||
self.database.queue.delete_many.assert_called_once_with({}) | ||
self.database.queue.create_index.assert_called_once_with('document_id', unique=True) | ||
self.database.queue.insert_many.assert_called_once_with( | ||
list(self.subject.remaining_posts()), ordered=False) | ||
|
||
@mock.patch('whistleblower.queue.whistleblower.tasks.publish_reimbursement') | ||
def test_process(self, publish_reimbursement_mock): | ||
reimbursement = {'document_id': 10} | ||
self.database.queue.find_one_and_delete.return_value = reimbursement | ||
self.subject.process() | ||
publish_reimbursement_mock.assert_called_once_with(reimbursement) | ||
|
||
@mock.patch('whistleblower.queue.Suspicions') | ||
@mock.patch('whistleblower.queue.Twitter') | ||
def test_remaining_posts(self, twitter_mock, suspicions_mock): | ||
suspicions = pd.DataFrame([pd.Series({'document_id': i}) for i in range(1, 5)]) | ||
suspicions_mock.return_value.all.return_value = suspicions | ||
twitter_mock.return_value.post_queue.return_value.sample.return_value = suspicions.head(2) | ||
response = [post for post in self.subject.remaining_posts()] | ||
self.assertEqual(suspicions.iloc[0].to_dict(), response[0]) | ||
self.assertEqual(suspicions.iloc[1].to_dict(), response[1]) | ||
|
||
@mock.patch('whistleblower.queue.Suspicions') | ||
def test_reimbursements(self, suspicions_mock): | ||
suspicions = [{'document_id': 10}] | ||
suspicions_mock.return_value.all.return_value = suspicions | ||
self.assertEqual(suspicions, self.subject.reimbursements()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM python:3.6.1 | ||
|
||
WORKDIR /usr/src/app | ||
COPY requirements.txt ./ | ||
RUN pip install -r requirements.txt | ||
|
||
RUN useradd -ms /bin/bash serenata_de_amor | ||
RUN chown -hR serenata_de_amor . | ||
USER serenata_de_amor | ||
|
||
COPY server.py ./ | ||
CMD flask run --host=0.0.0.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
flask==0.12.2 | ||
pymongo==3.4.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import http.client | ||
import os | ||
|
||
from flask import Flask | ||
from pymongo import MongoClient | ||
|
||
MONGO_URL = os.environ.get('MONGO_URL', 'mongodb://mongo:27017/') | ||
MONGO_DATABASE = os.environ.get('MONGO_DATABASE', 'whistleblower') | ||
DATABASE = MongoClient(MONGO_URL)[MONGO_DATABASE] | ||
app = Flask(__name__) | ||
|
||
|
||
@app.route('/') | ||
def hello_world(): | ||
return 'Hello, World!' | ||
|
||
|
||
# @app.route('/facebook_webhook', methods=['POST']) | ||
@app.route('/facebook_webhook') | ||
def facebook_webhook(): | ||
DATABASE.facebook_webhook.insert(request.form) | ||
return ('', http.client.NO_CONTENT) |
Oops, something went wrong.