From 39aad7e4c5075c8600bbcb5ad8f5d5fc7366b728 Mon Sep 17 00:00:00 2001 From: kCyborg <37458643+kCyborg@users.noreply.github.com> Date: Fri, 28 May 2021 05:09:35 -0400 Subject: [PATCH 1/2] Changing a bit the code to fit the timing_logout feature --- nauta.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/nauta.py b/nauta.py index 166e9d5..b18f45a 100755 --- a/nauta.py +++ b/nauta.py @@ -3,6 +3,9 @@ from pprint import pprint from textwrap import dedent +from threading import Thread +from time import sleep + import subprocess import requests import argparse @@ -16,7 +19,11 @@ import logging +sys.path.append('tools/') +from check_time import * + CONFIG_DIR = os.path.expanduser("~/.local/share/nauta/") + try: os.makedirs(CONFIG_DIR) except FileExistsError: @@ -27,12 +34,11 @@ logfile = open(os.path.join(CONFIG_DIR, "connections.log"), "a") def log(*args, **kwargs): - date = subprocess.check_output("date").decode().strip() kwargs.update(dict(file=logfile)) print( "{:.3f} ({})".format( time.time(), - date, + 'date', ), *args, **kwargs, @@ -77,7 +83,12 @@ def select_card(): return None, None return cards[0]['username'], cards[0]['password'] + def up(args): + + if args.time: + print("You have selected to shutdown your connection in:", args.time, "seconds") + session = requests.Session() r = session.get("http://google.com") @@ -196,6 +207,11 @@ def up(args): time.sleep(1) if not os.path.exists(LOGOUT_URL_FILE): break + + if args.time: + if (check_time(int(time.time()), login_time, args.time)) == True: + down([]) + except KeyboardInterrupt: print("Got a Ctrl+C, logging out...") log("Got Ctrl+C. Attempting disconnect...") @@ -450,16 +466,20 @@ def main(args): cards_info_parser = cards_subparsers.add_parser('info') cards_info_parser.set_defaults(func=cards_info) cards_info_parser.add_argument('username') - + up_parser = subparsers.add_parser('up') up_parser.set_defaults(func=up) up_parser.add_argument('username', nargs="?") + up_parser.add_argument('--time', '-t', type=int) + # up_parser.add_argument("-t", "--time", type=int, + # help="the ammount of time (in seconds) for the conection to be alive" + # ) down_parser = subparsers.add_parser('down') down_parser.set_defaults(func=down) args = parser.parse_args() - + if args.debug: logging.basicConfig(level=logging.DEBUG) from http.client import HTTPConnection From 93e3b1a0f790b470c465c2534c849f95f573cb81 Mon Sep 17 00:00:00 2001 From: kCyborg <37458643+kCyborg@users.noreply.github.com> Date: Fri, 28 May 2021 05:14:29 -0400 Subject: [PATCH 2/2] Create check_time.py --- tools/check_time.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tools/check_time.py diff --git a/tools/check_time.py b/tools/check_time.py new file mode 100644 index 0000000..433fbad --- /dev/null +++ b/tools/check_time.py @@ -0,0 +1,9 @@ +import time + +def check_time(times, home, argstimes): + if (times - home) >= argstimes: + print("Limit time reached. Your user will be disconected now") + return True + + +