Skip to content

Commit

Permalink
Working on time_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
RafayGhafoor committed Sep 30, 2017
1 parent fd8e2e7 commit 010c2e7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
17 changes: 9 additions & 8 deletions ptcl.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@
from tabulate import tabulate

ptcl = Router(password='123motorcross')
def show_dhcpinfo():
'''
Shows DHCP information.
'''
# print(ptcl.dhcpinfo())
print(tabulate([ptcl.dhcpinfo()], headers=['HOSTNAME'], tablefmt='fancy_grid'))

show_dhcpinfo()
ptcl.time_limit(username="rafay", mac="something", days="Mon-Tue")
# def show_dhcpinfo():
# '''
# Shows DHCP information.
# '''
# # print(ptcl.dhcpinfo())
# print(tabulate([ptcl.dhcpinfo()], headers=['HOSTNAME'], tablefmt='fancy_grid'))
#
# show_dhcpinfo()

# def show_active_dev():
# '''
Expand Down
51 changes: 29 additions & 22 deletions router.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def block(self, devmac):
'''
Block device using Mac Address.
'''
requests.get(self.mask + "wlmacflt.cmd?action=add&wlFltMacAddr=%s&sessionKey=%s" % (devmac, self.session_key()))
requests.get(self.mask + "wlmacflt.cmd?action=add&rmLst=%s&sessionKey=%s" % (devmac, self.session_key()))


def unblock(self, udevmac):
Expand Down Expand Up @@ -130,36 +130,43 @@ def time_limit(self, username="User_1", mac="", days="", start=1, end=24):
# mon-tue
# mon-sun
# mon-mon (Fail)
def day_to_binary(days="", start_name='', end_name=''):
pass

days = days.split('-')
for keys, val in week_days.items():
if len(days) != 0 and len(days) < 2:
if len(days) == 0:
scrape_page(self.mask, "todmngr.tod?action=add&username=%s&mac=%s&days=%s&start_time=%s&end_time=%s&sessionKey=%s"\
% (username, mac, week_days[days], start, end))
elif len(days) == 1:
if days[0] == days[1]:
scrape_page(self.mask, "todmngr.tod?action=add&username=%s&mac=%s&days=%s&start_time=%s&end_time=%s&sessionKey=%s"\
% (username, mac, week_days["Everyday"], start, end))
elif day[1]:
pass # Mon - Sunday, select the value from sunday and add it to the value preceding it.

week_days = {
"Mon": 1,
"Tue": 2,
"Wed": 4,
"Thu": 8,
"Fri": 16,
"Sat": 32,
"Sun": 64
"Sun": 64,
"Everyday": 127}
username = ""
mac = ""
# Time should be converted to minutes.
start_time = ""
end_time = ""
lst = []
def day_to_binary(binary):
if 1 in lst:
return sum(lst)
lst.append(binary / 2)
return day_to_binary(binary / 2)

days = days.split('-')
for keys, val in week_days.items():
if days and len(days) < 3:
if len(days) == 1:
print(self.mask, "todmngr.tod?action=add&username=%s&mac=%s&days=%s&start_time=%s&end_time=%s&sessionKey=%s"\
% (username, mac, week_days[days], start, end, self.session_key()))
break
elif len(days) == 2 and days[0] in week_days and days[1] in week_days:
if days[0] == days[1]:
print(self.mask, "todmngr.tod?action=add&username=%s&mac=%s&days=%s&start_time=%s&end_time=%s&sessionKey=%s"\
% (username, mac, week_days["Everyday"], start, end, self.session_key()))
break
elif days[0] != days[1]:
print(self.mask, "todmngr.tod?action=add&username=%s&mac=%s&days=%s&start_time=%s&end_time=%s&sessionKey=%s"\
% (username, mac, str(week_days[days[1]] + day_to_binary(week_days[days[1]])), str(start), str(end), self.session_key()))
break
# Mon - Sunday, select the value from sunday and add it to the value preceding it.
else:
print("Specified day is not in week_days.")

# time_limit("Mon")
# Mon-Sun
# scrape_page(self.mask, todmngr.tod?action=add&username=hello&mac=64:5a:04:8d:38:bc&days=63&start_time=1&end_time=1389&sessionKey=1478055827)
Expand Down

0 comments on commit 010c2e7

Please sign in to comment.