Skip to content

Instantly share code, notes, and snippets.

@grimpy
Created July 8, 2019 06:47
Show Gist options
  • Save grimpy/aaf39e61e315d85d4b1b9806d1172d85 to your computer and use it in GitHub Desktop.
Save grimpy/aaf39e61e315d85d4b1b9806d1172d85 to your computer and use it in GitHub Desktop.
isp_status
from i3pystatus import IntervalModule
import time
class VodaFone(IntervalModule):
interval = 3600
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
try:
import vodafone
for _ in range(3):
try:
self.vf = vodafone.Vodafone("nr", "gergreger")
self.vf.login()
break
except:
pass
else:
self.vf = None
except ImportError:
self.vf = None
def run(self):
if self.vf is None:
return
try:
quota = self.vf.get_quota()
except:
return
percent = (quota["totalConsumption"] / quota["totalBalance"]) * 100
renewdate = time.mktime(time.strptime(quota["quotaDTO"][0]["renewalDate"], "%d-%b-%y"))
remainingdays = int((renewdate - time.time()) / (3600 * 24))
remainingpercent = 100 - (remainingdays / 30) * 100
if remainingpercent < percent:
color = "#FF0000"
else:
color = "#FFFFFF"
self.data = self.vf.__dict__
self.output = {"full_text": "{limit:.0f}% R{remaining}d ({remper:.2f}%)".format(limit=percent, remaining=remainingdays, remper=remainingpercent),
'color': color}
def refresh(self):
self.run()
class TelecomEgypt(IntervalModule):
interval = 3600
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._te = None
@property
def te(self):
if self._te is None:
import telecomegypt
try:
self._te = telecomegypt.TelecomEgypt('nr', 'fwfwe/gergerger=')
self._te.login()
except:
pass
return self._te
def run(self):
if self.te is None:
return
try:
data = self.te.get_data()
except:
return
mobiledata = data['body']['detailedLineUsageList'][0]
percent = mobiledata['usagePercentage']
remainingpercent = 100 - (mobiledata['remainingDaysForRenewal'] / 31) * 100
if remainingpercent < percent:
color = "#FF0000"
else:
color = "#FFFFFF"
self.data = self.te.__dict__
self.output = {"full_text": "{limit:.0f}% R:{remaining}d ({remper:.0f}%)".format(limit=percent, remaining=mobiledata['remainingDaysForRenewal'], remper=remainingpercent),
'color': color}
def refresh(self):
self.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment