Initial code commit

This commit is contained in:
Isaac Shoebottom 2023-05-31 04:31:59 -03:00
parent 33992cd452
commit a7fec3e0b1
14 changed files with 214 additions and 0 deletions

9
.gitignore vendored Normal file
View File

@ -0,0 +1,9 @@
# Poetry Lock File
poetry.lock
# Poetry build files
dist
# Any image files
*.png
*.jpg

8
.idea/.gitignore vendored Normal file
View File

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

7
.idea/discord.xml Normal file
View File

@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="DiscordProjectSettings">
<option name="show" value="PROJECT_FILES" />
<option name="description" value="" />
</component>
</project>

View File

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

4
.idea/misc.xml Normal file
View File

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Poetry (qrtool)" project-jdk-type="Python SDK" />
</project>

8
.idea/modules.xml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/qrtool.iml" filepath="$PROJECT_DIR$/.idea/qrtool.iml" />
</modules>
</component>
</project>

8
.idea/qrtool.iml Normal file
View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="cli" type="PythonConfigurationType" factoryName="Python" nameIsGenerated="true">
<module name="qrtool" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="C:\Users\Isaac\AppData\Local\pypoetry\Cache\virtualenvs\qrtool-o9n_-b---py3.11\Scripts\python.exe" />
<option name="SDK_NAME" value="Poetry (qrtool)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/qrtool" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/qrtool/cli.py" />
<option name="PARAMETERS" value="-h" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="cli test" type="PythonConfigurationType" factoryName="Python">
<module name="qrtool" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="C:\Users\Isaac\AppData\Local\pypoetry\Cache\virtualenvs\qrtool-o9n_-b---py3.11\Scripts\python.exe" />
<option name="SDK_NAME" value="Poetry (qrtool)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/qrtool" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/qrtool/cli.py" />
<option name="PARAMETERS" value="--output &quot;test.png&quot; --text &quot;test&quot;" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,25 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="cli test wifi" type="PythonConfigurationType" factoryName="Python">
<module name="qrtool" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="PARENT_ENVS" value="true" />
<envs>
<env name="PYTHONUNBUFFERED" value="1" />
</envs>
<option name="SDK_HOME" value="C:\Users\Isaac\AppData\Local\pypoetry\Cache\virtualenvs\qrtool-o9n_-b---py3.11\Scripts\python.exe" />
<option name="SDK_NAME" value="Poetry (qrtool)" />
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/qrtool" />
<option name="IS_MODULE_SDK" value="false" />
<option name="ADD_CONTENT_ROOTS" value="true" />
<option name="ADD_SOURCE_ROOTS" value="true" />
<EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
<option name="SCRIPT_NAME" value="$PROJECT_DIR$/qrtool/cli.py" />
<option name="PARAMETERS" value="-o &quot;test.png&quot; -w --encryption=WPA --ssid &quot;testssid&quot; --password &quot;testwifipassword&quot;" />
<option name="SHOW_COMMAND_LINE" value="false" />
<option name="EMULATE_TERMINAL" value="false" />
<option name="MODULE_MODE" value="false" />
<option name="REDIRECT_INPUT" value="false" />
<option name="INPUT_FILE" value="" />
<method v="2" />
</configuration>
</component>

View File

@ -0,0 +1,17 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="readback qr" type="ShConfigurationType">
<option name="SCRIPT_TEXT" value="zbarimg test.png" />
<option name="INDEPENDENT_SCRIPT_PATH" value="true" />
<option name="SCRIPT_PATH" value="" />
<option name="SCRIPT_OPTIONS" value="" />
<option name="INDEPENDENT_SCRIPT_WORKING_DIRECTORY" value="false" />
<option name="SCRIPT_WORKING_DIRECTORY" value="$PROJECT_DIR$/qrtool" />
<option name="INDEPENDENT_INTERPRETER_PATH" value="true" />
<option name="INTERPRETER_PATH" value="" />
<option name="INTERPRETER_OPTIONS" value="" />
<option name="EXECUTE_IN_TERMINAL" value="true" />
<option name="EXECUTE_SCRIPT_FILE" value="false" />
<envs />
<method v="2" />
</configuration>
</component>

6
.idea/vcs.xml Normal file
View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>

19
pyproject.toml Normal file
View File

@ -0,0 +1,19 @@
[tool.poetry]
name = "qrtool"
version = "0.1.0"
description = "QR Code CLI tool"
authors = ["Isaac Shoebottom <ir.shoebottom@gmail.com>"]
license = "MIT"
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.11"
segno = "^1.5.2"
click = "^8.1.3"
[tool.poetry.scripts]
qrtool = 'qrtool.cli:cli'
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

47
qrtool/cli.py Normal file
View File

@ -0,0 +1,47 @@
import click
import pathlib
import segno
from segno import helpers
CONTEXT_SETTINGS = dict(help_option_names=['-h', '--help'])
@click.command(context_settings=CONTEXT_SETTINGS)
# Version, Input, Output, QR Text, QR Error Correction Level, QR Border, QR Scale, WiFi Helper
@click.option('-v', '--version', is_flag=True, help="Show version")
# Output file, required
@click.option('-o', '--output', type=pathlib.Path, required=True, help="Output file")
# QR Text, required
@click.option('-t', '--text', type=str, required=False, help="QR Text")
# QR Error Correction Level, values: L, M, Q, H, -, Not required, default: L
@click.option('-e', '--error-correction', default="L", type=str, required=False, help="QR error correction level")
# Border size, default: 4, Not required
@click.option('-b', '--border', type=int, default=4, required=False, help="QR border")
# QR Scale, default: 8, Not required
@click.option('-s', '--scale', type=int, default=8, required=False, help="QR scale")
# Wi-Fi switch, Not required
@click.option('-w', '--wifi', is_flag=True, required=False, help="Wi-Fi Flag, if enabled, it will parse the encryption, ssid and password options and generate a Wi-Fi QR code. What you put is taken literally, so make sure you put the right information.")
# Encryption type, Not required
@click.option('--encryption', type=click.Choice(["WEP", "WPA", "None"], case_sensitive=False), required=False, help="Wi-Fi encryption type")
# SSID, Not required
@click.option('--ssid', type=str, required=False, help="Wi-Fi SSID")
# Password, Not required
@click.option('--password', type=str, required=False, help="Wi-Fi password")
def cli(version, output, text, error_correction, border, scale, wifi, encryption, ssid, password):
"""QRTool - A simple QR code generator"""
if not text and not wifi:
print("Please provide text or Wi-Fi information")
return
if version:
print("QRTool v0.1.0")
if wifi:
text = helpers.make_wifi_data(ssid, password, encryption)
qr = segno.make_qr(content=text, error=error_correction)
qr.save(output, border=border, scale=scale)
print("QR code saved to: " + str(output))
if __name__ == '__main__':
cli()