Skip to content

Commit

Permalink
updated: logs and config path
Browse files Browse the repository at this point in the history
  • Loading branch information
imShakil committed Jul 28, 2022
1 parent 2103ae2 commit bdd995e
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 11 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Put this desktop entry inside:

# Usage

By default it will just try click your mouse and will switch tabs if they are open. You may customize the [config.ini](config.ini) as your own.
By default it will just try click your mouse and will switch tabs if they are open. You may customize the [config.ini](bin/config.ini) as your own.

```editorconfig
[DEFAULT]
Expand Down
45 changes: 37 additions & 8 deletions bin/autopi → autopi
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,44 @@
import os
import sys
import time
import glob
import random
import logging
import platform
import subprocess
import configparser

msg_fmt = "[%(asctime)s ] %(levelname)s @ line %(lineno)d: %(message)s"
logging.basicConfig(filename='autopi.log', filemode='w', format=msg_fmt)
ROOT_DIR = os.path.dirname(os.path.abspath('~')) # Change this if not in home directory
CONFIG_DIR = ROOT_DIR + "/bin"
LOG_DIR = ROOT_DIR + '/logs'

if not os.path.exists(LOG_DIR):
path = os.popen('mkdir -p ' + LOG_DIR).read()

msg_fmt = "[%(asctime)s ] %(levelname)s @ line %(lineno)d: %(message)s"
logging.basicConfig(filename=LOG_DIR + '/' + str(time.time()) + '_logfile.log',
filemode='w', format=msg_fmt, level=logging.DEBUG)
logging.warning("Is logs saved or not")
logging.info(ROOT_DIR)
logging.info(CONFIG_DIR)
logging.info(LOG_DIR)

# clean logs
files = glob.glob(LOG_DIR + '/*.*_logfile.log')
cnt = 0
current_time = time.time()
expire_time = 86400 # values are in seconds, default 24 hrs
for f in files:
f_ctime = os.path.getctime(f)
if current_time - f_ctime >= expire_time:
os.remove(f)
cnt += 1
if cnt > 0:
logging.info(str(cnt) + " logs cleaned successfully")

if platform.system() != "Linux":
logging.error("This script runs only for Linux OS.")
sys.exit()

if sys.version_info.major < 3:
logging.info("This script runs under python3")
Expand Down Expand Up @@ -44,7 +74,7 @@ from tkinter import *
from tkinter import ttk
import pyautogui as pyg

app = Tk()
app = Tk(className='Python Stalker')
app.geometry("400x300")
app.minsize(400, 300)
app.title('Python Stalker')
Expand All @@ -53,12 +83,10 @@ running = False

# Config Parse
config = configparser.ConfigParser()
try:
config.read('../config.ini')
except Exception as e:
logging.error(e)
sys.exit()
config.read(CONFIG_DIR + '/config.ini')

if len(config.sections()) <= 0:
logging.error("Configurations are corrupted or file is missing.")

mouse_movement = config.getboolean('MouseMovement', 'allow')
page_scroll = config.getboolean('PageScroll', 'allow')
Expand All @@ -72,6 +100,7 @@ def popup(msg):
text_box.delete("1.0", "end")
text_box.insert('end', msg)
text_box.update()
# logging.info(msg) use this to store messages in logs instead


def on_start():
Expand Down
4 changes: 2 additions & 2 deletions config.ini → bin/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ allow = true
mmTime =

[MouseClick]
allow = true
allow = false
button = right
clicks = 2
interval = .01
Expand All @@ -25,7 +25,7 @@ interval = .01
allow = true

[RefreshWindow]
allow = false
allow = true

[PageScroll]
allow = false
Expand Down

0 comments on commit bdd995e

Please sign in to comment.