Skip to content

Commit

Permalink
Shifting code to new repo
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Oct 26, 2017
1 parent 9338358 commit 842e194
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 227 deletions.
77 changes: 0 additions & 77 deletions configure.py

This file was deleted.

143 changes: 0 additions & 143 deletions ptcl.py

This file was deleted.

19 changes: 12 additions & 7 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def dhcpinfo(self):
hostname = td[td.index(i) - 1].text
self.dev_info["Hostname"] = hostname
self.dev_info[hostname] = [i.text, td[td.index(i) + 1].text, td[td.index(i) + 2].text]
return (self.dev_info)
return self.dev_info


def stationinfo(self):
Expand Down Expand Up @@ -141,6 +141,7 @@ def unblock(self, udevmac):
'''
self.session.get(self.mask + "wlmacflt.cmd?action=remove&rmLst=%s&sessionKey=%s" % (udevmac, self.session_key()))


def reboot(self):
'''
Reboots Router.
Expand Down Expand Up @@ -188,16 +189,18 @@ def time_limit(self, username="User_1", mac="", days="", start="1", end="24"):
"Everyday": 127}
num_lst = []

def day_to_binary(integer):
def bin_to_dec(integer):
# TODO: Add check for integer parameter.
'''
Takes an integer and divides it by 2, appends to the num_lst
and returns sum of the num_lst when it reaches 1.
'''
# if not isinstance(integer, int):
# raise Exception
if 1 in num_lst:
return sum(num_lst)
num_lst.append(integer / 2)
return day_to_binary(integer / 2)
return bin_to_dec(integer / 2)

def convert_time(start_time="1", end_time="23:59"):
# TODO : Add test that the numbers after : shouldn't exceed 60 (minutes)
Expand All @@ -224,9 +227,11 @@ def convert_time(start_time="1", end_time="23:59"):
start_time.append(00)
if len(end_time) == 1:
end_time.append(00)
# if end_time[0] > 24 or start_time[0] > 24 or end_time[1] > 60 or start_time[1] > 60:
# raise custom Exception
start_time = (start_time[0] * 60) + start_time[1]
end_time = (end_time[0] * 60) + end_time[1]
return start_time, end_time
return (start_time, end_time)

gen_params = lambda days: {
'username': username,
Expand All @@ -240,16 +245,16 @@ def convert_time(start_time="1", end_time="23:59"):
for keys, val in week_days.items():
if days and len(days) < 3:
if len(days) == 1:
r = self.session.get(self.mask + 'todmngr.tod?action=add&mac=%s' % (mac), params=gen_params(days=week_days[days]))
self.session.get(self.mask + 'todmngr.tod?action=add&mac=%s'.format(mac), params=gen_params(days=week_days[days]))
break

elif len(days) == 2 and days[0] in week_days and days[1] in week_days:
if days[0] == days[1]:
r = self.session.get(self.mask + 'todmngr.tod?action=add&mac=%s' % (mac), params=gen_params(days=week_days["Everyday"]))
self.session.get(self.mask + 'todmngr.tod?action=add&mac=%s'.format(mac), params=gen_params(days=week_days["Everyday"]))
break

elif days[0] != days[1]:
r = self.session.get(self.mask + 'todmngr.tod?action=add&mac=%s' % (mac), params=gen_params(days=str(week_days[days[1]])))
self.session.get(self.mask + 'todmngr.tod?action=add&mac=%s'.format(mac), params=gen_params(days=str(week_days[days[1]])))
break
# Mon - Sunday, select the value from sunday and add it to the value preceding it.
else:
Expand Down
34 changes: 34 additions & 0 deletions tests/convert_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
def time(start_time="1", end_time="23:59"):
# TODO : Add test that the numbers after : shouldn't exceed 60 (minutes)
'''
Converts time to minutes.
Takes time and splits it by ":", the first element before ":" is in
hour and the second element is in minutes.
Parameters:
- start_time: start time to apply limit from. Eg: 1:00 (am)
- end_time: end time to apply limit till. Eg: 13:00 (pm)
Return (Integer):
sum of start_time and end_time in format (Hours * 60 + minutes).
Example:
>>> convert_time(13:00, 18:08)
# returns (13 * 60) + 00, (18 * 60) + 08
780, 1080
'''
start_time = [int(i) for i in start_time.split(':')]
end_time = [int(i) for i in end_time.split(':')]
if len(start_time) == 1:
start_time.append(00)
if len(end_time) == 1:
end_time.append(00)
if end_time[0] > 24 or start_time[0] > 24 or end_time[1] > 60 or start_time[1] > 60:
# Raise Exception here!
print("The first segment of start and end time should be less than or equal to 24 (measured in hours)\
and the second segment should be less than or equal to 60 (measured in minutes).")
start_time = (start_time[0] * 60) + start_time[1]
end_time = (end_time[0] * 60) + end_time[1]
return (start_time, end_time)

s = time('25')

0 comments on commit 842e194

Please sign in to comment.