Skip to content

Commit

Permalink
Sleepless
Browse files Browse the repository at this point in the history
  • Loading branch information
toloco committed Jan 30, 2024
1 parent fdaf135 commit 6c6f148
Show file tree
Hide file tree
Showing 7 changed files with 242 additions and 2 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Continous integration
on: [push]

jobs:
build_and_test:
name: Build and test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Install
shell: bash
run: |
sudo apt-get install xvfb python3-tk python3-dev
pip3 install -e .
- name: Lint
shell: bash
run: |
pip3 install isort black autoflake
make lint
- name: Test
shell: bash
run: xvfb-run -a -s "-screen 0 640x480x8" sleepness --help
41 changes: 41 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!make
################################################################################
# Makefile internals
################################################################################
.PHONY: help

help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' Makefile | sort | \
awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-6s\033[0m %s\n", $$1, $$2}'

################################################################################

clean: ## Remove all pyc and caches
@find . -name '*.py[co]' -exec rm -f {} +
@find . -name '\.pytest_cache' -exec rm -fr {} +
@find . -name '\.mypy_cache' -exec rm -fr {} +
@find . -name '__pycache__' -exec rm -fr {} +
@find . -name 'dist' -exec rm -fr {} +

format: ## Format the code
@python3 -m isort --atomic . && \
python3 -m black . && \
python3 -m autoflake \
--in-place \
--remove-unused-variables \
--remove-all-unused-imports \
--remove-duplicate-keys \
--ignore-init-module-imports \
--recursive . \


lint: ## Static analysis
@python3 -m isort -c --atomic . && \
python3 -m black --check . \


build: ## Builds new version.
@python3 -m build

publish: ## Publish latest version.
python3 -m twine upload $(shell find dist -type f -print | tail -1) --verbose
44 changes: 42 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,42 @@
# sleepless
When you require an sleepless session
# Sleepless

![GitHub Actions Workflow Status](https://img.shields.io/github/actions/workflow/status/toloco/sleepness/ci.yml)
![PyPI - Version](https://img.shields.io/pypi/v/sleepness)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sleepness)

When you require an sleepless session, use **sleepless**.

Keep your screen on whilst you are drinking a ☕.

## INSTALLATION

On linux you'd need to have `Tkinter`, which is widely available in most distros.

Using public **pypi**:

```bash
pip install sleepness
```

```bash
pip3 install sleepness
```

Install from github:

```bash
pip install git+https://github.com/toloco/sleepness.git
```

## USAGE

```bash
sleepness --help
usage: sleepness [-h] [--timer TIMER] [--length [1-1000]] [--wait [10-1000]]

options:
-h, --help show this help message and exit
--timer TIMER Timer (in minutes), 0 means forever, default is forever.
--length [1-1000] Lenght of movement (in secs), default is 10.
--wait [10-1000] Waiting time between movements (in secs), default is 10.
```
41 changes: 41 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
[metadata]
name = sleepness
description = When you require an sleepness session, use **sleepness**.
version = 1.0.0
long_description = file: README.md
long_description_content_type = text/markdown
author = Tolo Palmer
url=https://github.com/toloco/sleepness
license = MIT License
license_files = LICENSE
classifiers =
Intended Audience :: Developers
Operating System :: POSIX
Programming Language :: Python :: 3
Programming Language :: Python :: 3 :: Only
Programming Language :: Python :: 3.8
Programming Language :: Python :: 3.9
Programming Language :: Python :: 3.10
Programming Language :: Python :: 3.11
Programming Language :: Python :: 3.12
Topic :: Utilities

[options]
packages =
sleepness
install_requires =
PyAutoGUI==0.9.54
tqdm==4.66.1
python_requires = >=3.8
zip_safe = yes

[options.entry_points]
console_scripts =
sleepness=sleepness.__main__:main

[options.extras_require]
testing =
pytest==7.2.0

[devpi:upload]
formats = sdist.tgz,bdist_wheel
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from setuptools import setup

if __name__ == "__main__":
setup()
Empty file added sleepness/__init__.py
Empty file.
85 changes: 85 additions & 0 deletions sleepness/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/usr/bin/env python3


import argparse
import math
import time
from datetime import datetime

import pyautogui
from tqdm import tqdm

pyautogui.FAILSAFE = False


def parse_args():
parser = argparse.ArgumentParser()

parser.add_argument(
"--timer",
type=int,
default=0,
help="Timer (in minutes), 0 means forever, default is forever.",
)

parser.add_argument(
"--length",
type=int,
default=10,
choices=range(1, 1000),
metavar="[1-1000]",
help="Lenght of movement (in secs), default is 10.",
)

parser.add_argument(
"--wait",
type=int,
default=10,
choices=range(10, 1000),
metavar="[10-1000]",
help="Waiting time between movements (in secs), default is 10.",
)

parser.set_defaults(feature=True)

return parser.parse_args()


def nod(length: float):
pos = pyautogui.position()

SCREEN_SIZE = pyautogui.size()

x = ((pos.x * 177) % (SCREEN_SIZE[0] * 0.8)) + SCREEN_SIZE[0] * 0.1
y = math.pow(pos.y, 21) % (SCREEN_SIZE[1] * 0.8) + SCREEN_SIZE[1] * 0.1
pyautogui.moveTo(x, y, duration=length, tween=pyautogui.easeInOutQuad)


def runner():
args = parse_args()

if args.timer <= 0:
print(f"Run forever")
while True:
time.sleep(args.wait)
nod(float(args.length))
print(f"{datetime.now().time()} ping")

iters = int((args.timer * 60) / (args.wait + args.length))
for i in tqdm(
iterable=range(iters),
total=iters,
colour="BLUE",
leave=False,
bar_format="{l_bar}{bar}",
):
time.sleep(args.wait)
nod(float(args.length))


def main():
try:
runner()
except KeyboardInterrupt:
pass
exit(0)

0 comments on commit 6c6f148

Please sign in to comment.