Skip to content

Commit ed0dcc4

Browse files
committed
V1: Initial version
Replaced Django+MySQL with Tornado+ES
1 parent fc79d4d commit ed0dcc4

File tree

113 files changed

+4250
-5327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+4250
-5327
lines changed

.coveragerc

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[run]
2+
omit =
3+
tests*
4+
branch = True
5+
source =
6+
politicos_api
7+
collector
8+
9+
[report]
10+
exclude_lines =
11+
pragma: no cover
12+
def __repr__
13+
raise NotImplementedError
14+
if __name__ == .__main__.:
15+
from urllib.parse import parse_qs
16+
except ImportError:

.editorconfig

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
trim_trailing_whitespace = true
7+
8+
[Makefile]
9+
indent_style = tab
10+
indent_size = 4
11+
12+
[*.html]
13+
indent_size = 2
14+
15+
[*.css]
16+
indent_size = 2
17+
18+
[*.json]
19+
indent_size = 2
20+
insert_final_newline = ignore

.gitignore

+3-4
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ report.html
5858
# VIM
5959
*.swp
6060

61-
# settings
62-
local.config
63-
64-
logs
61+
# Coverage
62+
.coverage
63+
htmlcov/

.travis.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
language: python
22

3+
before_install:
4+
- curl -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.4.2.deb
5+
- sudo dpkg -i --force-confnew elasticsearch-6.4.2.deb
6+
- sudo /etc/init.d/elasticsearch start
7+
- until curl --silent -XGET --fail http://localhost:9200; do printf '.'; sleep 1; done
8+
- sudo apt-get install redis-server
9+
310
python:
4-
- "2.7"
11+
- "3.6"
512

613
env:
714
matrix:
815
- TEST_TYPE=lint
16+
- TEST_TYPE=unit
917

1018
install:
1119
- make setup

AUTHORS

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Marcelo Jorge Vieira

Dockerfile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM python:3.7
2+
3+
RUN apt-get update && \
4+
apt-get -y install libcurl4-openssl-dev build-essential libssl-dev
5+
6+
RUN mkdir -p /usr/share/politicos-api
7+
WORKDIR /usr/share/politicos-api
8+
9+
COPY . /usr/share/politicos-api
10+
RUN pip install --no-cache-dir -r /usr/share/politicos-api/requirements.txt

Makefile

100644100755
+25-21
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
1-
setup:
2-
@pip install -U --process-dependency-links -e .\[tests\]
3-
41
run:
5-
@python manage.py runserver 0.0.0.0:8000
6-
7-
data:
8-
@python manage.py migrate
9-
10-
initial_data:
11-
@python manage.py countries
12-
@python manage.py states
13-
@python manage.py ethnicity
14-
@python manage.py education
15-
@python manage.py political_party
16-
@python manage.py mandate_event_type
17-
@python manage.py political_office
18-
@python manage.py institutions
19-
@python manage.py elections
2+
@python server.py
203

21-
clean_pycs:
22-
@find . -name "*.pyc" -delete
4+
setup:
5+
@pip install -r requirements.txt -r requirements_dev.txt
6+
7+
setup-prod:
8+
@pip install -r requirements.txt
239

2410
lint:
2511
@flake8
2612

13+
test: coverage lint
14+
15+
unit:
16+
@coverage run --branch `which nosetests` -vv --with-yanc -s tests
2717

28-
.PHONY: initial_data clean_pycs setup run
18+
focus:
19+
@coverage run --branch `which nosetests` -vv --with-yanc --with-focus -s tests
20+
21+
coverage: unit
22+
@coverage report -m
23+
24+
coverage-html: coverage
25+
@coverage html
26+
27+
collect:
28+
@python collector.py
29+
30+
clean_pycs:
31+
@find . -name "*.pyc" -delete
32+
@find . -type d -name __pycache__ -delete

README.md

+77-27
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,102 @@
1-
# Politicos API [![Build Status](https://secure.travis-ci.org/olhoneles/politicos.png?branch=master)](https://travis-ci.org/olhoneles/politicos)
1+
# Politicos API [![Build Status][build-status]][travis]
22

3-
Aqui você vai encontrar os dados, ferramentas e recursos para realizar pesquisas, desenvolver aplicativos, visualizações de dados, e muito mais.
3+
Aqui você vai encontrar os dados, ferramentas e recursos para realizar
4+
pesquisas, desenvolver aplicativos, visualizações de dados e muito mais.
45

56

67
## Instalação
78

8-
1. Clone o repositório:
9+
Temos duas formas para rodar o projeto, via [docker compose][docker-compose] ou
10+
instalando as dependências manualmente.
911

10-
git clone https://github.com/olhoneles/politicos.git
12+
### Clone o repositório:
1113

12-
1. Crie um [*virtualenv*](http://virtualenvwrapper.readthedocs.org/en/latest/install.html):
14+
```
15+
git clone https://github.com/olhoneles/politicos.git
16+
```
1317

14-
cd politicos
15-
mkvirtualenv politicos
18+
### Docker Compose
1619

17-
1. Instale as dependências:
20+
#### Subindo o projeto
1821

19-
make setup
22+
```
23+
cd politicos
24+
docker-compose up
25+
```
2026

21-
1. Crie o banco de dados:
27+
#### Para coletar os dados do TSE:
2228

23-
make data
29+
```
30+
make collect
31+
```
2432

25-
1. Inicialize o projeto:
33+
#### Para visualizar os dados:
2634

27-
make run
35+
Abra seu navegador e entre no endereço http://localhost:8888
2836

29-
1. Se você quiser sobrescrever algumas configurações do settings.py, como SECRET_KEY, DATABASES, ALLOWED_HOSTS, por favor crie o arquivo `politicos/local.config`.
37+
### Manualmente
3038

39+
#### Crie um [*virtualenv*][virtualenv]:
40+
41+
```
42+
cd politicos
43+
mkvirtualenv politicos
44+
```
45+
46+
#### Instale as dependências (python):
47+
48+
```
49+
make setup
50+
```
51+
52+
#### Instale o ElasticSearch e o Redis
53+
54+
55+
* [ElasticSearch][elasticsearch]
56+
* [Redis][redis-server]
57+
58+
#### Para coletar os dados do TSE:
59+
60+
```
61+
make collect
62+
```
63+
64+
#### Inicialize o projeto:
65+
66+
```
67+
make run
68+
```
69+
70+
Abra seu navegador e entre no endereço http://localhost:8888
3171

3272
## Como Contribuir
3373

34-
Participe da [lista de email](http://listas.olhoneles.org/cgi-bin/mailman/listinfo/montanha-dev) e também via IRC no canal [#olhoneles](irc://irc.freenode.net:6667/olhoneles) na Freenode.
74+
Participe da [lista de email][lista] e também via IRC no canal
75+
[#olhoneles][freenode] na Freenode.
3576

3677
Faça uma cópia do repositório e envie seus pull-requests.
3778

3879

3980
## Licença
4081

41-
This program is free software: you can redistribute it and/or modify
42-
it under the terms of the GNU Affero General Public License as published by
43-
the Free Software Foundation, either version 3 of the License, or
44-
(at your option) any later version.
45-
46-
This program is distributed in the hope that it will be useful,
47-
but WITHOUT ANY WARRANTY; without even the implied warranty of
48-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49-
GNU Affero General Public License for more details.
50-
51-
You should have received a copy of the GNU Affero General Public License
52-
along with this program. If not, see <http://www.gnu.org/licenses/>.
82+
This program is free software: you can redistribute it and/or modify it under
83+
the terms of the GNU Affero General Public License as published by the Free
84+
Software Foundation, either version 3 of the License, or (at your option) any
85+
later version.
86+
87+
This program is distributed in the hope that it will be useful, but WITHOUT ANY
88+
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
89+
PARTICULAR PURPOSE. See the GNU Affero General Public License for more
90+
details.
91+
92+
You should have received a copy of the GNU Affero General Public License along
93+
with this program. If not, see <http://www.gnu.org/licenses/>.
94+
95+
[virtualenv]: http://virtualenvwrapper.readthedocs.org/en/latest/install.html
96+
[lista]: http://listas.olhoneles.org/cgi-bin/mailman/listinfo/montanha-dev
97+
[freenode]: irc://irc.freenode.net:6667/olhoneles
98+
[build-status]: https://secure.travis-ci.org/olhoneles/politicos.png?branch=master
99+
[travis]: https://travis-ci.org/olhoneles/politicos
100+
[docker-compose]: https://docs.docker.com/compose/install/
101+
[elasticsearch]: https://www.elastic.co/downloads/elasticsearch
102+
[redis-server]: https://redis.io/download

apache.example.conf

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# a2enmod lbmethod_byrequests proxy proxy_balancer proxy_http ssl
2+
3+
<VirtualHost *:80>
4+
ProxyRequests off
5+
ServerName politicosapi.localdomain
6+
7+
<Proxy balancer://mycluster>
8+
BalancerMember http://localhost:8000
9+
BalancerMember http://localhost:8001
10+
BalancerMember http://localhost:8002
11+
BalancerMember http://localhost:8003
12+
13+
# Security "technically we aren't blocking anyone but this is
14+
# the place to make those changes.
15+
Require all granted
16+
# In this example all requests are allowed.
17+
18+
# Load Balancer Settings
19+
# We will be configuring a simple Round Robin style load
20+
# balancer. This means that all webheads take an equal share
21+
# of of the load.
22+
ProxySet lbmethod=byrequests
23+
24+
</Proxy>
25+
26+
# balancer-manager
27+
# This tool is built into the mod_proxy_balancer module and will allow
28+
# you to do some simple modifications to the balanced group via a gui
29+
# web interface.
30+
<Location /balancer-manager>
31+
SetHandler balancer-manager
32+
# I recommend locking this one down to your your office
33+
Require host politicosapi.localdomain
34+
35+
</Location>
36+
37+
# Point of Balance
38+
# This setting will allow to explicitly name the the location in the
39+
# site that we want to be balanced, in this example we will balance "/"
40+
# or everything in the site.
41+
ProxyPass /balancer-manager !
42+
ProxyPass / balancer://mycluster/
43+
</VirtualHost>

collector.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
#
4+
# Copyright (c) 2018, Marcelo Jorge Vieira <[email protected]>
5+
#
6+
# This program is free software: you can redistribute it and/or modify it
7+
# under the terms of the GNU Affero General Public License as published by the
8+
# Free Software Foundation, either version 3 of the License, or (at your
9+
# option) any later version.
10+
#
11+
# This program is distributed in the hope that it will be useful, but WITHOUT
12+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License
14+
# for more details.
15+
#
16+
# You should have received a copy of the GNU Affero General Public License
17+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
19+
import logging
20+
21+
from collector.tse import TSE
22+
from collector.tse_headers import year_headers
23+
24+
25+
# FIXME
26+
FILES_DIR = '/home/metal/Downloads/blah'
27+
28+
29+
def main():
30+
FORMAT = '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
31+
logging.basicConfig(format=FORMAT, level=logging.INFO)
32+
# mute elasticsearch INFO logs
33+
log = logging.getLogger('elasticsearch')
34+
log.setLevel('ERROR')
35+
36+
for year in year_headers.keys():
37+
tse = TSE(year, path=FILES_DIR)
38+
tse.download_and_extract(remove_tmp_dir=False, remove_zip=False)
39+
tse.all_candidates()
40+
41+
42+
if __name__ == '__main__':
43+
main()
File renamed without changes.

0 commit comments

Comments
 (0)