Commit 3d7c1f4c authored by Rémi FERRAND ⛰'s avatar Rémi FERRAND ⛰
Browse files


parent 2a6ede61
This diff is collapsed.
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) Remi Ferrand <>, 2014
# This software is a computer program whose purpose is to [describe
# functionalities and technical features of your software].
# This software is governed by the CeCILL license under French law and
# abiding by the rules of distribution of free software. You can use,
# modify and/ or redistribute the software under the terms of the CeCILL
# license as circulated by CEA, CNRS and INRIA at the following URL
# "".
# As a counterpart to the access to the source code and rights to copy,
# modify and redistribute granted by the license, users are provided only
# with a limited warranty and the software's author, the holder of the
# economic rights, and the successive licensors have only limited
# liability.
# In this respect, the user's attention is drawn to the risks associated
# with loading, using, modifying and/or developing or reproducing the
# software by the user in light of its specific status of free software,
# that may mean that it is complicated to manipulate, and that also
# therefore means that it is reserved for developers and experienced
# professionals having in-depth computer knowledge. Users are therefore
# encouraged to load and test the software's suitability as regards their
# requirements in conditions enabling the security of their systems and/or
# data to be ensured and, more generally, to use and operate it in the
# same conditions as regards security.
# The fact that you are presently reading this means that you have had
# knowledge of the CeCILL license and that you accept its terms.
import re
import os
......@@ -9,6 +41,7 @@ import logging
import requests
import HTMLParser
from optparse import OptionParser
from prettytable import PrettyTable
# try:
......@@ -58,7 +91,6 @@ class HTTPClient(object):
class FreeAdslBillFetcher(HTTPClient):
......@@ -173,7 +205,6 @@ class FreeAdslBillFetcher(HTTPClient):
class FreeAdslBillFetcherCli(object):
PROG_NAME = 'free_adsl_fetcher'
......@@ -215,6 +246,7 @@ class FreeAdslBillFetcherCli(object):
this.config = this._parseConfigFile(this.options.config_file)
this.fetcher = None
this.table = this._prepareTable()
def __enter__(this, *args, **kwargs):
......@@ -230,12 +262,20 @@ class FreeAdslBillFetcherCli(object):
with open(file) as f:
return json.load(f)
def _prepareTable(this):
headers = ['Month']
if this.options.show_price:
headers.insert(1, 'Price')
pt = PrettyTable(headers)
pt.align['Month'] = 'l'
return pt
def run(this):
fetched_bills = 0
wanted_bills = len(this.options.wanted_bills)
table_output = True if wanted_bills == 0 else False
for bill in this.fetcher.listBills():
bill_filename = this._composeBillFilename(bill)
if this.options.fetch_latest is True:
pdf_path = this._fetchBill(bill)
......@@ -245,18 +285,21 @@ class FreeAdslBillFetcherCli(object):
if wanted_bills > 0:
if bill.title in [x.decode('utf-8') for x in this.options.wanted_bills]:
pdf_path = this._fetchBill(bill)
print "%s bill was written to '%s'" % (bill.title, pdf_path)
print "[*] %s bill was written to '%s'" % (bill.title, pdf_path)
if table_output:
print this.table
def _printBill(this, bill):
print "- %s" % bill.title,
def _appendBillToTable(this, bill):
row = [bill.title]
if this.options.show_price:
print " (%s €)" % bill.amount,
print ""
row.insert(1, '%.2f €' % bill.amount)
def _composeBillFilename(this, bill):
bill_filename = this.options.write_directory.rstrip('/') + '/'
......@@ -269,7 +312,6 @@ class FreeAdslBillFetcherCli(object):
bill_filename = this._composeBillFilename(bill)
this.fetcher.writeBillToFile(bill, bill_filename)
return bill_filename
if __name__ == "__main__":
with FreeAdslBillFetcherCli() as cli:
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment