summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnthony Brodard <anthony.brodard@fullsix.com>2015-04-29 15:46:52 +0200
committerAnthony Brodard <anthony.brodard@fullsix.com>2015-04-29 15:46:52 +0200
commit5bc8eea74fd7b54be5a2d473728648b8bb775d09 (patch)
tree8adff38f52bb71e52da71be0e8109a22ae905885
parent0adf9e189fd73080f4458f8594ebc9daab33d9fe (diff)
Fix PEP8 compliance
-rwxr-xr-xpy3status/modules/aws_bill.py121
1 files changed, 62 insertions, 59 deletions
diff --git a/py3status/modules/aws_bill.py b/py3status/modules/aws_bill.py
index 6336da4..d10af4b 100755
--- a/py3status/modules/aws_bill.py
+++ b/py3status/modules/aws_bill.py
@@ -24,73 +24,76 @@ import boto
from boto.s3.connection import Key
from time import time
+
class Py3status:
- # available configuration parameters
- aws_access_key_id = ''
- aws_secret_access_key = ''
- aws_account_id = ''
- s3_bucket_name = ''
- billing_file = '/tmp/.aws_billing.csv'
- cache_timeout = 3600
+ # available configuration parameters
+ aws_access_key_id = ''
+ aws_secret_access_key = ''
+ aws_account_id = ''
+ s3_bucket_name = ''
+ billing_file = '/tmp/.aws_billing.csv'
+ cache_timeout = 3600
+
+ def _get_bill_amount(self):
+ # Billing file name, generated by Amazon itself
+ # Format : 123456789012-aws-billing-csv-yyyy-mm.csv
+ s3_file_key = self.aws_account_id + '-aws-billing-csv-' + \
+ datetime.datetime.now().strftime(
+ "%Y") + '-' + datetime.datetime.now().strftime("%m") + '.csv'
+ i = 0
+
+ # Connect to the bucket
+ conn = boto.connect_s3(
+ self.aws_access_key_id, self.aws_secret_access_key)
+ bucket = conn.get_bucket(self.s3_bucket_name)
- def _get_bill_amount(self):
- # Billing file name, generated by Amazon itself
- # Format : 123456789012-aws-billing-csv-yyyy-mm.csv
- s3_file_key = self.aws_account_id + '-aws-billing-csv-' + datetime.datetime.now().strftime("%Y") + '-' + datetime.datetime.now().strftime("%m") + '.csv'
- i = 0
+ # Fetch the objects keys and get the billing file
+ k = Key(bucket)
+ k.key = s3_file_key
+ try:
+ k.get_contents_to_filename(self.billing_file)
+ except:
+ return False
+ k.close
- # Connect to the bucket
- conn = boto.connect_s3(self.aws_access_key_id, self.aws_secret_access_key)
- bucket = conn.get_bucket(self.s3_bucket_name)
-
- # Fetch the objects keys and get the billing file
- k = Key(bucket)
- k.key = s3_file_key
- try:
- k.get_contents_to_filename(self.billing_file)
- except:
- return False
- k.close
+ # Parse the file and get the InvoiceTotal amount
+ with open(self.billing_file, 'rb') as f:
+ reader = csv.reader(f)
+ for row in reader:
+ if ''.join(row).find('InvoiceTotal') == -1:
+ continue
+ i = i + 1
+ return row[-1]
- # Parse the file and get the InvoiceTotal amount
- with open(self.billing_file,'rb') as f:
- reader = csv.reader(f)
- for row in reader:
- if ''.join(row).find('InvoiceTotal') == -1:
- continue
- i = i+1
- return row[-1]
+ def aws_bill(self, i3s_output_list, i3s_config):
+ response = {
+ 'cached_until': time() + self.cache_timeout,
+ 'full_text': ''
+ }
-
- def aws_bill(self, i3s_output_list, i3s_config):
- response = {
- 'cached_until': time() + self.cache_timeout,
- 'full_text': ''
- }
+ bill_amount = self._get_bill_amount()
- bill_amount = self._get_bill_amount()
+ if bill_amount:
+ response['full_text'] = str(bill_amount) + "$"
+ response['color'] = i3s_config['color_good']
+ else:
+ response['full_text'] = "Billing file not found in the bucket"
+ response['color'] = i3s_config['color_bad']
- if bill_amount:
- response['full_text'] = str(bill_amount) + "$"
- response['color'] = i3s_config['color_good']
- else:
- response['full_text'] = "Billing file not found in the bucket"
- response['color'] = i3s_config['color_bad']
-
- return response
+ return response
if __name__ == "__main__":
- """
- Test this module by calling it directly.
- """
- from time import sleep
- x = Py3status()
- config = {
- 'color_good': '#00FF00',
- 'color_bad': '#FF0000',
- }
- while True:
- print(x.aws_bill([], config))
- sleep(1)
+ """
+ Test this module by calling it directly.
+ """
+ from time import sleep
+ x = Py3status()
+ config = {
+ 'color_good': '#00FF00',
+ 'color_bad': '#FF0000',
+ }
+ while True:
+ print(x.aws_bill([], config))
+ sleep(1)