Skip to content

Instantly share code, notes, and snippets.

View wilk's full-sized avatar

Vincenzo Ferrari wilk

View GitHub Profile
@wilk
wilk / collector.py
Last active November 10, 2017 19:49
Collector.py
#! ./bin/python3
'''
Collector has the purpose to insert in a MongoDB collection all the cleaned data.
The model is set as follows:
Model {
id: ObjectID,
description: String,
amount: Float,
@wilk
wilk / collector.py
Last active November 10, 2017 19:50
Final testing
# test the collection
collection_counter = 0
collection_amount = 0
cursor = db[DB_COLLECTION_NAME].find()
for document in cursor:
print(document)
collection_amount += document['amount']
collection_counter += 1
assert total_counter == collection_counter
@wilk
wilk / collector.py
Last active November 10, 2017 19:51
Collector core logic
import csv
from datetime import datetime
EXPENSE_ACCOUNT = os.getenv('EXPENSE_ACCOUNT', 'expenses')
INCOME_ACCOUNT = os.getenv('INCOME_ACCOUNT', 'income')
total_counter = 0
total_amount = 0
for filename in csv_files:
filepath = join(CLEANED_FOLDER, filename)
@wilk
wilk / collector.py
Last active September 3, 2017 21:24
Files reading
from os import listdir
from os.path import isfile, join
import json
TAGS_FILE = os.path.abspath(os.getenv('TAGS_FILE', 'config/sample-tags.json'))
# load tags mapping
with open(TAGS_FILE) as json_file:
tags = json.load(json_file)
@wilk
wilk / collector.py
Created September 3, 2017 21:20
DB connection
from pymongo import MongoClient
DB_NAME = os.getenv('DB_NAME', 'collector')
DB_COLLECTION_NAME = os.getenv('DB_COLLECTION_NAME', 'collected')
# mongodb client
client = MongoClient(host=os.getenv('DB_HOST'), port=int(os.getenv('DB_PORT')))
db = client[DB_NAME]
# empty the collected collection
@wilk
wilk / collector.py
Created September 3, 2017 21:18
cleaned folder check
import sys
import os
CLEANED_FOLDER = os.path.abspath(os.getenv('CLEANED_FOLDER', 'cleaned'))
if not os.path.isdir(CLEANED_FOLDER):
print('Launch the cleaner before the collector')
sys.exit()
@wilk
wilk / docker-compose.yaml
Last active November 2, 2017 21:10
Collector service
collector:
# activate the virtualenv before starting the cleaner
command: bash -c "source ./bin/activate && python src/collector.py"
image: data.python3:1
environment:
- CLEANED_FOLDER=cleaned
- TAGS_FILE=config/sample-tags.json
- EXPENSE_ACCOUNT=expenses
- INCOME_ACCOUNT=income
- DB_HOST=mongodb
@wilk
wilk / docker-compose.yaml
Last active November 2, 2017 21:08
Collector service with MongoDB info
collector:
# activate the virtualenv before starting the cleaner
command: bash -c "source ./bin/activate && python src/collector.py"
image: data.python3:1
environment:
- CLEANED_FOLDER=cleaned
- DB_HOST=mongodb
- DB_PORT=27017
- DB_NAME=collector
- DB_COLLECTION_NAME=collected
@wilk
wilk / docker-compose.yaml
Last active November 2, 2017 21:08
MongoDB service
mongodb:
image: mongo:3.4
ports:
- "27017:27017"
volumes:
- db_mongo:/data/db:rw
@wilk
wilk / docker-compose.yaml
Created August 30, 2017 06:07
MongoDB volume
volumes:
db_mongo: